/* ---------- Токены темы ---------- */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --text: #1c1c1a;
  --muted: #6b6a66;
  --border: #e2e0da;
  --accent: #aa12aa;
  --accent-text: #ffffff;
  --accent-fg: #aa12aa;
  --accent-fill: #8f0f8f;
  --ok: #1f7a4d;
  --ok-bg: #e3f3ea;
  --warn: #8a5a00;
  --warn-bg: #fbf0d9;
  --danger: #b42318;
  --danger-bg: #fde8e6;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --surface: #1d1d1b; --surface-2: #262624; --text: #ecebe7; --muted: #a09e98;
    --border: #34332f; --accent: #aa12aa; --accent-text: #ffffff; --accent-fg: #e07ae0; --accent-fill: #8f0f8f;
    --ok: #6fd3a0; --ok-bg: #173a29; --warn: #f0c46a; --warn-bg: #3a2e14; --danger: #ff8a80; --danger-bg: #3d1a17;
    --shadow: 0 6px 24px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1d1d1b; --surface-2: #262624; --text: #ecebe7; --muted: #a09e98;
  --border: #34332f; --accent: #aa12aa; --accent-text: #ffffff; --accent-fg: #e07ae0; --accent-fill: #8f0f8f;
  --ok: #6fd3a0; --ok-bg: #173a29; --warn: #f0c46a; --warn-bg: #3a2e14; --danger: #ff8a80; --danger-bg: #3d1a17;
  --shadow: 0 6px 24px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

/* ---------- Основа ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}
a { color: var(--accent-fg); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 1rem; text-align: center; }
h2 { font-size: 1.2rem; margin: 2rem 0 .75rem; text-align: center; }
h3 { font-size: 1.05rem; margin: 0 0 .5rem; }
.wrap { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 16px; }
.main { flex: 1; padding-top: 28px; padding-bottom: 48px; }
.main.fill { display: flex; flex-direction: column; padding-bottom: 20px; }
.page-bottom { margin-top: auto; padding-top: 32px; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: .75rem 0; }

/* ---------- Шапка и меню ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; gap: 16px; height: 56px; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 16px; flex: 1; overflow-x: auto; white-space: nowrap; }
.nav a { color: var(--text); text-decoration: none; }
.nav a:hover { color: var(--accent-fg); }
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); color: var(--text);
}
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary, .menu summary:hover { background: var(--surface-2); }
.menu-panel {
  position: absolute; right: 0; top: 46px; z-index: 10; width: 260px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 6px;
}
.menu-panel a, .menu-panel .linklike { color: var(--text); text-decoration: none; padding: 6px 8px; border-radius: 6px; text-align: left; }
.menu-panel a:hover, .menu-panel .linklike:hover { background: var(--surface-2); }
.menu-label { font-size: .8rem; color: var(--muted); }
.menu-user { font-size: .85rem; color: var(--muted); padding: 0 8px; overflow: hidden; text-overflow: ellipsis; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; padding: 6px 4px; border: 0; background: transparent; color: var(--text); cursor: pointer; font: inherit; font-size: .85rem; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent-fill); color: var(--accent-text); }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }

/* ---------- Подвал ---------- */
.footer { border-top: 1px solid var(--border); background: var(--surface); padding: 10px 0; font-size: .85rem; }
.footer-inner { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; text-align: center; }
.footer-inner > * { white-space: nowrap; }
@media (max-width: 400px) { .footer { font-size: .76rem; } .footer-inner { gap: 5px; padding-left: 8px; padding-right: 8px; } }
.footer a { color: var(--muted); }

/* ---------- Компоненты ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 300px)); grid-auto-rows: 1fr; justify-content: center; }
/* Длинные названия/описания обрезаются, чтобы все карточки были одной высоты; полный текст — во всплывающей подсказке. */
.clamp-2, .clamp-4 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-2 { -webkit-line-clamp: 2; line-clamp: 2; }
.clamp-4 { -webkit-line-clamp: 4; line-clamp: 4; }
.grid > .card { margin-top: 0; display: flex; flex-direction: column; }
.grid > .card > .card-bottom { margin-top: auto; }
.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.center { text-align: center; }
.main > .row, .main > p, .main > form.row { justify-content: center; text-align: center; }
.flash { background: var(--ok-bg); color: var(--ok); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.offer-update { text-align: center; }
.offer-update .actions { margin: 8px 0 0; }
.offer-update form { margin: 0; }
.alert.danger { background: var(--danger-bg); color: var(--danger); }
.errors ul { margin: 0 0 16px; padding: 10px 14px 10px 32px; background: var(--danger-bg); color: var(--danger); border-radius: 8px; }
.validation-summary-valid { display: none; }
.field-validation-error { color: var(--danger); font-size: .85rem; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .8rem; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.muted { background: var(--surface-2); color: var(--muted); }
.price { font-size: 1.25rem; font-weight: 600; }
.price.small-price { font-size: 1rem; }
.badge + .price, .badge + .muted { margin-top: 6px; }

/* ---------- Формы ---------- */
form.stack, .stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; }
label.check input { margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 110px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--accent-fill); background: var(--accent-fill); color: var(--accent-text); text-decoration: none;
}
.btn.secondary { background: transparent; color: var(--accent-fg); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.btn-sm { padding: 4px 10px; font-size: .85rem; margin-top: 6px; }
/* Группа кнопок: на широком экране в ряд, на телефоне — друг под другом во всю ширину. */
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 16px 0 0; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 120px; text-align: left; }

fieldset.choice { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
fieldset.choice legend { font-size: .9rem; padding: 0 4px; }
[hidden] { display: none !important; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .82rem; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* ---------- Уведомления ---------- */
.notice { border-left: 3px solid var(--border); padding: 10px 14px; background: var(--surface); border-radius: 0 8px 8px 0; }
.notice.unread { border-left-color: var(--accent); }
.notice + .notice { margin-top: 8px; }
.notice { position: relative; }
.notice p { margin: 0 0 4px; white-space: pre-wrap; padding-right: 28px; }
.notice-close { position: absolute; top: 6px; right: 6px; margin: 0; }
.notice-close button {
  width: 26px; height: 26px; border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.notice-close button:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Юридические страницы ---------- */
.doc { max-width: 760px; margin-left: auto; margin-right: auto; }
.doc-link { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text); }
.doc-link:hover { border-color: var(--accent); }
.doc-link + .doc-link { margin-top: 0; }
.doc-card { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.doc-card > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.doc-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.doc > h2 { margin-top: 1.5rem; }
.placeholder { border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; color: var(--muted); }

@media (max-width: 600px) {
  /* Шапка в две строки: логотип и настройки сверху, ссылки снизу — чтобы ничего не обрезалось. */
  .topbar-inner { height: auto; flex-wrap: wrap; row-gap: 4px; padding-top: 8px; padding-bottom: 8px; }
  .brand { flex: 1; }
  .nav { order: 3; flex: 1 1 100%; justify-content: center; overflow: visible; flex-wrap: wrap; gap: 4px 18px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions > form { display: flex; flex-direction: column; }
  .doc-card-actions { width: 100%; }
  .doc-card-actions .btn { flex: 1; }
  .row > .btn, .row > form, .row > form > .btn { flex: 1 1 auto; }
  h1 { font-size: 1.35rem; }
  .grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .nav { gap: 12px; font-size: .92rem; }
}
