:root {
  --bg-sidebar: #f7f7f5;
  --bg-canvas: #ffffff;
  --bg-subtle: #fbfbfa;
  --bg-hover: #f1f0ec;
  --border-hairline: #eae9e5;
  --border-strong: #dcdad3;
  --text-primary: #1f1f1d;
  --text-secondary: #686660;
  --text-muted: #9a9891;
  --accent: #2383e2;
  --accent-hover: #1b6ec2;
  --accent-soft: #ebf5fe;
  --success: #0f7b6c;
  --success-bg: #e8f5f1;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #c43e3e;
  --danger-bg: #fdecec;
  --purple: #6940a5;
  --purple-bg: #f3effa;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-drawer: -8px 0 32px rgba(15, 23, 42, 0.12);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
}

.tabular { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

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

.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  height: 52px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-hairline);
  align-items: center;
  justify-content: space-between;
}
.mobile-brand { font-weight: 600; font-size: 15px; }

.sidebar {
  width: 244px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.sidebar-header {
  padding: 16px 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--text-primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}
.brand-title { font-weight: 600; font-size: 13.5px; color: var(--text-primary); }
.brand-sub { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 16px;
}
.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 12px 8px 4px;
  letter-spacing: 0.03em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: #eae8e2;
  color: var(--text-primary);
  font-weight: 600;
}
.nav-icon { width: 18px; text-align: center; font-size: 13px; opacity: 0.8; }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-secondary);
}
.nav-badge:empty { display: none; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.user-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.user-email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Main Canvas */
.main-canvas {
  flex: 1;
  min-width: 0;
  background: var(--bg-canvas);
}
.page-root {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 32px 64px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-title { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.page-subtitle { font-size: 13px; color: var(--text-secondary); margin: 4px 0 0; }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-subtle); border-color: #c7c4bc; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-warning { background: #d97706; border-color: #d97706; color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Cards & Grids */
.section-block { margin-bottom: 28px; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-title { font-size: 15px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 8px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}
.card {
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.quota-card { display: flex; flex-direction: column; gap: 8px; }
.quota-top { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; }
.quota-nums { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.quota-nums span { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.progress-track {
  height: 6px;
  background: var(--border-hairline);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s; }
.progress-fill.done { background: var(--success); }
.quota-foot { font-size: 11.5px; color: var(--text-muted); display: flex; justify-content: space-between; }

/* Metric Cards */
.metric-card { display: flex; flex-direction: column; gap: 6px; }
.metric-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-val.unconnected { font-size: 15px; color: var(--text-muted); font-weight: 600; }
.metric-meta { font-size: 11.5px; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 6px; }

/* View Tabs & Filter Bar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-hairline);
  margin-bottom: 14px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tab-btn {
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.tab-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.tab-btn.active { background: var(--text-primary); color: #fff; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.input, .select, .textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(35, 131, 226, 0.15);
}
.textarea { width: 100%; min-height: 92px; resize: vertical; }

/* Notion-style Enhanced Table */
.table-wrap {
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  overflow-x: auto;
  background: #fff;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}
.data-table th {
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-hairline);
  border-right: 1px solid #f2f1ed;
  white-space: nowrap;
}
.data-table th:last-child, .data-table td:last-child { border-right: none; }
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-hairline);
  border-right: 1px solid #f4f3ef;
  vertical-align: middle;
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { cursor: pointer; transition: background 0.1s; }
.data-table tbody tr:hover { background: #f9f9f7; }
.group-row td {
  background: #f8f8f6;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text-secondary);
  padding: 7px 12px;
}

.row-title-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 400px;
}
.row-title {
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.row-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-open-chip {
  opacity: 0;
  font-size: 11px;
  color: var(--text-secondary);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 6px;
  flex-shrink: 0;
  transition: opacity 0.12s;
}
.data-table tbody tr:hover .row-open-chip { opacity: 1; }
.row-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.muted-text { color: var(--text-secondary); font-size: 12.5px; }
.code-pill {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-secondary);
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}
.pill-neutral { background: var(--bg-hover); color: var(--text-secondary); }
.pill-blue { background: var(--accent-soft); color: var(--accent); }
.pill-green { background: var(--success-bg); color: var(--success); }
.pill-amber { background: var(--warning-bg); color: var(--warning); }
.pill-red { background: var(--danger-bg); color: var(--danger); }
.pill-purple { background: var(--purple-bg); color: var(--purple); }
.pill-demo { background: #1f1f1d; color: #fff; font-size: 10px; padding: 1px 5px; }

/* 4-Stage Stepper */
.stepper { display: flex; align-items: center; gap: 4px; }
.step-dot {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--bg-hover);
  color: var(--text-muted);
}
.step-dot.done { background: var(--success-bg); color: var(--success); font-weight: 600; }
.step-dot.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.step-dot.warn { background: var(--warning-bg); color: var(--warning); font-weight: 600; }
.step-dot.fail { background: var(--danger-bg); color: var(--danger); font-weight: 600; }

/* Mobile Card List (hidden on desktop) */
.mobile-card-list { display: none; flex-direction: column; gap: 10px; }
.mobile-card {
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mobile-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mobile-card-title { font-weight: 600; font-size: 14px; }
.mobile-card-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--text-secondary); }

/* Peek Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.25);
  z-index: 60;
}
.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 560px;
  max-width: 100vw;
  background: #fff;
  z-index: 70;
  box-shadow: var(--shadow-drawer);
  display: flex;
  flex-direction: column;
}
.detail-drawer.wide { width: 860px; }
.drawer-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-header-left, .drawer-header-actions { display: flex; align-items: center; gap: 8px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; }
.drawer-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-hairline);
  background: var(--bg-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.detail-section { margin-bottom: 18px; }
.detail-section h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.detail-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}

/* Preview Gallery & SEO Sandbox */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.gallery-item {
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-subtle);
}
.gallery-item img { width: 100%; height: 150px; object-fit: cover; display: block; }
.gallery-caption { padding: 4px 8px; font-size: 11px; color: var(--text-secondary); }
.seo-iframe {
  width: 100%;
  height: 360px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
}

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline-item {
  border-left: 2px solid var(--border-strong);
  padding-left: 12px;
  font-size: 12.5px;
}
.timeline-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-weight: 600; }
.timeline-time { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

/* Modal & Auth */
.modal-backdrop, .auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-card, .auth-card {
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 20px;
}
.auth-card { max-width: 390px; text-align: center; padding: 28px 24px; }
.auth-logo {
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  border-radius: 10px;
  background: var(--text-primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
}
.auth-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 18px; }
.auth-hint { font-size: 12px; color: var(--text-muted); margin-top: 10px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { margin: 0; font-size: 16px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-error { color: var(--danger); font-size: 12.5px; }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text-primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-md);
}
.toast.error { background: var(--danger); }

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

/* Responsive: Mobile 320px+ */
@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .mobile-topbar { display: flex; }
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    transition: left 0.2s ease;
  }
  .sidebar.open { left: 0; }
  .sidebar-backdrop.open {
    display: block !important;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.3);
    z-index: 35;
  }
  .page-root { padding: 16px 14px 72px; }
  .table-wrap { display: none; }
  .mobile-card-list { display: flex; }
  .field-row { grid-template-columns: 1fr; }
  .detail-drawer, .detail-drawer.wide { width: 100vw; }
  .drawer-footer { position: sticky; bottom: 0; }
}

.version-details {
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  background: var(--bg-subtle);
}
.version-details summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.version-snapshot-body {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-strong);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
}
