:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e2e7ec;
  --text: #15202b;
  --muted: #64748b;
  --accent: #0f766e;
  --accent-2: #14b8a6;
  --accent-soft: #e6f4f2;
  --ok: #15803d;
  --ok-soft: #e8f6ed;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --err: #b91c1c;
  --err-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1317; --surface: #151d22; --surface-2: #1a242a; --border: #26333b;
    --text: #e6edf1; --muted: #8fa1ad; --accent: #2dd4bf; --accent-2: #5eead4; --accent-soft: #123331;
    --ok: #4ade80; --ok-soft: #12291c; --warn: #fbbf24; --warn-soft: #2d230e; --err: #f87171; --err-soft: #321616;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 6px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.muted { color: var(--muted); }
.error { color: var(--err); margin: 0; }

/* ---------- бутони и полета ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 550; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #04201d; } }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; width: 100%;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input.changed { border-color: var(--warn); background: var(--warn-soft); }

/* ---------- вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 16px; }

/* ---------- горна лента ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 17px; letter-spacing: -.01em; }
.brand.big { font-size: 22px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); position: relative; flex: none; }
.logo::before { content: ""; position: absolute; inset: 6px 8px; border: 2px solid #fff; border-radius: 2px; border-top-right-radius: 6px; }
.logo::after { content: ""; position: absolute; left: 11px; right: 11px; top: 13px; height: 2px; background: #fff; box-shadow: 0 4px 0 #fff; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  padding: 10px 20px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 9px; cursor: pointer; }
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.active { color: var(--accent); background: var(--accent-soft); }
.bottom-nav { display: none; }

/* ---------- документи ---------- */
.docs { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; gap: 20px; padding: 20px; max-width: 1500px; margin: 0 auto; align-items: start; }
.col-list { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.col-detail { position: sticky; top: 76px; min-width: 0; max-height: calc(100vh - 96px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.drop {
  border: 2px dashed var(--border); background: var(--surface); border-radius: var(--radius);
  padding: 18px; display: grid; grid-template-columns: auto 1fr; gap: 12px 14px; align-items: center;
  transition: border-color .15s, background .15s; outline: none;
}
.drop:focus-visible, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); position: relative; }
.drop-icon::before { content: ""; position: absolute; left: 50%; top: 11px; width: 2px; height: 18px; background: var(--accent); transform: translateX(-50%); }
.drop-icon::after { content: ""; position: absolute; left: 50%; top: 11px; width: 10px; height: 10px; border-left: 2px solid var(--accent); border-top: 2px solid var(--accent); transform: translateX(-50%) rotate(45deg); transform-origin: center; margin-top: 1px; }
.drop-text { display: flex; flex-direction: column; font-size: 14px; }
.drop-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.drop-actions .btn { flex: 1; }
#cameraBtn { display: none; }
@media (pointer: coarse) { #cameraBtn { display: inline-flex; } }

.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar .count { flex: 1; font-size: 13px; color: var(--muted); font-weight: 600; }
.privacy { font-size: 12px; margin: -4px 2px 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; padding: 2px; background: var(--surface-2); }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 7px; cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.code-actions { align-items: center; }
.toolbar input { flex: 1; min-width: 0; }
.toolbar select { width: auto; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 210px; display: flex; flex-direction: column; }
.menu-list button { border: 0; background: transparent; color: var(--text); text-align: left; padding: 9px 12px; border-radius: 7px; font: inherit; cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list .danger-item { color: var(--err); border-top: 1px solid var(--border); border-radius: 0 0 7px 7px; }

.stats { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.stats .chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; color: var(--muted); }
.stats .chip b { color: var(--text); }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  transition: border-color .15s, box-shadow .15s;
}
.item:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.item.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.item .t { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.item .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .progress { grid-column: 1 / -1; height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.item .progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.item .progress.indeterminate i { width: 35%; animation: slide 1.1s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- детайли ---------- */
.placeholder { padding: 80px 20px; text-align: center; color: var(--muted); }
.ph-icon { width: 64px; height: 80px; margin: 0 auto 14px; border: 2px solid var(--border); border-radius: 6px 18px 6px 6px; position: relative; }
.ph-icon::after { content: ""; position: absolute; left: 12px; right: 12px; top: 26px; height: 2px; background: var(--border); box-shadow: 0 10px 0 var(--border), 0 20px 0 var(--border); }
.d-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; background: var(--surface); z-index: 5; }
.d-title { display: flex; align-items: center; gap: 10px; }
.d-title h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-back { display: none; }
.d-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.d-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.d-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; }
.d-tabs::-webkit-scrollbar { display: none; }
.d-tabs button { border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--muted); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.d-tabs button.active { color: var(--accent); background: var(--accent-soft); }
.d-tabs .count { font-size: 11px; background: var(--surface-2); border-radius: 999px; padding: 0 6px; margin-left: 4px; }
.d-body { padding: 18px; }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.summary .s { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.summary .s span { display: block; font-size: 12px; color: var(--muted); }
.summary .s b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary .s.total { background: var(--accent-soft); border-color: transparent; }
.summary .s.total b { color: var(--accent); }

.notes { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.note { font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); }
.note.info { background: var(--accent-soft); color: var(--accent); }
.note.err { background: var(--err-soft); color: var(--err); }

.groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.group { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.group.wide { grid-column: 1 / -1; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid .full { grid-column: 1 / -1; }
.savebar { position: sticky; bottom: 0; margin: 16px -18px -18px; padding: 12px 18px; background: var(--surface); border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.savebar .muted { flex: 1; font-size: 13px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 650; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table input { padding: 6px 8px; border-radius: 7px; min-width: 60px; }
.table td.num input { text-align: right; }
.table .desc input { min-width: 200px; }
.table tfoot td { font-weight: 700; background: var(--surface-2); }

pre.code { margin: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; overflow: auto; font: 13px/1.5 var(--mono); max-height: 70vh; white-space: pre; }
pre.code.wrap { white-space: pre-wrap; word-break: break-word; }
.code-actions { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 8px; }

.checks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.checks li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: 9px; background: var(--surface-2); font-size: 14px; }
.checks .dot { width: 18px; height: 18px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; margin-top: 1px; }
.checks .ok .dot { background: var(--ok); }
.checks .bad .dot { background: var(--err); }
.checks .warn .dot { background: var(--warn); }
.meter { height: 8px; background: var(--surface-2); border-radius: 8px; overflow: hidden; margin: 6px 0 16px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 8px; }

/* ---------- страници ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kv { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 6px 0; }
.kv > span:first-child { width: 110px; color: var(--muted); font-size: 13px; }
.endpoint { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.endpoint summary { padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; align-items: center; list-style: none; }
.endpoint summary::-webkit-details-marker { display: none; }
.endpoint .m { font: 700 12px var(--mono); padding: 3px 7px; border-radius: 6px; min-width: 58px; text-align: center; }
.m.GET { background: #e0f2fe; color: #0369a1; } .m.POST { background: #dcfce7; color: #15803d; }
.m.PATCH { background: #fef3c7; color: #b45309; } .m.DELETE { background: #fee2e2; color: #b91c1c; } .m.PUT { background: #ede9fe; color: #6d28d9; }
.endpoint .p { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.endpoint .dsc { color: var(--muted); font-size: 13px; margin-left: auto; text-align: right; }
.endpoint .body { padding: 0 14px 14px; }

dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, calc(100% - 24px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 15, 20, .45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }

.toasts { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100% - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: pop .2s ease-out; }
.toast.err { background: var(--err); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- мобилни ---------- */
@media (max-width: 1000px) {
  .docs { grid-template-columns: 1fr; padding: 12px 12px 90px; }
  .col-detail { position: fixed; inset: 0; top: 0; max-height: none; border-radius: 0; border: 0; z-index: 40; transform: translateX(100%); transition: transform .22s ease; box-shadow: none; }
  .col-detail.open { transform: none; }
  .d-back { display: inline-flex; }
  .d-head { padding-top: max(12px, env(safe-area-inset-top)); }
  .topbar .tabs { display: none; }
  .topbar { justify-content: space-between; padding: 10px 14px; }
  .bottom-nav {
    display: flex; position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 8px max(6px, env(safe-area-inset-bottom));
  }
  .bottom-nav button { flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 12px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px; border-radius: 10px; cursor: pointer; }
  .bottom-nav button.active { color: var(--accent); }
  .bottom-nav .i { width: 22px; height: 22px; border: 2px solid currentColor; border-radius: 5px; }
  .bottom-nav .i-parties { border-radius: 50% 50% 6px 6px; }
  .bottom-nav .i-api { border-radius: 50%; border-style: dashed; }
  .page { padding: 16px 12px 100px; }
  .page-head { flex-direction: column; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .groups, .grid { grid-template-columns: 1fr; }
  .d-body { padding: 14px; }
  .savebar { margin: 16px -14px -14px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .endpoint .dsc { display: none; }
  .toasts { left: 16px; right: 16px; bottom: 80px; max-width: none; }
}
@media (max-width: 420px) {
  .toolbar { flex-wrap: wrap; }
  .toolbar input { flex-basis: 100%; }
  .toolbar select, .toolbar .menu { flex: 1; }
  .toolbar .menu .btn { width: 100%; }
  .d-actions .btn { flex: 1 1 calc(33% - 6px); }
}
