:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #ebe8e2;
  --ink: #1f2328;
  --ink-2: #5b5f66;
  --line: #d9d5cc;
  --accent: #d9480f;
  --accent-ink: #ffffff;
  --accent-soft: #fde7dc;
  --good: #2b8a3e;
  --good-soft: #e3f4e6;
  --bad: #c92a2a;
  --bad-soft: #fde2e2;
  --warn: #b7791f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --surface-2: #2a2e33;
    --ink: #eceae6;
    --ink-2: #a3a7ad;
    --line: #353a40;
    --accent: #ff7a3d;
    --accent-ink: #15171a;
    --accent-soft: #3a2418;
    --good: #69db7c;
    --good-soft: #1d3324;
    --bad: #ff8787;
    --bad-soft: #3b1f1f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--ink);
  color: #fff;
  padding: calc(10px + var(--safe-top)) 16px 10px;
}
@media (prefers-color-scheme: dark) { .top { background: #0d0e10; } }
.top-row { display: flex; align-items: center; gap: 10px; max-width: 880px; margin: 0 auto; }
.brand { font-weight: 700; letter-spacing: .02em; font-size: 17px; flex: 1; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 800; }
.top .icon-btn { color: #fff; }
.search-wrap { max-width: 880px; margin: 10px auto 0; position: relative; }
.search-wrap input {
  width: 100%; border: 0; border-radius: 10px; padding: 12px 40px 12px 14px;
  background: #fff; color: #1f2328; font-size: 17px; outline: none;
}
.search-wrap input:focus { box-shadow: 0 0 0 3px var(--accent); }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: #777; font-size: 22px; width: 34px; height: 34px; cursor: pointer; }

/* ---------- layout ---------- */
main { max-width: 880px; margin: 0 auto; padding: 14px 16px calc(96px + var(--safe-bottom)); }
h1 { font-size: 22px; margin: 6px 0 14px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin: 22px 0 8px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.filter-row2 { display: flex; gap: 8px; margin-top: 8px; }
.filter-row2 select { flex: 1; min-width: 0; }
.count { margin: 12px 2px 8px; font-size: 13px; color: var(--ink-2); }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 14px; margin-bottom: 10px;
}
.result { cursor: pointer; }
.result.avoid { opacity: .72; border-color: var(--bad); }
.r-head { display: flex; align-items: flex-start; gap: 10px; }
.r-title { flex: 1; min-width: 0; }
.r-name { font-weight: 650; font-size: 17px; }
.r-sub { font-size: 14px; color: var(--ink-2); margin-top: 1px; }
.r-why { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.r-why b { color: var(--ink); font-weight: 600; }
.r-actions { display: flex; gap: 8px; margin-top: 12px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.type-mat { background: #e7f0fd; color: #1c5bb8; }
.badge.type-man { background: var(--accent-soft); color: var(--accent); }
.badge.type-mm { background: #efe6fb; color: #6b3fb8; }
.badge.type-srv { background: #e6f4f1; color: #127566; }
@media (prefers-color-scheme: dark) {
  .badge.type-mat { background: #1b2a40; color: #8fb8f5; }
  .badge.type-mm { background: #2c2140; color: #c3a6f5; }
  .badge.type-srv { background: #15302b; color: #7fd8c6; }
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.stars { color: #e8a317; letter-spacing: 1px; font-size: 14px; white-space: nowrap; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 9px 14px; font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; color: var(--ink);
  min-height: 42px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.flex { flex: 1; }
.btn.call { background: var(--good); border-color: var(--good); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; padding: 6px; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.btn svg { width: 18px; height: 18px; }

.fab {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-bottom)); z-index: 20;
  width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 18px rgba(0,0,0,.22); display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; }

/* ---------- detail ---------- */
.d-head { display: flex; gap: 10px; align-items: flex-start; }
.d-head h1 { margin: 0; flex: 1; }
.d-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.d-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 14px 0; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 15px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 10px; } }
.files { display: flex; flex-wrap: wrap; gap: 10px; }
.file { width: 96px; text-decoration: none; color: var(--ink); font-size: 12px; text-align: center; word-break: break-all; }
.file .thumb { width: 96px; height: 96px; border-radius: 10px; background: var(--surface-2) center/cover no-repeat; display: grid; place-items: center; font-weight: 700; color: var(--ink-2); margin-bottom: 4px; border: 1px solid var(--line); }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.field label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search], input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 90px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
@media (min-width: 560px) { .seg { grid-template-columns: repeat(4, 1fr); } }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 14px; font-weight: 600; cursor: pointer; }
.seg input:checked + span { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.rate { display: flex; gap: 2px; }
.rate button { border: 0; background: none; font-size: 28px; line-height: 1; padding: 2px; cursor: pointer; color: var(--line); }
.rate button.on { color: #e8a317; }
.rate-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rate-row .rate button { font-size: 22px; }
.catpick { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); max-height: 320px; overflow: auto; padding: 4px 10px 10px; }
.catpick .dom { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin: 12px 0 4px; }
.catpick label { display: inline-flex; align-items: center; gap: 6px; margin: 3px 10px 3px 0; font-size: 14px; font-weight: 400; cursor: pointer; }
.selected-cats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.sticky-save { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 70%, transparent); padding: 14px 0 calc(10px + var(--safe-bottom)); display: flex; gap: 10px; }

/* ---------- menu ---------- */
.menu-list a, .menu-list button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px; border: 0; background: none; text-align: left; text-decoration: none; color: var(--ink); font-size: 16px; cursor: pointer; border-bottom: 1px solid var(--line); }
.menu-list > :last-child { border-bottom: 0; }
.menu-list svg { width: 20px; height: 20px; color: var(--ink-2); }

/* ---------- import ---------- */
.imp-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.imp-row input[type=checkbox] { width: 20px; height: 20px; flex: none; }
.imp-row .t { flex: 1; min-width: 0; }
.imp-row .n { font-weight: 600; }
.imp-row .p { font-size: 13px; color: var(--ink-2); }
input[type=checkbox] { accent-color: var(--accent); }

/* ---------- categories admin ---------- */
.cat-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.cat-row input { flex: 1; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login .brand { color: var(--ink); font-size: 22px; margin-bottom: 18px; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 40px 10px; color: var(--ink-2); }
.empty .big { font-size: 17px; color: var(--ink); font-weight: 600; margin-bottom: 6px; }
#toast { position: fixed; left: 50%; bottom: calc(92px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 15px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.back { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; color: var(--ink-2); font-size: 15px; margin-bottom: 8px; }
.back svg { width: 18px; height: 18px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
