/* ============================================================
   Калькуляция Nonwoven пакетов — стили
   Порядок: токены → база → шапка → сетка → карточки → формы → кнопки →
   таблицы → уведомления → калькулятор → история → админка → КП →
   тёмная тема → печать → адаптив
   ============================================================ */

:root {
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --dark: #1f3864;          /* фирменный тёмно-синий: шапка приложения, заголовки карточек */
    --blue: #2f5fd0;          /* основные действия */
    --blue-hover: #244cad;
    --light: #e8eef9;         /* подложки итоговых строк и подзаголовков */
    --line: #e1e6ef;
    --grey: #667085;
    --text: #1c2433;
    --green: #178a4c;         /* «Сформировать КП» */
    --green-hover: #126f3d;
    --red: #c0392b;
    --red-hover: #a12b2b;
    --yellow: #fff4cc;
    --yellow-text: #7a5a00;
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafd;
    --focus: rgba(47, 95, 208, .28);
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
    --radius: 10px;
    --radius-sm: 8px;
    --control-h: 38px;
}

/* ---------- база ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--blue); }
code {
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 5px;
}
p { margin: 0 0 8px; }

/* ---------- шапка приложения ---------- */
header.topbar {
    background: var(--dark);
    color: #fff;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    box-shadow: 0 2px 10px rgba(16, 24, 40, .22);
}
header.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: .2px; }
header.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
header.topbar nav a {
    color: #cdd8ee;
    text-decoration: none;
    font-size: 13px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
}
header.topbar nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
header.topbar nav a.active { color: #fff; background: rgba(255, 255, 255, .14); font-weight: 600; }
.theme-toggle {
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .18);
    color: #fff;
    border-radius: 999px;
    width: 36px;
    height: 36px;
    padding: 0;
    margin-left: 8px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .22); }

