/* ===== Базовые переменные и темы ===== */
:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef1f7;
    --border: #e2e6ef;
    --text: #161c2b;
    --text-muted: #626c85;
    --accent: #3d6bff;
    --accent-contrast: #ffffff;
    --accent-soft: rgba(61, 107, 255, 0.1);
    --shadow: 0 1px 2px rgba(20, 28, 50, 0.05), 0 8px 24px rgba(20, 28, 50, 0.06);
    --shadow-hover: 0 2px 6px rgba(20, 28, 50, 0.08), 0 16px 32px rgba(20, 28, 50, 0.1);
    --radius: 16px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1320;
        --surface: #181d2e;
        --surface-2: #212739;
        --border: #2a3145;
        --text: #eef1f8;
        --text-muted: #99a2ba;
        --accent: #6d8dff;
        --accent-contrast: #0f1320;
        --accent-soft: rgba(109, 141, 255, 0.16);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
        --shadow-hover: 0 2px 6px rgba(0, 0, 0, 0.35), 0 16px 32px rgba(0, 0, 0, 0.4);
    }
}

/* Ручной выбор темы перекрывает системный */
:root[data-theme="light"] {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef1f7;
    --border: #e2e6ef;
    --text: #161c2b;
    --text-muted: #626c85;
    --accent: #3d6bff;
    --accent-contrast: #ffffff;
    --accent-soft: rgba(61, 107, 255, 0.1);
    --shadow: 0 1px 2px rgba(20, 28, 50, 0.05), 0 8px 24px rgba(20, 28, 50, 0.06);
    --shadow-hover: 0 2px 6px rgba(20, 28, 50, 0.08), 0 16px 32px rgba(20, 28, 50, 0.1);
}

:root[data-theme="dark"] {
    --bg: #0f1320;
    --surface: #181d2e;
    --surface-2: #212739;
    --border: #2a3145;
    --text: #eef1f8;
    --text-muted: #99a2ba;
    --accent: #6d8dff;
    --accent-contrast: #0f1320;
    --accent-soft: rgba(109, 141, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
    --shadow-hover: 0 2px 6px rgba(0, 0, 0, 0.35), 0 16px 32px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 20px;
}

main.container { flex: 1 0 auto; padding-bottom: 56px; }

a { color: var(--accent); }

/* ===== Шапка ===== */
.site-header {
    padding: 20px 0;
}

.site-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    font-weight: 650;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    color: var(--text);
    text-decoration: none;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 6px 12px 6px 8px;
    border-radius: 999px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.back-link:hover { background: var(--surface); color: var(--text); }
.back-link svg { width: 18px; height: 18px; }

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover { color: var(--text); border-color: var(--text-muted); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle__moon { display: none; }

:root[data-theme="dark"] .theme-toggle__sun { display: none; }
:root[data-theme="dark"] .theme-toggle__moon { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle__sun { display: none; }
    :root:not([data-theme="light"]) .theme-toggle__moon { display: block; }
}

/* ===== Главная ===== */
.hero {
    padding: 40px 0 32px;
    max-width: 560px;
}

.hero h1 {
    margin: 0 0 8px;
    font-size: clamp(1.9rem, 5vw, 2.6rem);
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.hero p {
    margin: 0;
    color: var(--text-muted);
    font-size: 1.05rem;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

a.tile:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: var(--accent);
}

a.tile:hover .tile__icon { background: var(--accent); color: var(--accent-contrast); }

.tile__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    margin-bottom: 10px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
    transition: background-color 0.18s ease, color 0.18s ease;
}

.tile__icon svg { width: 22px; height: 22px; }

.tile__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 620;
    font-size: 1.08rem;
    letter-spacing: -0.01em;
}

.tile__description {
    color: var(--text-muted);
    font-size: 0.93rem;
    line-height: 1.45;
}

.tile__badge {
    font-style: normal;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-muted);
}

.tile--soon { opacity: 0.62; cursor: default; box-shadow: none; }

/* ===== Заголовок страницы инструмента ===== */
.page-intro {
    padding: 24px 0 28px;
    text-align: center;
}

.page-intro h1 {
    margin: 0 0 6px;
    font-size: clamp(1.6rem, 4vw, 2.1rem);
    letter-spacing: -0.02em;
}

.page-intro p { margin: 0; color: var(--text-muted); }

