/* papibot Unified Design System — Modern Minimalist Workspace */
:root {
  color-scheme: light;
  --bg: #f6f8fa;
  --bg-glow: rgba(37, 99, 235, 0.055);
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-hover: #f8fafc;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.085);
  --border-strong: rgba(15, 23, 42, 0.16);
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.09);
  --accent-ink: #ffffff;
  --ok: #10b981;
  --ok-soft: rgba(16, 185, 129, 0.11);
  --ok-text: #047857;
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --warn-text: #b45309;
  --bad: #ef4444;
  --bad-soft: rgba(239, 68, 68, 0.11);
  --bad-text: #b91c1c;
  --grid: #e2e8f0;
  --axis: #cbd5e1;
  --track: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 20px -2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 16px 40px -8px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.04);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0b0e14;
    --bg-glow: rgba(59, 130, 246, 0.09);
    --surface: #121721;
    --surface-2: #19202e;
    --surface-hover: #171e2b;
    --ink: #f1f5f9;
    --ink-2: #94a3b8;
    --muted: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --accent-ink: #ffffff;
    --ok: #10b981;
    --ok-soft: rgba(16, 185, 129, 0.15);
    --ok-text: #34d399;
    --warn: #f59e0b;
    --warn-soft: rgba(245, 158, 11, 0.16);
    --warn-text: #fbbf24;
    --bad: #ef4444;
    --bad-soft: rgba(239, 68, 68, 0.16);
    --bad-text: #f87171;
    --grid: #1e293b;
    --axis: #334155;
    --track: #1e293b;
    --shadow-sm: none;
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.28);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0e14;
  --bg-glow: rgba(59, 130, 246, 0.09);
  --surface: #121721;
  --surface-2: #19202e;
  --surface-hover: #171e2b;
  --ink: #f1f5f9;
  --ink-2: #94a3b8;
  --muted: #64748b;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --accent-ink: #ffffff;
  --ok: #10b981;
  --ok-soft: rgba(16, 185, 129, 0.15);
  --ok-text: #34d399;
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.16);
  --warn-text: #fbbf24;
  --bad: #ef4444;
  --bad-soft: rgba(239, 68, 68, 0.16);
  --bad-text: #f87171;
  --grid: #1e293b;
  --axis: #334155;
  --track: #1e293b;
  --shadow-sm: none;
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; min-height: 100vh; }

body {
  background: radial-gradient(960px 380px at 50% -100px, var(--bg-glow), transparent 70%), var(--bg);
  color: var(--ink);
  font: 14px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: var(--font-mono); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }

/* Top Navigation */
.topbar-wrap {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--border);
}

.topbar {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none !important;
}

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.28);
}

.crumb-sep { color: var(--muted); opacity: 0.5; font-size: 14px; }
.crumb-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 500;
}

.user-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
}

/* Main Container */
.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.page-head p {
  margin: 0;
  color: var(--ink-2);
  font-size: 13.5px;
}

/* Cards & Panels */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* KPI Tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
}

.tile .label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

.tile-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.tile-sub {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--muted);
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
  text-decoration: none !important;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--ink-2);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); border-color: var(--border-strong); }

.btn.danger {
  color: var(--bad-text);
  border-color: color-mix(in srgb, var(--bad) 30%, var(--border));
}
.btn.danger:hover { background: var(--bad-soft); }

.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.icon-btn { padding: 7px 9px; }

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
input:not([type]),
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[readonly] {
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}

/* Status Badges */
.badge, .status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
}

.badge.ok, .status.ok {
  background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 28%, transparent);
  color: var(--ok-text);
}

.badge.warn, .status.warn {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 28%, transparent);
  color: var(--warn-text);
}

.badge.bad, .status.bad {
  background: var(--bad-soft);
  border-color: color-mix(in srgb, var(--bad) 28%, transparent);
  color: var(--bad-text);
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.icon { width: 14px; height: 14px; flex-shrink: 0; }

/* Login View */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.login-card .login-head {
  margin-bottom: 22px;
}

.login-card h1 {
  margin: 12px 0 4px;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-card .sub {
  margin: 0;
  color: var(--ink-2);
  font-size: 13px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  font-size: 12.5px;
  color: var(--bad-text);
}

/* Copy Row */
.copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.copy-row input { flex: 1; min-width: 220px; }

.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

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

/* Portal Module Grid */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.module-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  text-decoration: none !important;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.module-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: var(--shadow-md);
}

.module-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

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

.module-host {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
}

.module-body h2 {
  margin: 0 0 6px;
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.module-body p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.55;
}

.module-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
}

/* Meter & Chart (Hawaii) */
.hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.hero-value {
  font-size: 30px;
  font-weight: 750;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 2px;
}

.hero-unit {
  font-size: 16px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
}

.status-list { display: flex; gap: 8px; flex-wrap: wrap; }

.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
  margin-bottom: 8px;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.35s ease;
}
.meter-fill.warn { background: var(--warn); }
.meter-fill.crit { background: var(--bad); }

.chart-card { position: relative; margin-left: 0; margin-right: 0; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .budget-line { stroke: var(--warn); stroke-width: 1.2; stroke-dasharray: 4 4; opacity: 0.85; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: var(--font-sans); }
.chart .bar { fill: var(--accent); opacity: 0.86; transition: opacity 0.12s ease; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart .hit:hover + .bar, .chart .hit:focus + .bar { opacity: 1; filter: brightness(1.08); }
.chart .value-label { fill: var(--ink-2); font-size: 11px; font-weight: 600; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  box-shadow: var(--shadow-md);
  z-index: 10;
  white-space: nowrap;
}
.tt-value { font-weight: 700; font-size: 13px; }
.tt-sub { font-size: 11.5px; color: var(--ink-2); }

/* Upload Dropzone (web.papibot.cn) */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 24px 20px;
  text-align: center;
  background: var(--surface-2);
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: pointer;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone input[type="file"] { display: none; }

/* KV Details */
details {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  user-select: none;
}
dl.kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 12px;
  margin: 12px 0 0;
  font-size: 12.5px;
}
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-family: var(--font-mono); word-break: break-all; }

.pw-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.ok-msg, .small.ok { color: var(--ok-text); }
.err-msg, .small.err { color: var(--bad-text); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.foot {
  text-align: center;
  margin-top: 28px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pw-form { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; }
  .wrap { padding: 20px 16px 48px; }
}
