:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --border: #e2e5ea;
    --text: #1b1f27;
    --muted: #6b7280;
    --accent: #2457d6;
    --accent-hover: #1c46b0;
    --accent-soft: #e8eefc;
    --danger: #c62f2f;
    --danger-soft: #fdecec;
    --ok: #1f7a4d;
    --ok-soft: #e6f4ec;
    --warn-soft: #fff5db;
    --topbar: #152033;
    --topbar-text: #e7ebf3;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --avia: #2457d6;
    --hotel: #8a3ffc;
    --rail: #c05a00;
    --transfer: #0f7b6c;
    --vip: #a0700a;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f131a;
        --surface: #171c25;
        --surface-2: #1d2330;
        --border: #2a3242;
        --text: #e6e9ef;
        --muted: #98a1b3;
        --accent: #6b94ff;
        --accent-hover: #8aabff;
        --accent-soft: #1d2a4a;
        --danger: #ff6b6b;
        --danger-soft: #3a1c1f;
        --ok: #4cc38a;
        --ok-soft: #173327;
        --warn-soft: #3a3016;
        --topbar: #0b0f15;
        --shadow: none;
        --avia: #7ea2ff;
        --hotel: #b88cff;
        --rail: #f0964a;
        --transfer: #4cc3b0;
        --vip: #e3b64f;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 .75rem; font-weight: 650; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .75rem; font-weight: 600; }
.card > h2:first-child, .section-head h2 { margin-top: 0; }

