:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --chip: #eef2ff;
  --input: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
  --radius: 12px;
  --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #131c2e;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --line: #23304a;
    --accent: #3b82f6;
    --chip: #1e2a44;
    --input: #0f172a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .back { border: 0; background: none; font-size: 22px; padding: 0 6px 0 0; cursor: pointer; color: var(--accent); }
main { padding: 12px 16px calc(var(--nav-h) + 90px); max-width: 760px; margin: 0 auto; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11.5px;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.on { color: var(--accent); font-weight: 600; }

@media (min-width: 900px) {
  .nav { top: 0; bottom: 0; right: auto; width: 88px; height: auto; flex-direction: column; justify-content: flex-start; padding-top: 16px; border-top: 0; border-right: 1px solid var(--line); }
  .nav a { flex: 0 0 72px; }
  .top, main { margin-left: 88px; }
  main { padding-bottom: 100px; }
}

/* ---------- элементы ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  text-decoration: none; color: inherit; cursor: pointer;
}
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .right { text-align: right; white-space: nowrap; }
.row .chev { color: var(--muted); }
.inactive { opacity: .55; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--chip); font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.section-title { margin: 18px 2px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .search { flex: 1 1 180px; }

input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--input); outline: none; min-height: 44px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }

.form { display: flex; flex-direction: column; gap: 14px; padding: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 10px; }
.check label { margin: 0; color: var(--text); font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .6; }
.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 9;
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 16px rgba(37,99,235,.35); text-decoration: none;
  display: flex; align-items: center; justify-content: center;
}

.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg a { flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg a.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* редактор полей категории */
.fdef { padding: 12px; display: flex; flex-direction: column; gap: 10px; border: 1px dashed var(--line); border-radius: 10px; }
.fdef .head { display: flex; gap: 8px; align-items: center; }
.fdef .head input { flex: 1; }
.fdef .x { border: 0; background: none; color: var(--danger); font-size: 22px; cursor: pointer; padding: 0 4px; }
.inherited { padding: 10px 12px; border-radius: 10px; background: var(--chip); font-size: 14px; }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { width: 100%; max-width: 360px; }
.login .logo { width: 56px; height: 56px; margin: 0 auto 6px; display: block; }
.login h1 { text-align: center; margin: 0 0 4px; font-size: 22px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 12px;
  background: #111827; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 14px;
}
.toast.err { background: var(--danger); }
.spinner { text-align: center; color: var(--muted); padding: 30px; }
