:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-strong: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #059669;
  --success-soft: #d1fae5;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --sidebar: #101827;
  --sidebar-muted: #94a3b8;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

code,
pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.skip-link,
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link:focus {
  z-index: 20;
  width: auto;
  height: auto;
  left: 16px;
  top: 16px;
  padding: 10px 14px;
  margin: 0;
  clip: auto;
  color: #fff;
  background: var(--primary);
  border-radius: var(--radius-sm);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex: 0 0 280px;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 28px 20px;
  color: #e5eefb;
  background: linear-gradient(180deg, #0f172a 0%, #111827 54%, #0b1120 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, #3b82f6, #22c55e);
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.35);
}

.brand-block h1,
.panel h2,
.preview-drawer h2,
.diff-card h3 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar .eyebrow,
.side-nav__item span,
.sidebar-card span,
.sidebar-card__label {
  color: var(--sidebar-muted);
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav__item {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  color: #e2e8f0;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 14px;
}

.side-nav__item:hover,
.side-nav__item:focus-visible,
.side-nav__item.is-active {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(148, 163, 184, 0.24);
  outline: none;
}

.side-nav__item strong {
  font-size: 15px;
}

.sidebar-card {
  padding: 16px;
  margin-top: auto;
  background: rgba(15, 23, 42, 0.58);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: var(--radius-md);
}

.sidebar-card strong,
.sidebar-card span {
  display: block;
}

.sidebar-card__label {
  margin: 0 0 6px;
  font-size: 12px;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 24px;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(260px, 440px) auto;
  gap: 16px;
  align-items: center;
  padding: 14px 18px;
  margin-bottom: 18px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.status-cluster {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.status-cluster strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  background: var(--warning);
  border-radius: 999px;
  box-shadow: 0 0 0 6px rgba(217, 119, 6, 0.14);
}

.sync-chip,
.filter-chip,
.badge,
.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  border-radius: 999px;
}

.sync-chip,
.filter-chip {
  padding: 6px 10px;
  color: var(--muted);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  font-size: 12px;
}

.global-search input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
}

.global-search input:focus,
select:focus,
input:focus,
button:focus-visible {
  border-color: var(--primary);
  outline: 3px solid rgba(37, 99, 235, 0.16);
}

.action-bar,
.drawer-actions,
.table-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.btn {
  min-height: 40px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-weight: 700;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.1);
}

.btn-primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  color: #1e293b;
  background: var(--panel-strong);
}

.btn-success {
  color: #fff;
  background: var(--success);
  border-color: var(--success);
}

.btn-danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.notice-strip {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 18px;
  color: #1e3a8a;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
}

.notice-strip span {
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.summary-card {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.summary-card__label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.summary-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1;
}

.summary-card small {
  color: var(--muted);
}

.summary-card.warning {
  border-color: #fde68a;
}

.summary-card.success {
  border-color: #bbf7d0;
}

.summary-card.neutral {
  border-color: #c7d2fe;
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 390px);
  gap: 18px;
  align-items: start;
}

.workspace-main {
  display: grid;
  min-width: 0;
  gap: 18px;
}

.panel,
.preview-drawer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-heading,
.drawer-header,
.diff-card__header,
.records-heading {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.route-hint {
  padding: 8px 12px;
  color: #1e40af;
  background: #dbeafe;
  border-radius: 999px;
  font-weight: 800;
}

.geo-cascade {
  scroll-margin-top: 112px;
}

.cascade-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.cascade-grid label,
.postal-row label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
.postal-row input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.postal-row {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr;
  gap: 14px;
  align-items: end;
  margin-top: 14px;
}

.badge {
  width: fit-content;
  min-height: 36px;
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 800;
}

.badge-success,
.badge[data-state="local-hit"] {
  color: #065f46;
  background: var(--success-soft);
}

.badge-warning,
.badge[data-state="review"] {
  color: #92400e;
  background: var(--warning-soft);
}

.badge[data-state="empty"] {
  color: #475569;
  background: #e2e8f0;
}

.records-panel {
  padding-bottom: 10px;
}

.table-scroll {
  width: 100%;
  margin-top: 12px;
  overflow-x: auto;
}

.records-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.records-table caption {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.records-table th,
.records-table td {
  padding: 13px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.records-table th {
  color: var(--muted);
  background: var(--panel-strong);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.records-table tbody tr {
  transition: background 0.16s ease, box-shadow 0.16s ease;
}

.records-table tbody tr:hover,
.records-table tbody tr.is-selected {
  background: #eff6ff;
}

.records-table code {
  color: #1d4ed8;
  font-weight: 800;
}

.state-pill {
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.state-draft {
  color: #1e40af;
  background: #dbeafe;
}

.state-review {
  color: #92400e;
  background: var(--warning-soft);
}

.state-published {
  color: #065f46;
  background: var(--success-soft);
}

.link-button {
  padding: 0;
  margin-right: 10px;
  color: var(--primary);
  background: transparent;
  border: 0;
  font-weight: 800;
}

.link-button:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

.preview-drawer {
  position: sticky;
  top: 96px;
  display: grid;
  gap: 16px;
  padding: 18px;
}

.drawer-header {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--muted);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 24px;
  line-height: 1;
}

.preview-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--panel-strong);
  border-radius: var(--radius-md);
}

.preview-meta span {
  color: var(--muted);
}

.feed-preview {
  min-height: 170px;
  max-height: 260px;
  padding: 14px;
  overflow: auto;
  color: #dbeafe;
  background: #0f172a;
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.diff-card {
  padding: 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
}

.diff-card__header {
  margin-bottom: 10px;
}

.diff-lines {
  color: #78350f;
  font-weight: 700;
}

.drawer-actions {
  justify-content: stretch;
}

.drawer-actions .btn {
  flex: 1 1 auto;
}

body.js-enabled .preview-drawer.is-open {
  outline: 3px solid rgba(37, 99, 235, 0.14);
}

.action-modal[hidden] {
  display: none;
}

.action-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.action-modal.is-open {
  display: flex;
}

.action-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
}

.action-modal__dialog {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 16px;
  width: min(760px, 100%);
  max-height: min(90vh, 920px);
  padding: 22px;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.24);
}

.action-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.action-modal__body {
  display: grid;
  gap: 16px;
}

.action-modal__footer {
  justify-content: flex-end;
}

.action-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.action-form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.action-form-grid input,
.action-form-grid select,
.action-form-grid textarea {
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.action-form-grid textarea {
  min-height: 120px;
  resize: vertical;
}

.action-form-grid .span-2 {
  grid-column: 1 / -1;
}

.action-surface {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.action-tip {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

@media (max-width: 1240px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .action-bar {
    justify-content: flex-start;
  }

  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .preview-drawer {
    position: static;
  }
}

@media (max-width: 860px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    position: relative;
    flex: none;
    width: 100%;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main-content {
    padding: 16px;
  }

  .summary-grid,
  .cascade-grid,
  .postal-row {
    grid-template-columns: 1fr;
  }

  .panel-heading,
  .records-heading,
  .drawer-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .side-nav {
    grid-template-columns: 1fr;
  }

  .action-bar,
  .drawer-actions,
  .table-tools {
    justify-content: stretch;
  }

  .btn,
  .filter-chip {
    flex: 1 1 100%;
    justify-content: center;
  }
}