.muted { color: var(--muted); }
.small { font-size: .85em; }
.hint { display: block; color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.req { color: var(--danger); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ── Top bar ───────────────────────────────────────── */
.topbar { background: var(--topbar); color: var(--topbar-text); }
.topbar-inner {
    max-width: 1400px; margin: 0 auto; padding: 0 20px;
    display: flex; align-items: center; gap: 28px; min-height: 56px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 650; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark { display: block; width: 32px; height: 32px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--topbar-text); opacity: .8; padding: 8px 12px; border-radius: 8px; }
.nav a:hover { opacity: 1; background: rgba(255, 255, 255, .08); text-decoration: none; }
.nav a.active { opacity: 1; background: rgba(255, 255, 255, .14); }
.user { display: flex; align-items: center; gap: 14px; }
.user-name { color: var(--topbar-text); }
.user .btn-link { color: var(--topbar-text); opacity: .75; }
.user form { margin: 0; }

/* ── Layout ────────────────────────────────────────── */
.container { max-width: 1400px; width: 100%; margin: 0 auto; padding: 24px 20px 40px; flex: 1; }
.footer {
    text-align: center; color: var(--muted); font-size: .85rem;
    padding: 18px 20px; border-top: 1px solid var(--border); background: var(--surface);
}
.footer strong { color: var(--text); font-weight: 600; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card.narrow { max-width: 440px; margin: 40px auto; }
.card.empty { text-align: center; color: var(--muted); padding: 40px; }
p.empty { color: var(--muted); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.count {
    display: inline-block; font-size: .8rem; font-weight: 600; color: var(--muted);
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 9px; vertical-align: middle;
}

.dict-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.dict-side .card { margin-bottom: 18px; }
@media (max-width: 900px) { .dict-layout { grid-template-columns: 1fr; } }

/* ── Forms ─────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; border: 0; padding: 0; }
.field > span:first-child, .field > label, .field legend { font-weight: 550; font-size: .9rem; }
.field legend { padding: 0; margin-bottom: 5px; }

input, select, textarea {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px; width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.readonly, input[readonly] { background: var(--surface-2); color: var(--muted); }
input.input-validation-error, select.input-validation-error { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .85rem; }
.field-error:empty { display: none; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; max-width: 900px; }
.span-2 { grid-column: span 2; }
@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
}
[hidden] { display: none !important; }

.actions { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 14px; }
.inline-form input { width: auto; flex: 1; min-width: 180px; }
.inline-form input.short { flex: 0 1 180px; min-width: 120px; }
tr.editing .inline-form { margin: 0; }

.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segment { position: relative; }
.segment input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segment span {
    display: inline-block; padding: 8px 18px; border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer; background: var(--surface); user-select: none; font-weight: 500;
}
.segment input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.segment input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── Buttons ───────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font: inherit; font-weight: 550; padding: 8px 16px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.wide { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }

/* ── Alerts ────────────────────────────────────────── */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert.error ul { margin: 0; padding-left: 18px; }
.validation-summary-valid { display: none; }

/* ── Autocomplete ──────────────────────────────────── */
.autocomplete { position: relative; }
.ac-list {
    position: absolute; top: 66px; left: 0; right: 0; z-index: 20; margin: 0; padding: 4px; list-style: none;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .14); max-height: 320px; overflow: auto;
}
.ac-list li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.ac-list li.active, .ac-list li:hover { background: var(--accent-soft); }
.ac-list li.ac-empty { color: var(--muted); cursor: default; background: none; }
.ac-id { color: var(--muted); font-size: .85rem; white-space: nowrap; }
input.chosen { border-color: color-mix(in srgb, var(--ok) 60%, var(--border)); }
input.unmatched { border-color: var(--danger); }

/* ── Tables ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; padding: 0; }
.card.table-wrap { padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
    text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em;
    background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table .clip { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .sub { color: var(--muted); font-size: .8rem; }
.table tr.inactive td { color: var(--muted); }
.row-actions { display: flex; gap: 14px; align-items: center; }
.row-actions form { margin: 0; }
.card:not(.table-wrap) .table-wrap { border: 1px solid var(--border); border-radius: 8px; }

.tag {
    display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text); white-space: nowrap;
}
.tag-avia { color: var(--avia); border-color: color-mix(in srgb, var(--avia) 35%, transparent); background: color-mix(in srgb, var(--avia) 10%, transparent); }
.tag-hotel { color: var(--hotel); border-color: color-mix(in srgb, var(--hotel) 35%, transparent); background: color-mix(in srgb, var(--hotel) 10%, transparent); }
.tag-rail { color: var(--rail); border-color: color-mix(in srgb, var(--rail) 35%, transparent); background: color-mix(in srgb, var(--rail) 10%, transparent); }
.tag-transfer { color: var(--transfer); border-color: color-mix(in srgb, var(--transfer) 35%, transparent); background: color-mix(in srgb, var(--transfer) 10%, transparent); }
.tag-vip { color: var(--vip); border-color: color-mix(in srgb, var(--vip) 35%, transparent); background: color-mix(in srgb, var(--vip) 10%, transparent); }
.tag-admin { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.tag-ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.tag-off { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

.plain-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }

/* ── Filters ───────────────────────────────────────── */
.filters { padding: 0; }
.filters summary { cursor: pointer; padding: 14px 22px; font-weight: 600; user-select: none; }
.filters[open] summary { border-bottom: 1px solid var(--border); }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); column-gap: 16px; padding: 18px 22px 8px; }
.filter-actions { grid-column: 1 / -1; margin-bottom: 14px; }
.range { display: flex; align-items: center; gap: 6px; }
.range input { min-width: 0; }

.pager { display: flex; justify-content: center; align-items: center; gap: 14px; }

/* ── Admin ─────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs a { padding: 9px 16px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.invite-list { display: grid; gap: 10px; }
.invite { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.invite.fresh { border-color: var(--accent); background: var(--accent-soft); }
.invite.used, .invite.revoked, .invite.expired { opacity: .75; }
.invite-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.copy-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.copy-row input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; }
.copy-row form { margin: 0; }
.link-card { border-color: var(--accent); }

.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 18px; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }

/* ── Мягкое удаление и журнал изменений ─────────────── */
fieldset.contents { display: contents; border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.contents:disabled input, fieldset.contents:disabled textarea, fieldset.contents:disabled select { background: var(--surface-2); color: var(--muted); }
fieldset.contents:disabled .segment span { cursor: default; opacity: .7; }
.deleted-banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.deleted-banner form { margin: 0; }
.table tr.deleted td { color: var(--muted); background: color-mix(in srgb, var(--danger) 4%, transparent); }
.table tr.deleted td:not(:last-child) { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.history { max-width: 900px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); display: grid; gap: 16px; }
.timeline li { position: relative; }
.timeline li::before {
    content: ""; position: absolute; left: -24px; top: 6px; width: 10px; height: 10px; border-radius: 50%;
    background: var(--surface); border: 2px solid var(--accent);
}
.timeline-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 6px; }

.changes { border-collapse: collapse; font-size: .88rem; }
.changes th { text-align: left; font-weight: 500; color: var(--muted); padding: 2px 14px 2px 0; white-space: nowrap; vertical-align: top; }
.changes td { padding: 2px 6px 2px 0; vertical-align: top; overflow-wrap: anywhere; }
.changes .old { color: var(--danger); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.changes .new { color: var(--ok); }
.changes .arrow { color: var(--muted); }
.audit-table td { vertical-align: top; }
.audit-filters { padding: 18px 22px 8px; }

/* ── Справочники: отели, поставщики ─────────────────── */
div.contents { display: contents; }
.ac-name { display: flex; flex-direction: column; min-width: 0; }
.ac-name small { color: var(--muted); font-size: .8rem; }
.tag-other { color: var(--muted); }
.tabs { flex-wrap: wrap; }
