/* ---------- Токены темы ---------- */
:root {
    color-scheme: light;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #14171c;
    --muted: #5a6472;
    --border: #e1e5ea;
    --accent: #0a62d0;
    --accent-hover: #0852b0;
    --on-accent: #ffffff;
    --digit: #0a62d0;
    --symbol: #c2410c;
    --weak: #d92d20;
    --medium: #b54708;
    --strong: #087443;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 5%);
    --radius: 16px;
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0e1116;
        --surface: #171b22;
        --surface-2: #20252e;
        --text: #e8ebf0;
        --muted: #9aa4b2;
        --border: #2a303a;
        --accent: #4c9aff;
        --accent-hover: #6aaeff;
        --on-accent: #08111f;
        --digit: #6aaeff;
        --symbol: #fb923c;
        --weak: #f97066;
        --medium: #fdb022;
        --strong: #32d583;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 25%);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #20252e;
    --text: #e8ebf0;
    --muted: #9aa4b2;
    --border: #2a303a;
    --accent: #4c9aff;
    --accent-hover: #6aaeff;
    --on-accent: #08111f;
    --digit: #6aaeff;
    --symbol: #fb923c;
    --weak: #f97066;
    --medium: #fdb022;
    --strong: #32d583;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 25%);
}

/* ---------- База ---------- */
*, *::before, *::after { 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, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.muted { color: var(--muted); }

.icon { flex: none; display: block; }

/* ---------- Страница ---------- */
.page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.container {
    width: 100%;
    max-width: 1040px;
    margin-inline: auto;
    padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}

.main { flex: 1; padding-block: 8px 24px; }

/* ---------- Шапка ---------- */
.header { padding-block: 12px; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 0; }
.brand:hover { color: var(--text); }
.brand-logo { color: var(--accent); flex: none; }
.brand h1 { font-size: 1.2rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand h1 span { display: none; font-weight: 400; color: var(--muted); margin-left: 6px; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px;
    border: 1px solid transparent; border-radius: 12px;
    font-weight: 600; line-height: 1;
    transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-lg { width: 100%; min-height: 52px; font-size: 1.05rem; }

.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .875rem; font-weight: 500; border-radius: 10px; }

.icon-btn {
    display: inline-grid; place-items: center; flex: none;
    width: 44px; height: 44px; padding: 0;
    background: transparent; border: 1px solid transparent; border-radius: 12px;
    color: var(--muted);
    transition: background-color .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.theme-toggle { min-height: 40px; padding: 0 12px; }
.theme-toggle-label { display: none; font-weight: 500; font-size: .9rem; }

/* ---------- Карточки и сетка ---------- */
.layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 16px;
}

.card-title { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; }

.result { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Пароль ---------- */
.password-box {
    display: flex; align-items: flex-start; gap: 4px;
    padding: 6px 6px 6px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    min-height: 76px;
}

.password {
    flex: 1; min-width: 0; align-self: center;
    padding: 6px 0; text-align: left;
    background: none; border: 0; border-radius: 8px;
    font-family: var(--mono);
    font-size: clamp(1.2rem, 1rem + 1.6vw, 1.7rem);
    line-height: 1.35;
    letter-spacing: .02em;
    word-break: break-all;
    user-select: all;
    -webkit-user-select: all;
}

.password-error { flex: 1; align-self: center; padding: 6px 0; color: var(--weak); font-weight: 500; }

.password-actions { display: flex; flex-direction: column; gap: 2px; flex: none; }

.pw-digit { color: var(--digit); }
.pw-symbol { color: var(--symbol); }
.pw-hidden { color: var(--muted); }

/* ---------- Стойкость ---------- */
.strength { --level-color: var(--muted); display: grid; gap: 8px; }
.strength[data-level="weak"] { --level-color: var(--weak); }
.strength[data-level="medium"] { --level-color: var(--medium); }
.strength[data-level="strong"] { --level-color: var(--strong); }

.meter { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--level-color); transition: width .25s ease, background-color .25s; }

.strength-text { font-size: .9rem; }
.strength-text strong { color: var(--level-color); }

/* ---------- Длина ---------- */
.length { display: grid; gap: 4px; }
.length-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 500; }
.length-value { font-family: var(--mono); font-size: 1.4rem; font-weight: 600; color: var(--accent); }
.length-control { display: flex; align-items: center; gap: 4px; }

input[type="range"] {
    flex: 1; min-width: 0; height: 44px; margin: 0;
    background: transparent; cursor: pointer;
    -webkit-appearance: none; appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 6px; border-radius: 99px;
    background: linear-gradient(to right, var(--accent) var(--fill), var(--surface-2) var(--fill));
    border: 1px solid var(--border);
}
input[type="range"]::-moz-range-track {
    height: 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border);
}
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 24px; height: 24px; margin-top: -10px;
    border-radius: 50%; background: var(--surface); border: 3px solid var(--accent);
    box-shadow: 0 1px 4px rgb(0 0 0 / 25%);
}
input[type="range"]::-moz-range-thumb {
    width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent);
    box-shadow: 0 1px 4px rgb(0 0 0 / 25%);
}