/* ---------- сетка ---------- */
.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 20px 40px; }
.layout { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.col-form { flex: 0 0 360px; }
.col-result { flex: 1 1 560px; min-width: 320px; }

/* ---------- карточки ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 18px;
    overflow-x: auto;
    box-shadow: var(--shadow);
}
.card > h2 {
    background: var(--dark);
    color: #fff;
    font-size: 13px;
    margin: 0;
    padding: 10px 16px;
    font-weight: 600;
    letter-spacing: .2px;
}
.card > h3 {
    background: var(--light);
    color: var(--dark);
    font-size: 12.5px;
    margin: 0;
    padding: 8px 16px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    font-weight: 600;
}
.card .body { padding: 16px; }
/* свёрнутые блоки результата: <summary> выглядит как заголовок карточки */
.card > summary {
    background: var(--dark);
    color: #fff;
    font-size: 13px;
    margin: 0;
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::before { content: '▸'; display: inline-block; width: 16px; opacity: .8; }
.card[open] > summary::before { content: '▾'; }
.card > summary:hover { background: #274579; }

/* ---------- формы ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span, .field > span {
    display: block;
    font-size: 12px;
    color: var(--grey);
    margin-bottom: 4px;
    font-weight: 500;
}
label.field small, .field small {
    display: block;
    color: var(--grey);
    font-size: 11.5px;
    margin-top: 4px;
}
.inline-note { display: inline; font-weight: 400; }
.req { color: var(--red); font-weight: 700; margin-left: 2px; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=file], select {
    width: 100%;
    height: var(--control-h);
    padding: 0 10px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    font: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s, background .15s;
}
input[type=file] { height: auto; padding: 7px 10px; }
input::placeholder { color: #9aa3b2; }
input:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--focus); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 8px; cursor: pointer; }
.check input { width: auto; height: auto; }
.field-error { display: block; color: var(--red); font-size: 11.5px; margin-top: 4px; }
.field-warn { display: block; color: var(--yellow-text); font-size: 11.5px; margin-top: 4px; }
/* режимы полей: неактивное — серое и не редактируется; обязательное — красное, пока пусто */
input.field-inactive, select.field-inactive {
    background: #eef1f6;
    color: #7b8494;
    border-style: dashed;
    cursor: not-allowed;
}
input.field-missing, select.field-missing { border-color: var(--red); background: #fdf1f0; }
input.field-missing:focus, select.field-missing:focus { box-shadow: 0 0 0 3px rgba(192, 57, 43, .22); }
.missing-list { margin: 6px 0 0 18px; padding: 0; color: var(--red); }
.missing-list li { margin: 2px 0; }
.warn-text { color: var(--yellow-text); }

/* ---------- кнопки ---------- */
button, .btn {
    background: var(--blue);
    color: #fff;
    border: 0;
    border-radius: var(--radius-sm);
    height: var(--control-h);
    padding: 0 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    transition: background .15s, box-shadow .15s, transform .05s;
}
button:hover, .btn:hover { background: var(--blue-hover); }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.btn-primary { background: var(--blue); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid #cbd5e1; font-weight: 500; }
.btn-secondary:hover { background: var(--surface-2); border-color: #a9b4c4; }
.btn-danger { background: var(--surface); color: var(--red); border: 1px solid #e5b4b4; font-weight: 500; }
.btn-danger:hover { background: #fdf1f0; border-color: var(--red); }
.btn-cta { background: var(--green); }
.btn-cta:hover { background: var(--green-hover); }
button[disabled], .btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-cta[disabled]:hover { background: var(--green); }

/* ---------- таблицы ---------- */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
th, td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
thead th {
    background: var(--surface-2);
    color: var(--grey);
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
    border-bottom: 1px solid #d5dbe6;
}
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.center { text-align: center; }
td.strong { font-weight: 700; color: var(--dark); }
tr.section td { background: var(--dark); color: #fff; font-weight: 600; font-size: 12px; }
tr.total td { background: var(--light); font-weight: 700; color: var(--dark); }
tr.sub td { color: var(--grey); background: var(--surface-2); font-size: 12.5px; }
tr.muted td { color: #9aa0a8; }
td .formula { display: block; color: var(--grey); font-size: 11.5px; margin-top: 2px; }
table.compare td { font-size: 14px; padding: 10px 12px; }
.empty-state { text-align: center; color: var(--grey); padding: 26px 16px !important; font-size: 13px; }

/* ---------- уведомления ---------- */
.alert {
    position: relative;
    padding: 11px 14px 11px 40px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid;
    transition: opacity .45s;
}
.alert::before { position: absolute; left: 14px; top: 10px; font-weight: 700; font-size: 14px; }
.alert-ok { background: #e6f6ec; border-color: #a9d9ba; color: #145a2e; }
.alert-ok::before { content: '✓'; }
.alert-err { background: #fdecea; border-color: #e5b4b4; color: #8a2222; }
.alert-err::before { content: '✕'; }
.alert-warn { background: var(--yellow); border-color: #e2d18a; color: var(--yellow-text); }
.alert-warn::before { content: '!'; }
.alert-hide { opacity: 0; }
.alert div + div { margin-top: 4px; }

/* ---------- калькулятор ---------- */
.qty-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.qty-row input { flex: 1; }
.btn-remove-qty {
    flex: 0 0 auto;
    background: var(--surface);
    color: var(--red);
    border: 1px solid #e5b4b4;
    border-radius: 999px;
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 16px;
    line-height: 1;
}
.btn-remove-qty:hover { background: #fdf1f0; border-color: var(--red); }
.btn-add-qty { height: 30px; padding: 0 10px; font-size: 12px; margin-top: 2px; }
.form-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 -4px 18px rgba(16, 24, 40, .1);
    padding: 12px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.form-hint { flex-basis: 100%; font-size: 12px; color: var(--red); }
.notes { padding: 12px 16px; font-size: 12px; color: var(--grey); }
.notes p { margin: 0 0 6px; }
.notes p:last-child { margin-bottom: 0; }
/* сводные плитки (legacy) */
.summary { display: flex; gap: 12px; flex-wrap: wrap; padding: 16px; }
.summary .box { flex: 1 1 150px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); }
.summary .box .lbl { font-size: 11px; color: var(--grey); text-transform: uppercase; letter-spacing: .3px; }
.summary .box .val { font-size: 19px; font-weight: 700; color: var(--dark); margin-top: 4px; }
.summary .box.accent { background: var(--light); }

/* ---------- история КП ---------- */
.quotes-filter { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.quotes-filter .field { margin-bottom: 0; }
.quotes-filter .field:first-child { flex: 1 1 220px; }
.quotes-filter-actions { display: flex; gap: 8px; }
.quotes-actions { white-space: nowrap; }
.quotes-actions .btn, .quotes-actions button { height: 30px; padding: 0 10px; font-size: 12px; margin-right: 4px; }

/* ---------- админка ---------- */
.login { max-width: 380px; margin: 60px auto; }
.admin-table td { vertical-align: middle; }
.admin-table input[type=number], .admin-table input[type=text] { min-width: 90px; }
.admin-note { color: var(--grey); font-size: 11.5px; }
.sticky-save {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0 -4px 18px rgba(16, 24, 40, .08);
}
.logo-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-top: 4px; }
.logo-preview {
    width: 180px;
    height: 100px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 8px;
}
.logo-empty { display: flex; align-items: center; justify-content: center; color: var(--grey); font-size: 12px; background: var(--surface-2); }
.logo-controls { flex: 1 1 260px; }
footer.foot { text-align: center; color: var(--grey); font-size: 12px; padding: 10px 0 30px; }

/* ---------- документ КП (kp.php) ---------- */
body.kp-doc { background: #fff; color: #1c2433; max-width: 780px; margin: 0 auto; padding: 32px 24px; }
.kp-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 24px; }
.kp-head {
    display: flex;
    align-items: center;
    gap: 22px;
    border-bottom: 2px solid var(--dark);
    padding-bottom: 16px;
    margin-bottom: 22px;
}
.kp-logo { max-height: 84px; max-width: 220px; object-fit: contain; flex: 0 0 auto; }
.kp-title h1 { margin: 0 0 4px; font-size: 22px; color: var(--dark); letter-spacing: .2px; }
.kp-sub { font-size: 15px; color: #1c2433; }
.kp-meta { font-size: 13px; color: var(--grey); margin-top: 4px; }
body.kp-doc h3 { color: var(--dark); font-size: 13px; margin: 22px 0 8px; text-transform: uppercase; letter-spacing: .4px; }
body.kp-doc table { font-size: 13.5px; }
body.kp-doc th, body.kp-doc td { border-bottom: 1px solid #d9dfe8; padding: 8px 10px; }
body.kp-doc thead th { background: #eef2f9; color: var(--dark); }
body.kp-doc tbody tr:hover td { background: transparent; }
.kp-foot { color: var(--grey); font-size: 12px; margin-top: 24px; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- тёмная тема: data-theme="dark" на <html>, выбор хранится в localStorage ---------- */
:root[data-theme="dark"] {
    --dark: #101b33;
    --blue: #5b8fd9;
    --blue-hover: #7ba4e6;
    --light: #223050;
    --line: #2c3a55;
    --grey: #9aa4b8;
    --text: #e7ebf3;
    --green: #2ea364;
    --green-hover: #3fbf75;
    --red: #e06666;
    --red-hover: #f08080;
    --yellow: #3a3214;
    --yellow-text: #f1dc8a;
    --bg: #0f1523;
    --surface: #1a2338;
    --surface-2: #202b44;
    --focus: rgba(91, 143, 217, .35);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
:root[data-theme="dark"] body { color: var(--text); }
:root[data-theme="dark"] input[type=text],
:root[data-theme="dark"] input[type=number],
:root[data-theme="dark"] input[type=password],
:root[data-theme="dark"] input[type=date],
:root[data-theme="dark"] input[type=file],
:root[data-theme="dark"] select { border-color: #33415e; color-scheme: dark; }
:root[data-theme="dark"] input::placeholder { color: #6f7889; }
:root[data-theme="dark"] .btn-secondary { border-color: #3a4a6a; }
:root[data-theme="dark"] .btn-secondary:hover { border-color: #52658a; }
:root[data-theme="dark"] .btn-danger { border-color: #7a3a3a; }
:root[data-theme="dark"] .btn-danger:hover { background: #3a1414; }
:root[data-theme="dark"] .btn-remove-qty { border-color: #7a3a3a; }
:root[data-theme="dark"] .btn-remove-qty:hover { background: #3a1414; }
:root[data-theme="dark"] .card > h3,
:root[data-theme="dark"] tr.total td,
:root[data-theme="dark"] td.strong,
:root[data-theme="dark"] .summary .box .val { color: var(--text); }
:root[data-theme="dark"] .card > summary:hover { background: #182747; }
:root[data-theme="dark"] thead th { border-bottom-color: #33415e; }
:root[data-theme="dark"] tr.muted td { color: #6f7889; }
:root[data-theme="dark"] input.field-inactive,
:root[data-theme="dark"] select.field-inactive { background: #232c40; color: #8a93a6; }
:root[data-theme="dark"] input.field-missing,
:root[data-theme="dark"] select.field-missing { background: #3a1414; border-color: #e06666; }
:root[data-theme="dark"] .alert-ok { background: #123321; border-color: #1c5c31; color: #8fe3ac; }
:root[data-theme="dark"] .alert-err { background: #3a1414; border-color: #8a2222; color: #f0a3a3; }
:root[data-theme="dark"] .alert-warn { background: #3a3214; border-color: #6b5a12; color: #f1dc8a; }
:root[data-theme="dark"] .logo-preview { background: #fff; }
:root[data-theme="dark"] .logo-empty { background: var(--surface-2); }
:root[data-theme="dark"] code { background: var(--surface-2); border-color: var(--line); }

/* ---------- печать ---------- */
@media print {
    header.topbar, .col-form, .sticky-save, .no-print, .form-actions, .theme-toggle { display: none !important; }
    body { background: #fff; color: #000; }
    .card { border-color: #999; box-shadow: none; break-inside: avoid; }
    .card > summary { color: #000; background: #eee; }
    body.kp-doc { padding: 0; max-width: none; }
    .kp-head { border-bottom-color: #000; }
    tbody tr:hover td { background: transparent; }
}

/* ---------- адаптив ---------- */
@media (max-width: 760px) {
    .wrap { padding: 14px 12px 30px; }
    header.topbar { padding: 10px 14px; }
    .col-form { flex-basis: 100%; }
    .col-result { min-width: 0; flex-basis: 100%; }
    .grid2 { grid-template-columns: 1fr; }
    .form-actions { position: static; box-shadow: var(--shadow); }
    .quotes-actions { white-space: normal; }
    .quotes-actions .btn, .quotes-actions button { margin-bottom: 4px; }
}

/* ---------- платформа: шапка с пользователем, вход ---------- */
header.topbar h1 a.brand { color: #fff; text-decoration: none; }
.nav-user { color: #cdd8ee; font-size: 13px; padding: 7px 4px 7px 12px; border-left: 1px solid rgba(255, 255, 255, .18); margin-left: 6px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--grey); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }
.pager { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 12px 16px; font-size: 13px; color: var(--grey); }
.pager a { padding: 4px 9px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; color: var(--text); }
.pager a.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; background: var(--surface-2); color: var(--grey); border: 1px solid var(--line); }
.badge-admin { background: var(--light); color: var(--dark); }
.badge-off { background: #fdecea; color: #8a2222; border-color: #e5b4b4; }
.kv { font-size: 12px; color: var(--grey); }
:root[data-theme="dark"] .badge-off { background: #3a1414; color: #f0a3a3; border-color: #8a2222; }

/* ---------- КП: доп. строки ---------- */
.kp-extra { font-size: 13px; margin-top: 12px; color: #1c2433; }
.kp-terms { font-size: 13px; margin-top: 14px; padding: 10px 12px; background: #f6f8fb; border-left: 3px solid var(--dark); }
.user-row-edit summary { cursor: pointer; color: var(--blue); font-size: 12.5px; }
.user-row-edit .body { padding: 10px 0 0; }
.log-details { font-size: 12px; color: var(--grey); word-break: break-word; max-width: 420px; }
