:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --bg-canvas: #f5f7fb;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafd;
  --bg-muted: #eef2f8;
  --bg-topbar: rgba(245, 247, 251, 0.84);
  --bg-terminal: #0f172a;
  --text-terminal: #dbeafe;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --border-subtle: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.09);
  --accent-ring: rgba(37, 99, 235, 0.22);

  --teal: #0d9488;
  --teal-soft: rgba(13, 148, 136, 0.1);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.11);
  --violet: #7c3aed;
  --violet-soft: rgba(124, 58, 237, 0.1);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.11);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.09);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.04), 0 6px 20px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, 0.12), 0 4px 14px rgba(15, 23, 42, 0.06);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-width: 248px;
}

[data-theme="dark"] {
  --bg-canvas: #0b101b;
  --bg-surface: #111827;
  --bg-subtle: #162032;
  --bg-muted: #1e293b;
  --bg-topbar: rgba(11, 16, 27, 0.84);
  --bg-terminal: #070b14;
  --text-terminal: #cbd5e1;

  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --border-subtle: rgba(148, 163, 184, 0.13);
  --border-strong: rgba(148, 163, 184, 0.24);

  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --accent-ring: rgba(59, 130, 246, 0.32);

  --teal: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.15);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.15);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.28), 0 8px 24px rgba(0, 0, 0, 0.22);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font: 14px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-muted);
  color: var(--text-primary);
  padding: 2px 6px;
  border-radius: 6px;
}

h1, h2, h3 {
  margin: 0;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

p {
  margin: 0;
}

.muted,
small {
  color: var(--text-muted);
}

small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.55;
  margin-top: 5px;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Buttons */
button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.12s ease, opacity 0.16s ease;
}

button:active:not(:disabled) {
  transform: translateY(0.5px);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-primary,
form button[type="submit"]:not([class*="btn-"]),
button:not([class]) {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover:not(:disabled),
form button[type="submit"]:not([class*="btn-"]):hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary,
.file-button {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled),
.file-button:hover {
  background: var(--bg-subtle);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.btn-danger-soft {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-danger-soft:hover:not(:disabled) {
  background: var(--danger);
  color: #ffffff;
}

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

.btn-danger:hover:not(:disabled) {
  filter: brightness(0.92);
}

.btn-sm {
  min-height: 32px;
  padding: 6px 11px;
  font-size: 12px;
}

.btn-mini {
  min-height: 26px;
  padding: 3px 9px;
  font-size: 11px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-terminal);
}

.btn-mini:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
}

.btn-block {
  width: 100%;
  min-height: 42px;
}

.btn-icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.btn-icon.is-spinning {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.icon-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  flex-shrink: 0;
}

.icon-btn:hover:not(:disabled) {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Brand Emblem */
.brand-emblem {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2563eb 0%, #0ea5e9 100%);
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
  flex-shrink: 0;
}

.brand-emblem svg {
  width: 24px;
  height: 24px;
}

.brand-emblem.small {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.brand-emblem.small svg {
  width: 19px;
  height: 19px;
}

/* Login Screen */
.login-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(60% 50% at 20% 10%, rgba(37, 99, 235, 0.12), transparent 65%),
    radial-gradient(50% 45% at 85% 90%, rgba(14, 165, 233, 0.1), transparent 65%),
    var(--bg-canvas);
}

.login-card {
  width: min(940px, 100%);
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.login-copy {
  position: relative;
  padding: 48px 44px;
  background:
    radial-gradient(90% 80% at 10% 0%, rgba(56, 189, 248, 0.2), transparent 60%),
    linear-gradient(155deg, #0f172a 0%, #172554 58%, #0f172a 100%);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-copy .eyebrow {
  margin: 24px 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #7dd3fc;
}

.login-copy h1 {
  font-size: 28px;
  line-height: 1.3;
  color: #ffffff;
  margin-bottom: 14px;
}

.login-lead {
  color: #cbd5e1;
  font-size: 14px;
  line-height: 1.65;
}

.login-features {
  list-style: none;
  padding: 0;
  margin: 28px 0 0;
  display: grid;
  gap: 13px;
}

.login-features li {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 13px;
  color: #e2e8f0;
}

.feature-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.2);
  color: #7dd3fc;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.feature-check svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-form-panel {
  padding: 48px 42px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-mobile-brand {
  display: none;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  font-size: 18px;
}

.login-form-panel h2 {
  font-size: 22px;
  margin-bottom: 6px;
}

.login-form-panel form {
  margin-top: 24px;
  display: grid;
  gap: 16px;
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--text-primary);
}

.brand:hover {
  text-decoration: none;
}

.brand-text strong {
  display: block;
  font-size: 16px;
  font-weight: 750;
  line-height: 1.2;
}

.brand-text small {
  margin-top: 2px;
  font-size: 11px;
}

#menu-toggle,
#menu-close {
  display: none;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 8px 2px;
}

.nav-group {
  display: grid;
  gap: 3px;
}

.nav-label {
  padding: 0 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.nav-item {
  width: 100%;
  justify-content: flex-start;
  gap: 10px;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 550;
  font-size: 13.5px;
}

.nav-item:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.nav-item.selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.nav-icon {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item.selected .nav-icon {
  opacity: 1;
}

.nav-count {
  margin-left: auto;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--bg-muted);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-item.selected .nav-count {
  background: var(--accent);
  color: #ffffff;
}

.aside-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  display: grid;
  gap: 8px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.user-meta {
  min-width: 0;
  flex: 1;
}

.user-meta strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-meta small {
  margin-top: 1px;
  font-size: 11px;
}

.btn-logout {
  width: 100%;
  min-height: 34px;
  font-size: 12.5px;
}

/* Main Layout */
.main-content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 32px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

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

.page-heading {
  min-width: 0;
}

.page-heading h1 {
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
}

.page-summary {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sync-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 650;
  background: var(--success-soft);
  color: var(--success);
  white-space: nowrap;
}

.status-pill.off {
  background: var(--amber-soft);
  color: var(--amber);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status-pill:not(.off) .pulse-dot {
  box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.55);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(5, 150, 105, 0); }
  100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

.page-container {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px 32px 84px;
}

/* Notice Banner */
.notice-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  margin-bottom: 18px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid rgba(37, 99, 235, 0.16);
  color: var(--text-secondary);
  font-size: 12.5px;
  line-height: 1.5;
}

.notice-icon {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Readiness Strip */
.readiness-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.readiness-label {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-secondary);
  margin-right: 4px;
}

.readiness-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid transparent;
}

.readiness-pill:hover {
  border-color: currentColor;
}

.readiness-pill.is-done {
  background: var(--success-soft);
  color: var(--success);
}

.readiness-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Cards & Grids */
.page-section {
  display: grid;
  gap: 16px;
}

.page-section.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

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

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  min-width: 0;
}

.sub-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  min-width: 0;
}

