/* Design tokens and shared components for every page. Page-specific styles live next to their JS. */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #0f1b2d;
  --text-2: #3d4757;          /* secondary text: dark enough to read, never light grey */
  --muted: #5b6575;
  --accent: #3559f0;
  --accent-hover: #2445d4;
  --accent-soft: #eaeefe;
  --pro: #0b7a55;
  --pro-soft: #e3f4ec;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn-soft: #fff6e0;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 4px 16px rgba(15, 27, 45, .04);
  --shadow-pop: 0 8px 28px rgba(15, 27, 45, .16);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 264px;
  --sidebar-rail: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: #f0c4c4; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.on { color: var(--accent); }
.icon-btn svg, .btn svg { width: 20px; height: 20px; flex: none; }

/* ---------- form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 14px; }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); outline: none;
}
.textarea { height: auto; min-height: 90px; padding: 10px 14px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field .hint { font-size: 13px; color: var(--muted); }
.form-error {
  background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 14px; margin-bottom: 14px;
}

/* ---------- cards, badges ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.badge-pro {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 11px;
  background: var(--pro); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .2px;
}
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 11px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); }

/* ---------- switch ---------- */
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 13px; background: var(--border-strong); transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:disabled + span { opacity: .5; cursor: default; }

/* ---------- top bar (public pages) ---------- */
.topbar {
  height: 64px; display: flex; align-items: center; gap: 24px; padding: 0 28px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--text) !important; text-decoration: none !important; }
.brand img { width: 30px; height: 30px; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.topbar nav a { color: var(--text-2); font-weight: 600; padding: 8px 12px; border-radius: 8px; text-decoration: none; }
.topbar nav a:hover, .topbar nav a.active { background: var(--surface-2); color: var(--text); }
.topbar .actions { display: flex; gap: 10px; align-items: center; }

/* ---------- app shell (sidebar + main; the details live in app.css) ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav button.nav-item {
  display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 7px 10px; border-radius: 8px;
  color: var(--text); font-size: 15px; font-weight: 500; line-height: 1.3; text-decoration: none;
  border: 2px solid transparent; background: none; width: 100%; text-align: left; cursor: pointer;
}
.nav a svg, .nav button.nav-item svg { width: 22px; height: 22px; color: var(--text); flex: none; }
.nav a:hover, .nav button.nav-item:hover { background: var(--surface-2); }
.nav a.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.nav a.active svg { color: var(--accent); }
.sidebar .spacer { flex: 1; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--pro); color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex: none; text-transform: uppercase;
}
.main { flex: 1; min-width: 0; }
.page-title { font-size: 26px; font-weight: 750; margin-bottom: 18px; }

/* ---------- toast & modal ---------- */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #0f1b2d; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow-pop); animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.modal-back { position: fixed; inset: 0; background: rgba(15, 27, 45, .45); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-pop); width: 100%; max-width: 460px; padding: 26px; max-height: 90vh; overflow: auto; }
.modal h3 { font-size: 20px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---------- popover menu ---------- */
.menu { position: absolute; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-pop); padding: 6px; min-width: 200px; }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; color: var(--text); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--surface-2); }

/* ---------- empty states / tables ---------- */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; color: var(--border-strong); margin-bottom: 10px; }
.empty h3 { color: var(--text); font-size: 18px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }

.mobile-only { display: none !important; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 70; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-pop); }
  .shell.nav-open .sidebar { transform: none; }
  .topbar { padding: 0 16px; gap: 12px; }
  .topbar nav { display: none; }
  .mobile-only { display: inline-flex !important; }
  .topbar.nav-open nav {
    display: flex; flex-direction: column; position: absolute; left: 0; right: 0; top: 64px;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 12px 12px;
    box-shadow: var(--shadow-pop);
  }
  .topbar .actions .btn-ghost { display: none; }
}
@media (max-width: 420px) {
  .topbar .actions .btn { height: 36px; padding: 0 12px; font-size: 14px; }
  .topbar .brand { font-size: 16px; }
}
