:root {
  --bg: #0a0b0d;
  --panel: #121417;
  --panel-2: #171a1f;
  --line: #23272e;
  --line-2: #2e343c;
  --text: #e8eaed;
  --muted: #8b929c;
  --accent: #c8ff2e;
  --accent-dim: #a8d922;
  --danger: #ff5d5d;
  --warn: #ffb020;
  --ok: #3ddc97;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
a { color: var(--accent); text-decoration: none; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(900px 500px at 50% -10%, #17200a 0%, var(--bg) 60%); }
.login-card { width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: grid; gap: 12px; }
.login-card h1 { font-size: 18px; }
.brand-mark { width: 40px; height: 40px; border-radius: 11px; background: var(--accent); color: #0a0b0d; display: grid; place-items: center; font-weight: 800; font-size: 20px; }
.brand-mark.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; }
.err { color: var(--danger); font-size: 13px; margin: 0; min-height: 16px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: #0c0e11; display: flex; flex-direction: column; padding: 18px 14px; gap: 18px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.logo b { display: block; font-size: 15px; }
#nav { display: grid; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px; color: var(--muted); cursor: pointer; font-weight: 520; border: 1px solid transparent; }
.nav-item:hover { background: #14171b; color: var(--text); }
.nav-item.active { background: #191d22; color: var(--text); border-color: var(--line); }
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0; }
.nav-item.active .dot { opacity: 1; }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--muted); font-family: var(--mono); }
.side-foot { margin-top: auto; display: grid; gap: 8px; }
.save-chip { font-size: 12px; color: var(--muted); padding: 6px 10px; border-radius: 8px; background: #12151a; border: 1px solid var(--line); text-align: center; }
.save-chip.dirty { color: var(--warn); border-color: #3a2f10; background: #1c1710; }
.save-chip.saving { color: var(--accent); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 26px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: rgba(10, 11, 13, 0.86); backdrop-filter: blur(10px); z-index: 5; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.view { padding: 22px 26px 80px; }

/* ---------- bits ---------- */
.btn { appearance: none; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 560; cursor: pointer; }
.btn:hover { border-color: #3d444e; }
.btn.primary { background: var(--accent); color: #0a0b0d; border-color: var(--accent); font-weight: 680; }
.btn.primary:hover { background: var(--accent-dim); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { color: var(--danger); border-color: #402225; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.pill { font-size: 12px; padding: 5px 10px; border-radius: 999px; background: #14171c; border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--ok); border-color: #1d3b2c; background: #0f1a15; }
.pill.warn { color: var(--warn); border-color: #3a2f10; background: #1a1509; }
.pill.bad { color: var(--danger); border-color: #402225; background: #1a0f11; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .n { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.kpi .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 8px; }

label.field { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); }
label.field > span { font-weight: 560; }
input[type="text"], input[type="number"], input[type="password"], input[type="url"], textarea, select {
  width: 100%; background: #0e1013; border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 9px 11px; font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: #46505c; box-shadow: 0 0 0 3px rgba(200, 255, 46, 0.08); }
textarea { resize: vertical; min-height: 70px; font-size: 13px; }
input[dir="rtl"], textarea[dir="rtl"] { text-align: right; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
td { padding: 9px 10px; border-bottom: 1px solid #191d22; vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #14171b; }
tr.sel td { background: #171d12; }
.tbl-wrap { max-height: 62vh; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }

.chip { display: inline-block; font-size: 11.5px; padding: 3px 8px; border-radius: 999px; background: #1a1e24; color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.accent { background: #1e2609; color: var(--accent); border-color: #33400f; }
.chip.gym { background: #1b1a26; color: #b3a8ff; border-color: #2c2a45; }
.chip.home { background: #0f1f1a; color: #63d6b0; border-color: #1b3a31; }
.chip.muscle { background: #241a1a; color: #ff9b8a; border-color: #402a28; }
.chip.burn { background: #241f12; color: #ffc861; border-color: #3f3418; }

.switch { position: relative; width: 38px; height: 22px; border-radius: 999px; background: #23272e; border: 1px solid var(--line-2); cursor: pointer; transition: 0.15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #7c828b; transition: 0.15s; }
.switch.on { background: #24310b; border-color: #4b5f14; }
.switch.on::after { left: 18px; background: var(--accent); }

.searchbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.searchbar input[type="text"] { max-width: 300px; }
.searchbar select { width: auto; min-width: 120px; }

.bar { height: 8px; border-radius: 999px; background: #1b1f25; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

.list { display: grid; gap: 6px; }
.list-item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2); cursor: pointer; }
.list-item:hover { border-color: var(--line-2); }
.list-item.active { border-color: #4b5f14; background: #161c0f; }

.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 520px; max-width: 94vw; background: #0e1013; border-left: 1px solid var(--line); z-index: 20; display: flex; flex-direction: column; box-shadow: -30px 0 60px rgba(0, 0, 0, 0.5); }
.drawer-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.drawer-body { padding: 18px; overflow: auto; display: grid; gap: 14px; }
.drawer-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; }

.seg { display: inline-flex; background: #0e1013; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { background: transparent; border: 0; color: var(--muted); padding: 6px 11px; border-radius: 7px; font: inherit; font-size: 12.5px; cursor: pointer; }
.seg button.on { background: #1d2229; color: var(--text); }

.steps-editor { display: grid; gap: 8px; }
.step-row { display: flex; gap: 8px; align-items: flex-start; }
.step-row .num { width: 22px; height: 30px; display: grid; place-items: center; color: var(--muted); font-family: var(--mono); font-size: 11px; flex: none; }
.step-row textarea { min-height: 44px; }

.issue { display: flex; gap: 10px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font-size: 13px; }
.issue .tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 7px; border-radius: 6px; height: fit-content; flex: none; margin-top: 2px; }
.issue.err { border-color: #3a1f22; background: #170f11; }
.issue.err .tag { background: #3a1f22; color: #ff8f8f; }
.issue.warn { border-color: #3a2f10; background: #17130a; }
.issue.warn .warn .tag, .issue.warn .tag { background: #3a2f10; color: var(--warn); }
.issue .path { color: var(--muted); font-family: var(--mono); font-size: 11px; }

.phone { width: 300px; border-radius: 34px; border: 1px solid #2c323a; background: #07080a; padding: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); }
.phone-screen { border-radius: 24px; background: linear-gradient(170deg, #101310 0%, #0a0b0d 55%); padding: 20px 18px; min-height: 520px; display: flex; flex-direction: column; gap: 14px; }
.phone h3 { font-size: 22px; line-height: 1.15; letter-spacing: -0.02em; }
.pw-opt { border: 1px solid #242a31; border-radius: 14px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pw-opt.on { border-color: var(--accent); background: rgba(200, 255, 46, 0.06); }
.pw-cta { background: var(--accent); color: #0a0b0d; text-align: center; padding: 14px; border-radius: 14px; font-weight: 700; margin-top: auto; }
.pw-bullets { display: grid; gap: 8px; font-size: 13.5px; color: #cfd4da; }
.pw-bullets div::before { content: "✓"; color: var(--accent); margin-right: 8px; font-weight: 700; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1b2027; border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 11px; opacity: 0; transition: 0.2s; pointer-events: none; font-size: 13px; z-index: 60; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: 640px; max-width: 100%; max-height: 86vh; overflow: auto; }

.empty { padding: 40px; text-align: center; color: var(--muted); }
.hr { height: 1px; background: var(--line); margin: 4px 0; }
.tag-sel { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-sel .t { padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0e1013; color: var(--muted); font-size: 12.5px; cursor: pointer; }
.tag-sel .t.on { border-color: #4b5f14; color: var(--accent); background: #161c0f; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
  #nav { display: flex; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .g2 { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
}
