:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; word-break: break-all; }
.muted { color: var(--muted); font-size: 13px; }

/* Buttons & Badges */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-soft); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: #fff; color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-soft); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.full { width: 100%; padding: 10px 16px; font-size: 14px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #e2e8f0;
  color: #334155;
  white-space: nowrap;
}
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--primary-soft); color: var(--primary); }

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top left, #e0ecff, #f4f6fa 55%);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}
.brand-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 13px; font-weight: 500; }
.field input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.alert.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.login-foot {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* App Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 14px;
}
.logo-row { display: flex; align-items: center; gap: 10px; padding: 0 6px 14px; border-bottom: 1px solid var(--border); }
.logo-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.logo-title { font-weight: 700; font-size: 15px; }
.logo-sub { font-size: 12px; color: var(--muted); }

.domain-box { margin: 14px 0; }
.domain-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0 6px 6px; }
.domain-list { display: flex; flex-direction: column; gap: 4px; }
.domain-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; border-radius: 8px; font-size: 13px;
  background: var(--surface-soft); border: 1px solid transparent;
}
.domain-item.active { background: var(--primary-soft); border-color: #bfdbfe; font-weight: 600; color: var(--primary); }
.domain-item.planned { opacity: 0.68; }

.nav-list { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: transparent; color: var(--text);
  padding: 10px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 500;
  cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--surface-soft); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.65; }
.nav-item .pill { margin-left: auto; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; }
.user-card { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11.5px; color: var(--muted); }

/* Main */
.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.view-section { padding: 20px 24px 36px; display: flex; flex-direction: column; gap: 18px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12.5px; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 700; margin: 6px 0 4px; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.grid-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { margin: 0 0 2px; font-size: 15.5px; }
.card-head p { margin: 0; }

/* Funnel & Health */
.funnel-list { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: flex; flex-direction: column; gap: 4px; }
.funnel-meta { display: flex; justify-content: space-between; font-size: 13px; }
.bar-track { height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.bar-fill.ok { background: var(--success); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.danger { background: var(--danger); }

.health-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.health-box { background: var(--surface-soft); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
.health-box.full { grid-column: 1 / -1; }
.health-title { font-size: 12px; color: var(--muted); }
.health-val { font-size: 14px; font-weight: 600; margin-top: 3px; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top;
}
.data-table th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-soft); white-space: nowrap; }
.data-table tr:hover td { background: #fafcff; }
.cell-title { font-weight: 600; color: var(--text); max-width: 360px; }

/* Filters & Tabs */
.filter-bar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.zone-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab {
  border: 1px solid var(--border); background: var(--surface-soft); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px; cursor: pointer;
}
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.filter-inputs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-inputs select, .filter-inputs input {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 13px; background: #fff;
}
.filter-inputs input { flex: 1; min-width: 200px; }

.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.page-btns { display: flex; gap: 8px; }

/* Stack & KV */
.stack-list { display: flex; flex-direction: column; gap: 10px; }
.stack-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-soft); }
.stack-actions { display: flex; gap: 8px; margin-top: 10px; }
.kv-list { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.policy-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.policy-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-soft); }
.empty-hint { padding: 24px; text-align: center; color: var(--muted); background: var(--surface-soft); border-radius: 10px; margin-top: 12px; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 100vw);
  background: var(--surface); z-index: 50; box-shadow: -8px 0 32px rgba(15, 23, 42, 0.16);
  display: flex; flex-direction: column;
}
.drawer-head {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.drawer-head h3 { margin: 6px 0 4px; font-size: 17px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 32px; display: flex; flex-direction: column; gap: 16px; }
.preview-box {
  background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: 14px;
  font-size: 12.5px; line-height: 1.6; max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  background: #0f172a; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
}

.mobile-only { display: none; }

@media (max-width: 960px) {
  .grid-two { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .sm-hide { display: none; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 45;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 28px rgba(15, 23, 42, 0.18); }
  .topbar { padding: 12px 16px; }
  .view-section { padding: 14px 16px 28px; }
}