.sub-card h3 {
  font-size: 14.5px;
  margin-bottom: 10px;
}

.sub-heading {
  font-size: 14.5px;
  margin: 20px 0 10px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading h2 {
  font-size: 16.5px;
  font-weight: 700;
  margin-bottom: 3px;
}

.panel-heading .muted {
  font-size: 12.5px;
  line-height: 1.5;
}

.panel-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Overview Metrics */
.overview-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.metric-card:hover {
  border-color: var(--border-strong);
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.metric-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-icon,
.tile-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.metric-icon svg,
.tile-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tone-blue { background: var(--accent-soft); color: var(--accent); }
.tone-teal { background: var(--teal-soft); color: var(--teal); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }

.metric-value {
  display: block;
  font-size: 26px;
  font-weight: 750;
  line-height: 1.2;
  margin: 10px 0 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.overview-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.85fr);
  gap: 16px;
}

.service-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.terminal-wrap {
  margin: 12px 0 14px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: var(--bg-terminal);
}

.terminal-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #94a3b8;
  font-size: 11.5px;
  font-weight: 600;
}

.terminal-actions {
  display: flex;
  gap: 6px;
}

pre {
  margin: 0;
  padding: 14px;
  background: var(--bg-terminal);
  color: var(--text-terminal);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 360px;
  overflow: auto;
}

.update-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.update-row b {
  display: block;
  font-size: 13.5px;
  margin-bottom: 2px;
}

.update-row p {
  font-size: 12px;
  color: var(--text-muted);
}

.quick-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.quick-tile {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 2px;
  align-items: center;
  text-align: left;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  white-space: normal;
}

.quick-tile:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.quick-tile .tile-icon {
  grid-row: 1 / span 2;
}

.quick-tile b {
  font-size: 13px;
  font-weight: 650;
}

.quick-tile small {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.4;
}

/* Segmented Control */
.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 9px;
  background: var(--bg-muted);
  gap: 2px;
}

.segmented button {
  min-height: 28px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  box-shadow: none;
}

.segmented button.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Tables */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.data-table th {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-muted);
  background: var(--bg-subtle);
  white-space: nowrap;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: var(--bg-subtle);
}

.badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 650;
  white-space: nowrap;
}

