:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-soft: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --sidebar-w: 220px;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar (desktop) ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  padding: 18px 12px;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-logo { width: 32px; height: 32px; }
.brand-name { font-weight: 700; font-size: 16px; color: var(--primary-dark); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 10px;
  color: var(--text-soft); text-decoration: none; font-weight: 500;
  cursor: pointer; user-select: none;
}
.nav-item span { font-size: 15px; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); }
.sync-state {
  margin-top: 12px; font-size: 12px; color: var(--text-soft);
  padding: 8px 10px; background: var(--bg); border-radius: 8px; text-align: center;
}
.sync-state.cloud { color: var(--success); background: #dcfce7; }

/* ---------- Main ---------- */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  background: rgba(255,255,255,.9);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 18px; font-weight: 700; flex: 1; }
.menu-btn { display: none; font-size: 22px; background: none; border: none; cursor: pointer; color: var(--text); }

.view { padding: 20px; max-width: 1100px; width: 100%; margin: 0 auto; padding-bottom: 90px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

/* ---------- Cards & stats ---------- */
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.stat-num { font-size: 28px; font-weight: 800; color: var(--primary-dark); }
.stat-label { font-size: 13px; color: var(--text-soft); margin-top: 2px; }
.stat-icon { font-size: 22px; }

.section-title { font-size: 16px; font-weight: 700; margin: 4px 0 12px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--text-soft); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* ---------- Tables / lists ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { color: var(--text-soft); font-weight: 600; font-size: 13px; background: var(--bg); }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 13px 14px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow);
}
.avatar {
  width: 42px; height: 42px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary-dark); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 650; }
.item-sub { font-size: 13px; color: var(--text-soft); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-gray { background: var(--bg); color: var(--text-soft); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Modal ---------- */
#modal-root { position: fixed; inset: 0; z-index: 50; display: none; }
#modal-root.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.45); }
.modal {
  position: relative; max-width: 560px; width: calc(100% - 32px);
  margin: 6vh auto; background: var(--surface); border-radius: 16px;
  padding: 22px; max-height: 86vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal h3 { font-size: 18px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--text-soft); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.pill-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.pill { padding: 7px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-soft); }
.pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.note { font-size: 13px; color: var(--text-soft); background: var(--bg); border-radius: 10px; padding: 12px 14px; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px; overflow: auto; font-size: 13px; }

/* ---------- Tabbar (mobile) ---------- */
.tabbar { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: .25s; box-shadow: 4px 0 20px rgba(0,0,0,.1); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: block; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tab-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; color: var(--text-soft); text-decoration: none; padding: 4px 0;
  }
  .tab-item span { font-size: 11px; }
  .tab-item.active { color: var(--primary); }
  .form-grid { grid-template-columns: 1fr; }
  .hide-mobile { display: none; }
}
