:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #18181b;
  --ink-2: #52525b;
  --ink-3: #a1a1aa;
  --line: #e4e4e7;
  --gold: #ffd100;
  --gold-deep: #f5b800;
  --emerald: #059669;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.04), 0 6px 20px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

.hidden { display: none !important; }

/* Auth Gate */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(80% 45% at 50% 0%, #fff6cc 0%, var(--bg) 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 26px;
  box-shadow: 0 20px 50px -20px rgba(15, 23, 42, 0.14);
}

.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-logo { width: 38px; height: 38px; border-radius: 11px; background: #fffbeb; padding: 3px; object-fit: contain; border: 1px solid rgba(245, 184, 0, 0.35); }
.auth-brand h1 { font-size: 18px; font-weight: 800; line-height: 1.2; }
.auth-brand p { font-size: 12px; color: var(--ink-2); }

/* App Shell */
.app-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sb-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.sb-logo { width: 32px; height: 32px; border-radius: 9px; background: #fffbeb; padding: 2px; object-fit: contain; border: 1px solid rgba(245, 184, 0, 0.35); }
.sb-title { font-size: 15px; font-weight: 800; line-height: 1.2; }
.sb-sub { font-size: 11px; color: var(--ink-3); }

.sb-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: #f4f4f5; color: var(--ink); }
.nav-btn.active { background: #18181b; color: var(--gold); font-weight: 700; }

.sb-foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-2); }

.main-area {
  padding: 24px 28px 48px;
  max-width: 1120px;
  width: 100%;
}

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.page-header p { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 800; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-k { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.stat-v { font-size: 26px; font-weight: 900; margin-top: 6px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }

/* Onboarding Steps */
.onboard-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ob-item { padding: 12px 14px; border-radius: 12px; background: #fafafa; border: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.ob-item.done { background: #ecfdf5; border-color: #a7f3d0; }
.ob-dot { width: 22px; height: 22px; border-radius: 50%; background: #e4e4e7; color: #52525b; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ob-item.done .ob-dot { background: var(--emerald); color: #fff; }
.ob-item b { display: block; font-size: 13px; }
.ob-item span { font-size: 11.5px; color: var(--ink-2); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid #d4d4d8;
  background: #fff;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}
.field .hint { font-size: 11.5px; color: var(--ink-3); }

.inline-row { display: flex; gap: 8px; align-items: center; }
.inline-row input { flex: 1; }

/* Buttons */
.btn {
  height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--gold); }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-outline { background: #fff; border-color: #d4d4d8; color: var(--ink); }
.btn-danger { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 8px; }

/* Badges & Tables */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-green { background: #dcfce7; color: #047857; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-gray { background: #f4f4f5; color: #52525b; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11.5px; color: var(--ink-3); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid #f4f4f5; vertical-align: middle; }
tr:last-child td { border-bottom: none; }

/* Trend Bars */
.trend-bars { display: flex; align-items: flex-end; gap: 10px; height: 110px; padding-top: 12px; }
.t-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.t-bar { width: 100%; max-width: 34px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, #ffd100, #f59e0b); min-height: 4px; }
.t-num { font-size: 11px; font-weight: 700; color: var(--ink-2); }
.t-day { font-size: 11px; color: var(--ink-3); }

/* Toast */
.toast {
  position: fixed;
  top: 18px;
  right: 20px;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  z-index: 99;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}
.toast.err { background: var(--danger); }

.code-box {
  background: #f4f4f5;
  padding: 8px 10px;
  border-radius: 8px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}

@media (max-width: 860px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); padding: 12px; }
  .sb-nav { flex-direction: row; overflow-x: auto; }
  .nav-btn { width: auto; white-space: nowrap; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .onboard-row, .form-grid { grid-template-columns: 1fr; }
  .main-area { padding: 16px; }
}