.badge-chip.ok { background: var(--success-soft); color: var(--success); }
.badge-chip.info { background: var(--accent-soft); color: var(--accent); }
.badge-chip.warn { background: var(--amber-soft); color: var(--amber); }
.badge-chip.err { background: var(--danger-soft); color: var(--danger); }
.badge-chip.neutral { background: var(--bg-muted); color: var(--text-secondary); }

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Forms & Controls */
.form-stack {
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  align-items: start;
}

.form-inline-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 0.8fr) auto;
  gap: 12px;
  align-items: end;
}

.inline-btn-wrap {
  padding-bottom: 1px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 0;
}

input:not([type="checkbox"]),
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  margin-top: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:not([type="checkbox"]):hover,
select:hover {
  border-color: var(--text-muted);
}

input:not([type="checkbox"]):focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.search-input {
  width: 210px !important;
  min-height: 32px !important;
  margin-top: 0 !important;
  padding: 5px 11px !important;
  font-size: 12.5px !important;
}

.password-field {
  position: relative;
  margin-top: 6px;
}

.password-field input {
  margin-top: 0;
  padding-right: 40px;
}

.password-toggle {
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  min-height: 32px;
}

.field-action {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.field-action input,
.field-action select {
  margin-top: 0;
  min-width: 0;
  flex: 1;
}

.field-action + input {
  margin-top: 8px;
}

.hint {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 12.5px;
  line-height: 1.55;
}

/* Switch Toggle */
.check {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-height: 40px;
}

.check > small {
  flex: 0 0 100%;
  margin: 0;
}

.state-input {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.state-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 5px 12px 5px 7px;
  border-radius: 99px;
  border: 1px solid var(--border-strong);
  background: var(--bg-muted);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 650;
}

.state-toggle .switch-track {
  width: 30px;
  height: 17px;
  border-radius: 99px;
  background: rgba(100, 116, 139, 0.35);
  position: relative;
  transition: background-color 0.18s ease;
  flex-shrink: 0;
}

.state-toggle .switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}

.state-toggle.is-active {
  border-color: rgba(5, 150, 105, 0.35);
  background: var(--success-soft);
  color: var(--success);
}

.state-toggle.is-active .switch-track {
  background: var(--success);
}

.state-toggle.is-active .switch-thumb {
  transform: translateX(13px);
}

.state-input:focus-visible + .state-toggle {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Accounts & Login Steps */
.account-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
}

.account-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
}

.account-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.account-info {
  min-width: 0;
  flex: 1;
}

.account-title {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.account-title b {
  font-size: 14px;
}

.account-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

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

.step-box {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  display: grid;
  gap: 10px;
  align-content: start;
}

.step-2fa {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* Lookup Workbench */
.cache-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--teal-soft);
  color: var(--teal);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cache-pill.is-live {
  background: var(--accent-soft);
  color: var(--accent);
}

.lookup-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

.toolbar-select {
  min-width: 220px;
  flex: 0 1 280px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.results-panel {
  margin-top: 18px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-surface);
}

.results-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.results-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.results-title-group h3 {
  font-size: 14px;
}

.count-pill {
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--bg-muted);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.results-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.lookup-list {
  max-height: 460px;
  overflow-y: auto;
}

.lookup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color 0.12s ease;
}

.lookup-row:last-child {
  border-bottom: 0;
}

.lookup-row:hover {
  background: var(--bg-subtle);
}

.lookup-row-main {
  min-width: 0;
  flex: 1;
}

.lookup-row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lookup-row-title b {
  font-size: 13.5px;
  word-break: break-word;
}

.lookup-row-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.mono-id {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-muted);
  padding: 1px 7px;
  border-radius: 6px;
  user-select: all;
}

.lookup-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Record Cards (Groups & Check-ins) */
.record-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.record {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  overflow: hidden;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.record:hover {
  border-color: var(--border-strong);
}

.record.is-new {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.record-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  user-select: none;
}

.record.is-collapsed .record-heading {
  border-bottom: 0;
}

.record-title-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex-wrap: wrap;
}

.record-chevron {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.18s ease;
  flex-shrink: 0;
}

.record.is-collapsed .record-chevron {
  transform: rotate(-90deg);
}

.record-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.record-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.record-body {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.record.is-collapsed .record-body {
  display: none;
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  align-items: start;
}

.record-subpanel {
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: var(--bg-surface);
  display: grid;
  gap: 12px;
  transition: opacity 0.16s ease;
}

.record-subpanel.is-inactive {
  opacity: 0.62;
}

.record-subpanel.is-inactive .subpanel-fields {
  display: none;
}

.subpanel-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
}

