/* Общие стили справочника и админки */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --surface-3: #e7e9ee;
  --text: #15171c;
  --text-2: #5b6170;
  --text-3: #8a90a0;
  --border: #e3e5ea;
  --accent: #d6202a;
  --accent-2: #b3141d;
  --accent-soft: #fde8e9;
  --accent-text: #ffffff;
  --link: #2a6fdb;
  --ok: #1f9d55;
  --ok-soft: #e3f6ec;
  --warn: #c27c0e;
  --warn-soft: #fdf3e1;
  --danger: #d6202a;
  --danger-soft: #fde8e9;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-2: 0 8px 24px rgba(16, 24, 40, .12), 0 2px 6px rgba(16, 24, 40, .06);
  --shadow-3: 0 24px 64px rgba(16, 24, 40, .24);
  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --surface-3: #2a2f39;
    --text: #eef0f4;
    --text-2: #a7adbb;
    --text-3: #7a8191;
    --border: #2a2f39;
    --accent: #f0464f;
    --accent-2: #ff6a71;
    --accent-soft: #3a1c1f;
    --link: #6aa5ff;
    --ok: #3ccf7d;
    --ok-soft: #173326;
    --warn: #f0b04a;
    --warn-soft: #3a2d15;
    --danger: #ff6a71;
    --danger-soft: #3a1c1f;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 8px 24px rgba(0, 0, 0, .45);
    --shadow-3: 0 24px 64px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #20242c;
  --surface-3: #2a2f39;
  --text: #eef0f4;
  --text-2: #a7adbb;
  --text-3: #7a8191;
  --border: #2a2f39;
  --accent: #f0464f;
  --accent-2: #ff6a71;
  --accent-soft: #3a1c1f;
  --link: #6aa5ff;
  --ok: #3ccf7d;
  --ok-soft: #173326;
  --warn: #f0b04a;
  --warn-soft: #3a2d15;
  --danger: #ff6a71;
  --danger-soft: #3a1c1f;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, .45);
  --shadow-3: 0 24px 64px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 14px; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; }
.btn.small.icon { width: 28px; }

/* ---------- поля ---------- */
.input, .textarea, .select {
  width: 100%; min-height: 38px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; line-height: 1.5; min-height: 80px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.hint { font-size: 12px; color: var(--text-3); }

/* ---------- метки ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- содержимое сообщений ---------- */
.rich { white-space: normal; overflow-wrap: anywhere; }
.rich a { color: var(--link); }
.rich code, .rich pre { font-family: var(--mono); font-size: .92em; background: var(--surface-2); border-radius: 4px; }
.rich code { padding: 1px 4px; }
.rich pre { padding: 8px 10px; white-space: pre-wrap; }
.rich blockquote { margin: 6px 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--accent); color: var(--text-2); }
.rich tg-spoiler, .rich .spoiler { background: var(--text-3); color: transparent; border-radius: 3px; cursor: pointer; }
.rich tg-spoiler.open, .rich .spoiler.open { background: transparent; color: inherit; }

.file-card {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  text-decoration: none !important;
  transition: background .15s;
}
.file-card:hover { background: var(--surface-3); }
.file-ico {
  flex: none; width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; letter-spacing: .02em;
}
.file-ico.doc { background: #2a6fdb; }
.file-ico.img { background: #1f9d55; }
.file-ico.arc { background: #8b5cf6; }
.file-ico.cad { background: #f08c00; }
.file-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.file-sub { font-size: 12px; color: var(--text-3); }

.map-card {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: var(--radius); background: var(--surface-2); color: var(--text);
  text-decoration: none !important;
}
.map-pin { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--ok); color: #fff; font-size: 20px; }

/* ---------- окна ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 12, 16, .5); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 16px;
  animation: fade .15s ease-out;
}
.modal {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border-radius: var(--radius-l); box-shadow: var(--shadow-3);
  animation: pop .18s cubic-bezier(.2, .9, .3, 1.2);
}
.modal-head { display: flex; align-items: center; gap: 8px; padding: 18px 20px 6px; }
.modal-head h3 { margin: 0; font-size: 18px; flex: 1; }
.modal-body { padding: 10px 20px 4px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 20px; }

.toasts { position: fixed; z-index: 200; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: min(520px, calc(100vw - 32px));
  padding: 10px 16px; border-radius: 999px;
  background: #15171c; color: #fff; box-shadow: var(--shadow-2);
  font-size: 14px; font-weight: 500; animation: rise .2s ease-out;
}
.toast.ok::before { content: "✓ "; color: #3ccf7d; font-weight: 800; }
.toast.err { background: var(--danger); }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.center-fill { min-height: 60vh; display: grid; place-items: center; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.lightbox {
  position: fixed; inset: 0; z-index: 150; background: rgba(0, 0, 0, .92);
  display: grid; place-items: center; animation: fade .15s;
}
.lightbox img { max-width: 96vw; max-height: 88vh; object-fit: contain; border-radius: 6px; }
.lightbox .lb-close, .lightbox .lb-prev, .lightbox .lb-next {
  position: absolute; border: 0; background: rgba(255, 255, 255, .12); color: #fff;
  width: 44px; height: 44px; border-radius: 50%; font-size: 22px; cursor: pointer;
}
.lightbox .lb-close { top: 16px; right: 16px; }
.lightbox .lb-prev { left: 16px; top: 50%; }
.lightbox .lb-next { right: 16px; top: 50%; }
.lightbox .lb-count { position: absolute; bottom: 18px; color: #fff; opacity: .7; font-size: 13px; }

mark { background: #ffe58a; color: inherit; border-radius: 3px; padding: 0 1px; }
:root[data-theme="dark"] mark { background: #6b5513; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) mark { background: #6b5513; } }