/* ---------- Настройки ---------- */
.settings { display: flex; flex-direction: column; gap: 4px; }
.extra-title { margin-top: 16px; }

.options { display: grid; grid-template-columns: minmax(0, 1fr); }

.option {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    min-height: 56px; padding: 8px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.options > .option:last-child { border-bottom: 0; }

.option-text { display: grid; min-width: 0; }
.option-title { font-weight: 500; }
.option-hint { font-size: .85rem; color: var(--muted); }

.switch {
    -webkit-appearance: none; appearance: none; flex: none;
    position: relative; width: 46px; height: 28px; margin: 0;
    border-radius: 99px; background: var(--border);
    cursor: pointer; transition: background-color .2s;
}
.switch::after {
    content: ""; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
    transition: transform .2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

/* ---------- История ---------- */
.history { display: flex; flex-direction: column; gap: 8px; }
.empty { font-size: .9rem; }

.history-list { list-style: none; margin: 0; padding: 0; display: grid; }
.history-list li {
    display: flex; align-items: center; gap: 8px;
    padding: 2px 0 2px 2px; border-bottom: 1px solid var(--border);
}
.history-list li:last-child { border-bottom: 0; }
.history-pw {
    flex: 1; min-width: 0; font-family: var(--mono); font-size: .95rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Подвал ---------- */
.footer { display: grid; gap: 8px; padding-block: 8px calc(24px + env(safe-area-inset-bottom)); font-size: .875rem; color: var(--muted); }
.privacy { display: flex; gap: 8px; align-items: flex-start; }
.privacy .icon { margin-top: 2px; color: var(--strong); }
.footer-links { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; }
.footer-links a { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Уведомление ---------- */
.toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 32px);
    padding: 12px 18px; border-radius: 12px;
    background: var(--text); color: var(--bg);
    font-size: .95rem; font-weight: 500; text-align: center;
    box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
    transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .2s;
}
.toast[data-visible="true"] { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Загрузка и ошибки Blazor ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-spinner {
    width: 36px; height: 36px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.noscript { padding: 24px; text-align: center; }

#blazor-error-ui {
    display: none; position: fixed; inset: auto 0 0 0; z-index: 1000;
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
    background: #fff4cc; color: #3b2f00; box-shadow: 0 -1px 6px rgb(0 0 0 / 25%);
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 12px; }

/* ---------- Планшет: от 600px ---------- */
@media (min-width: 600px) {
    .container { padding-inline: max(24px, env(safe-area-inset-left)) max(24px, env(safe-area-inset-right)); }
    .header { padding-block: 16px; }
    .brand h1 span { display: inline; }
    .theme-toggle-label { display: inline; }
    .card { padding: 24px; }
    .layout { gap: 20px; }
    .layout > .card { width: 100%; max-width: 720px; margin-inline: auto; }
    .options { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 32px; }
    .options > .option:nth-last-child(2) { border-bottom: 0; }
    .toast { bottom: 32px; }
}

/* ---------- Десктоп: от 960px ---------- */
@media (min-width: 960px) {
    .container { padding-inline: 32px; }
    .main { padding-block: 16px 40px; }

    .layout {
        grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
        grid-template-areas:
            "result settings"
            "history settings";
        align-items: start;
        gap: 24px;
    }
    .layout > .card { max-width: none; margin: 0; }
    .result { grid-area: result; padding: 28px; }
    .settings { grid-area: settings; padding: 28px; }
    .history { grid-area: history; }

    .options { grid-template-columns: minmax(0, 1fr); }
    .options > .option:nth-last-child(2) { border-bottom: 1px solid var(--border); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; }
}