/* ===== Калькулятор ===== */
.calc {
    max-width: 380px;
    margin: 0 auto;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.calc__display {
    padding: 18px 16px 14px;
    margin-bottom: 16px;
    background: var(--surface-2);
    border-radius: var(--radius);
    text-align: right;
    overflow: hidden;
}

.calc__history {
    min-height: 22px;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc__value {
    display: block;
    font-size: 2.6rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: font-size 0.12s ease;
}

.calc__value.is-long { font-size: 2rem; }
.calc__value.is-very-long { font-size: 1.5rem; }
.calc__value.is-error { color: #e5484d; font-size: 1.6rem; }

.calc__keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.key {
    height: 62px;
    border: none;
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 1.35rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.08s ease, filter 0.15s ease, background-color 0.15s ease;
}

.key svg { width: 22px; height: 22px; }

.key:hover { filter: brightness(0.96); }
:root[data-theme="dark"] .key:hover { filter: brightness(1.18); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .key:hover { filter: brightness(1.18); }
}

.key:active, .key.is-active { transform: scale(0.95); }

.key:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.key--fn { color: var(--text-muted); font-size: 1.2rem; }

.key--op {
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.5rem;
}

.key--op.is-selected {
    background: var(--accent);
    color: var(--accent-contrast);
}

.key--equals {
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 1.5rem;
}

.hint {
    max-width: 380px;
    margin: 20px auto 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.7;
}

kbd {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface);
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text);
}

@media (max-width: 420px) {
    .key { height: 56px; font-size: 1.25rem; }
    .calc { padding: 14px; }
}

/* ===== Панель инструмента (НДС и др.) ===== */
.panel {
    max-width: 520px;
    margin: 0 auto;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    margin-bottom: 20px;
    background: var(--surface-2);
    border-radius: 12px;
}

.segmented__item {
    padding: 10px 12px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 550;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented__item:hover { color: var(--text); }

.segmented__item.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.field {
    margin: 0 0 18px;
    padding: 0;
    border: none;
}

.field__label {
    display: block;
    margin-bottom: 8px;
    padding: 0;
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 550;
}

.field__input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 1.5rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field__input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    padding: 9px 16px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 550;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip:hover { border-color: var(--accent); }

.chip.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.chip--input {
    width: 110px;
    cursor: text;
    font-weight: 500;
}

.chip--input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.result {
    margin: 22px 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.result__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.result__row:last-child { border-bottom: none; }

.result__label { color: var(--text-muted); font-size: 0.92rem; }
.result__rate { font-style: normal; color: var(--text-muted); }

.result__value {
    font-size: 1.15rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.result__row--accent {
    background: var(--accent-soft);
}

.result__row--accent .result__label,
.result__row--accent .result__rate { color: var(--accent); }

.result__row--accent .result__value {
    color: var(--accent);
    font-size: 1.4rem;
}

.btn {
    width: 100%;
    padding: 13px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 0.98rem;
    font-weight: 550;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.is-done { border-color: var(--accent); color: var(--accent); }

/* ===== Статистика ===== */
.panel--wide {
    max-width: 860px;
    margin-bottom: 20px;
}

.panel__title {
    margin: 0 0 16px;
    font-size: 1.05rem;
    font-weight: 600;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    max-width: 860px;
    margin: 0 auto 20px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stat-card__label { color: var(--text-muted); font-size: 0.85rem; }

.stat-card__value {
    font-size: 1.9rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.stat-card__hint { color: var(--text-muted); font-size: 0.82rem; }

.chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 180px;
    padding-top: 8px;
    overflow-x: auto;
}

.chart__col {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    min-width: 14px;
    height: 100%;
}

.chart__bar {
    width: 100%;
    min-height: 2px;
    background: var(--accent);
    border-radius: 4px 4px 0 0;
    transition: height 0.25s ease;
}

.chart__col:hover .chart__bar { opacity: 0.75; }

.chart__tick {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.table th,
.table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 550;
}

.table td + td,
.table th + th { text-align: right; width: 120px; }

.table tr:last-child td { border-bottom: none; }

/* ===== Текстовые блоки (SEO-контент) ===== */
.prose {
    max-width: 680px;
    margin: 48px auto 0;
}

.prose h2 {
    margin: 36px 0 12px;
    font-size: 1.45rem;
    letter-spacing: -0.015em;
}

.prose h3 {
    margin: 26px 0 8px;
    font-size: 1.1rem;
}

.prose p, .prose li { color: var(--text-muted); }
.prose strong { color: var(--text); font-weight: 600; }
.prose ul { padding-left: 20px; }
.prose li { margin-bottom: 6px; }

.formula {
    padding: 12px 16px;
    margin: 10px 0;
    background: var(--surface-2);
    border-left: 3px solid var(--accent);
    border-radius: 0 10px 10px 0;
    color: var(--text) !important;
    font-variant-numeric: tabular-nums;
}

.note {
    padding: 14px 16px;
    margin-top: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.92rem;
}

.faq { margin-top: 14px; }

.faq__item {
    padding: 14px 16px;
    margin-bottom: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.faq__item summary {
    cursor: pointer;
    font-weight: 550;
    list-style: none;
}

.faq__item summary::-webkit-details-marker { display: none; }

.faq__item summary::after {
    content: '+';
    float: right;
    color: var(--text-muted);
    font-weight: 400;
}

.faq__item[open] summary::after { content: '−'; }
.faq__item p { margin: 10px 0 0; }

/* ===== Подвал ===== */
.site-footer {
    flex-shrink: 0;
    padding: 24px 0 32px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.site-footer p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
    * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