.identity-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.identity-control input {
  margin-top: 0;
}

.identity-control small {
  grid-column: 1 / -1;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--accent);
}

.identity-control small:empty {
  display: none;
}

.record-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.section-footer-actions {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Settings & Cache & Backups */
.bot-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.cache-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.cache-stat {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

.cache-stat span {
  display: block;
  font-size: 12px;
}

.cache-stat strong {
  display: block;
  font-size: 20px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.backup-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 10px;
}

.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.backup-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

.backup-item-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 12px;
}

.backup-item-size {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* Footer */
.app-footer {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Sticky Dirty Save Bar */
.dirty-bar {
  position: fixed;
  left: calc(var(--sidebar-width) + 24px);
  right: 24px;
  bottom: 20px;
  z-index: 40;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.dirty-bar-inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 16px;
  border-radius: 14px;
  background: var(--text-primary);
  color: var(--bg-surface);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 550;
  max-width: 100%;
  flex-wrap: wrap;
}

[data-theme="dark"] .dirty-bar-inner {
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid var(--border-strong);
}

.dirty-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  flex-shrink: 0;
}

.dirty-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
}

.dirty-bar .btn-ghost {
  color: inherit;
  opacity: 0.82;
}

.dirty-bar .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
  opacity: 1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-dialog {
  width: min(460px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modal-in 0.16s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: 16px;
}

.modal-body {
  padding: 18px 20px;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.6;
  display: grid;
  gap: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border-subtle);
}

/* Toast Stack */
.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  line-height: 1.5;
  animation: toast-in 0.18s ease-out;
}

.toast-item.is-error {
  background: #7f1d1d;
  border-color: rgba(254, 202, 202, 0.25);
}

.toast-item.is-success {
  background: #064e3b;
  border-color: rgba(167, 243, 208, 0.25);
}

.toast-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toast-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-close {
  width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
}

.toast-close:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive Breakpoints */
@media (max-width: 1120px) {
  .overview-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .overview-columns,
  .page-section.two-col,
  .bot-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .span-2 {
    grid-column: auto;
  }
  .form-inline-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .login-card {
    grid-template-columns: 1fr;
    max-width: 460px;
  }
  .login-copy {
    display: none;
  }
  .login-mobile-brand {
    display: flex;
  }
  .login-form-panel {
    padding: 32px 24px;
  }
  .step-grid,
  .lookup-forms,
  .form-grid,
  .record-grid,
  .subpanel-fields {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  body.menu-open {
    overflow: hidden;
  }
  #menu-toggle,
  #menu-close {
    display: inline-grid;
  }
  .nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(15, 23, 42, 0.52);
    backdrop-filter: blur(2px);
  }
  .sidebar {
    width: min(280px, 84vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s ease;
    box-shadow: var(--shadow-lg);
  }
  .menu-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }
  .main-content {
    margin-left: 0;
  }
  .topbar {
    padding: 10px 14px;
    gap: 8px;
  }
  .topbar-left {
    gap: 8px;
    flex: 1;
    min-width: 0;
  }
  .page-summary,
  .sync-meta {
    display: none;
  }
  .page-heading h1 {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header-actions {
    gap: 6px;
  }
  .header-actions .status-pill {
    padding: 4px 9px;
    font-size: 11px;
    gap: 5px;
  }
  #refresh {
    width: 36px;
    min-height: 36px;
    padding: 0;
  }
  #refresh span {
    display: none;
  }
  .page-container {
    padding: 16px 14px calc(92px + env(safe-area-inset-bottom));
  }
  .card {
    padding: 16px;
    border-radius: 14px;
  }
  .overview-stats {
    gap: 10px;
  }
  .metric-card {
    padding: 14px;
  }
  .metric-value {
    font-size: 22px;
  }
  .quick-links,
  .form-inline-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .panel-heading {
    flex-direction: column;
    align-items: stretch;
  }
  .panel-heading .status-pill,
  .panel-heading .cache-pill {
    align-self: flex-start;
    width: fit-content;
  }
  .record-title-wrap {
    flex: 1;
  }
  .search-input {
    width: 100% !important;
  }
  .lookup-row {
    flex-direction: column;
    align-items: stretch;
  }
  .field-action {
    flex-direction: column;
    align-items: stretch;
  }
  .dirty-bar {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .app-footer {
    flex-direction: column;
  }
  input:not([type="checkbox"]),
  select {
    font-size: 16px;
    min-height: 44px;
  }
  button,
  .file-button {
    min-height: 42px;
  }
  .btn-sm {
    min-height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
