/*
 * «Настройки» — design_handoff_settings (set-sheet.jsx is the layout's source
 * of truth). Colours come from the IA tokens in ia.css; §6 of the handoff
 * added the ones this page needed next to them.
 *
 * `--ia-primary` is the prototype's `brand` in BOTH themes (#2489c5 light,
 * #63b4e4 dark), where `--ia-brand` stays #2489c5 in dark as well — so the
 * switch, the tab underline and the holiday cells use `--ia-primary`.
 *
 * NARROW IS A CONTAINER WIDTH, not a viewport width: the sidebar decides how
 * much of a 1024px screen the page actually gets, and the rows only care
 * about that. Same approach as tasks.css.
 */

div.ia-settings {
    --st-hover: #f6f8fb;
    --st-on-danger: #ffffff;
    gap: 0;
    container: st / inline-size;
}

.dark div.ia-settings {
    --st-hover: rgba(255, 255, 255, 0.04);
    --st-on-danger: #1a0d0e;
}

.ia-settings :is(button, input, select, a):focus-visible {
    outline: 2px solid var(--ia-primary);
    outline-offset: 2px;
}

.ia-settings a { color: var(--ia-brand-ink); }

@keyframes st-in {
    from { opacity: 0; transform: translateY(2px); }
    to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------------ header */

.st-h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
    color: var(--ia-ink);
}

.st-sub {
    margin: 6px 0 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ia-ink-soft);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
}

.st-attn {
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    color: var(--ia-danger);
}

/* -------------------------------------------------------------------- tabs */

/* overflow-y hidden: the underline's -1px overlap must never grow a vertical
   scrollbar on the bar (§2). */
.st-tabs {
    display: flex;
    gap: 4px;
    margin-top: 24px;
    border-bottom: 1px solid var(--ia-line);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

.st-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 46px;
    padding: 0 14px;
    margin-bottom: -1px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: var(--ia-ink-soft);
    white-space: nowrap;
    flex: none;
}

.st-tab:hover { color: var(--ia-ink); }

.st-tab.is-on {
    font-weight: 600;
    color: var(--ia-brand-ink);
    border-bottom-color: var(--ia-primary);
}

.st-tab__n {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    box-sizing: border-box;
    border-radius: 9px;
    background: var(--ia-danger);
    color: var(--st-on-danger);
    font-size: 11px;
    font-weight: 700;
    display: grid;
    place-items: center;
}

/* ---------------------------------------------------------------- sections */

.st-body {
    max-width: 880px;
    margin-top: 28px;
    display: flex;
    flex-direction: column;
    gap: 36px;
}

.st-sec {
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-margin-top: 80px;
}

.st-sec__head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.st-sec__titles { flex: 1 1 320px; min-width: 0; }

.st-sec__title {
    margin: 0;
    font-size: 17px;
    font-weight: 650;
    color: var(--ia-ink);
}

.st-sec__lead {
    margin: 3px 0 0;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--ia-ink-soft);
    text-wrap: pretty;
}

.st-sec__right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Exactly one card per section; never nested. */
.st-card {
    background: var(--ia-surface);
    border: 1px solid var(--ia-line);
    border-radius: 12px;
    overflow: hidden;
}

.st-row + .st-row { border-top: 1px solid var(--ia-line-2); }

/* ------------------------------------------------------------- setting row */

.st-set {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 24px;
    padding: 14px 16px;
}

.st-set--stack { grid-template-columns: minmax(0, 1fr); gap: 10px; }
.st-set__text { min-width: 0; }

.st-set__label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--ia-ink);
}

.st-set__help {
    margin-top: 3px;
    max-width: 560px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--ia-ink-soft);
    text-wrap: pretty;
}

.st-set__ctl {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.st-set--stack .st-set__ctl { justify-content: flex-start; }

.st-err {
    flex-basis: 100%;
    margin: 0;
    font-size: 13px;
    line-height: 1.4;
    color: var(--ia-danger);
    text-align: right;
}

.st-set--stack .st-err,
.st-add-row .st-err,
.st-acc__text .st-err,
.st-ntf__text .st-err { text-align: left; }

.st-add-row .st-err { margin-top: 6px; }

/* A strip is a table header inside a card. */
.st-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ia-ink-soft);
    background: var(--ia-surface-2);
}

.st-strip__grow,
.st-grow { flex: 1; }

/* ------------------------------------------------------------- problem row */

.st-warn {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 16px;
    background: var(--ia-danger-wash);
    font-size: 13px;
    line-height: 1.45;
    color: var(--ia-ink-2);
}

.st-card .st-warn,
.st-card .st-row + .st-warn { border-top: 1px solid var(--ia-danger-line); }

.st-warn__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ia-danger);
    flex: none;
}

.st-warn__text { flex: 1 1 280px; min-width: 0; }
.st-warn__text b { font-weight: 650; color: var(--ia-ink); }
.st-warn__acts { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ switch */

.st-sw {
    position: relative;
    width: 40px;
    height: 24px;
    flex: none;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--ia-input-line);
    cursor: pointer;
    transition: background 0.15s;
}

.st-sw::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: left 0.15s;
}

.st-sw[aria-checked='true'] { background: var(--ia-primary); }
.st-sw[aria-checked='true']::after { left: 19px; }
.st-sw:disabled { opacity: 0.45; cursor: default; }

/* A disabled control swallows the pointer, so its sentence lives on the
   wrapper and the control lets the pointer through to it. */
.st-dis { display: inline-flex; align-items: center; cursor: help; }
.st-dis :disabled { pointer-events: none; }

/* ----------------------------------------------------------------- stepper */

.st-step { display: inline-flex; align-items: center; gap: 8px; flex: none; }

.st-step__box {
    display: inline-flex;
    align-items: center;
    height: 32px;
    box-sizing: border-box;
    border: 1px solid var(--ia-input-line);
    border-radius: 8px;
    background: var(--ia-surface);
}

.st-step__btn {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ia-ink-2);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.st-step__btn:disabled { color: var(--ia-faint); cursor: default; }

.st-step__v {
    min-width: 28px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--ia-ink);
    font-variant-numeric: tabular-nums;
}

.st-step__suf { font-size: 13px; color: var(--ia-ink-soft); }
.st-step.st-dis .st-step__v { color: var(--ia-faint); }

/* --------------------------------------------------------------- segmented */

.st-seg {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 3px;
    border-radius: 9px;
    background: var(--ia-surface-2);
    border: 1px solid var(--ia-line);
}

.st-seg__opt {
    height: 30px;
    padding: 0 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    color: var(--ia-ink-soft);
    white-space: nowrap;
    cursor: pointer;
}

.st-seg__opt.is-on {
    background: var(--ia-surface);
    color: var(--ia-ink);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    cursor: default;
}

.st-seg__opt:disabled { color: var(--ia-faint); cursor: default; }

/* ------------------------------------------------------------------ select */

.st-sel { position: relative; display: inline-flex; width: 220px; max-width: 100%; flex: none; }

.st-sel select {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    height: 36px;
    padding: 0 30px 0 10px;
    border-radius: 8px;
    border: 1px solid var(--ia-input-line);
    background: var(--ia-surface);
    color: var(--ia-ink);
    font-size: 14px;
    cursor: pointer;
}

.st-sel select:disabled { color: var(--ia-faint); cursor: default; }

.st-sel__chev {
    position: absolute;
    right: 11px;
    top: 12px;
    color: var(--ia-ink-soft);
    pointer-events: none;
}

/* ------------------------------------------------------------ range, input */

.st-range { display: inline-flex; align-items: center; gap: 12px; }
.st-range input { width: 180px; accent-color: var(--ia-primary); cursor: pointer; }
.st-range input:disabled { cursor: default; opacity: 0.55; }

.st-range__v {
    min-width: 44px;
    text-align: right;
    font-size: 14px;
    font-weight: 600;
    color: var(--ia-ink);
    font-variant-numeric: tabular-nums;
}

.st-input {
    width: 280px;
    max-width: 100%;
    height: 36px;
    box-sizing: border-box;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid var(--ia-input-line);
    background: var(--ia-surface);
    color: var(--ia-ink);
    font-size: 14px;
}

.st-input:focus { border-color: var(--ia-primary); }

/* ----------------------------------------------------------------- buttons */

/* Primary is #1a6d9e with white text: white on #2489c5 is only 3.9:1,
   too low for 14px text (§3). */
.st-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    flex: none;
    box-sizing: border-box;
}

.st-btn--sm { height: 30px; padding: 0 10px; font-size: 13px; }

.ia-settings .st-btn--primary {
    background: var(--ia-brand-btn);
    border-color: var(--ia-brand-btn);
    color: var(--ia-on-brand-btn);
}

.st-btn--primary:hover { opacity: 0.9; }

.ia-settings .st-btn--ghost {
    background: var(--ia-surface);
    border-color: var(--ia-input-line);
    color: var(--ia-ink-2);
}

.st-btn--ghost:hover { background: var(--st-hover); }

.ia-settings .st-btn--quiet {
    background: transparent;
    border-color: transparent;
    color: var(--ia-brand-ink);
}

.st-btn--quiet:hover { background: var(--ia-brand-wash); }
.st-btn:disabled { opacity: 0.6; cursor: default; }

/* ------------------------------------------------------------ small pieces */

.st-saved {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--ia-ok);
    white-space: nowrap;
    animation: st-in 0.18s ease-out;
}

.st-saved__undo {
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ia-brand-ink);
}

.st-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 11px;
    border-radius: 999px;
    border: 1px solid var(--ia-line);
    background: var(--ia-surface);
    color: var(--ia-ink-2);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
}

.st-chip:hover { background: var(--st-hover); }

.st-chip[aria-pressed='true'] {
    background: var(--ia-brand-wash);
    border-color: var(--ia-brand-line);
    color: var(--ia-brand-ink);
}

.st-lock {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--ia-surface-2);
    border: 1px solid var(--ia-line);
    font-size: 12.5px;
    color: var(--ia-ink-soft);
    white-space: nowrap;
}

.st-tag {
    height: 22px;
    padding: 0 8px;
    border-radius: 6px;
    border: 0;
    background: var(--ia-brand-wash);
    color: var(--ia-brand-ink);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    flex: none;
}

.st-foot {
    padding: 11px 16px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--ia-ink-soft);
}

.st-empty {
    padding: 28px 16px;
    text-align: center;
    font-size: 14px;
    color: var(--ia-ink-soft);
}

/* --------------------------------------------------------- lists, quick-add */

.st-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }

.st-item__name {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    color: var(--ia-ink);
    overflow-wrap: anywhere;
}

.st-item__name.is-empty { color: var(--ia-ink-soft); }

.st-item__n {
    min-width: 64px;
    text-align: right;
    font-size: 13px;
    color: var(--ia-ink-soft);
    font-variant-numeric: tabular-nums;
}

.st-add-row { padding: 12px 16px; }

.st-add {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px;
    padding: 0 12px;
    box-sizing: border-box;
    border-radius: 8px;
    border: 1px dashed var(--ia-input-line);
    cursor: text;
}

.st-add:focus-within { border-color: var(--ia-primary); }
.st-add__plus { color: var(--ia-ink-soft); font-size: 18px; line-height: 1; }

.st-add input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--ia-ink);
    font-size: 14px;
    padding: 0;
}

.st-add input:focus-visible { outline: none; }

/* ------------------------------------------------------------ access table */

.st-acc {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 120px 140px;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
}

.st-acc--head {
    padding: 9px 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ia-ink-soft);
    background: var(--ia-surface-2);
}

.st-c { display: flex; justify-content: center; text-align: center; }
.st-acc__text { min-width: 0; }
.st-acc__label { font-size: 14px; font-weight: 500; color: var(--ia-ink); }

.st-acc__desc {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 2px;
    font-size: 13px;
    color: var(--ia-ink-soft);
}

/* ----------------------------------------------------------- notifications */

.st-ntf {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 170px 60px 60px 60px;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
}

.st-ntf--head {
    padding: 9px 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ia-ink-soft);
    background: var(--ia-surface-2);
}

.st-ntf__text { min-width: 0; }
.st-ntf__label { font-size: 14px; font-weight: 500; color: var(--ia-ink); }

.st-ntf__timing {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
    font-size: 13px;
    color: var(--ia-ink-soft);
}

.st-who { font-size: 13px; line-height: 1.4; color: var(--ia-ink-2); }
.st-ntf--head .st-who { font-size: 12px; color: var(--ia-ink-soft); }

/* ----------------------------------------------------------------- journal */

.st-loghead {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--ia-line-2);
}

.st-log {
    display: grid;
    grid-template-columns: 128px 110px minmax(0, 1fr);
    gap: 16px;
    align-items: baseline;
    padding: 11px 16px;
}

.st-log.is-fresh { background: var(--ia-brand-wash); }

.st-log__when {
    font-size: 13px;
    color: var(--ia-ink-soft);
    font-variant-numeric: tabular-nums;
}

.st-log__who { font-size: 13px; color: var(--ia-ink-2); }

.st-log__text {
    font-size: 14px;
    line-height: 1.45;
    color: var(--ia-ink);
    text-wrap: pretty;
    overflow-wrap: anywhere;
}

/* --------------------------------------------------------------- year grid */

.st-year-wrap { padding: 16px; display: flex; flex-direction: column; gap: 18px; }

.st-year {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 18px 20px;
}

.st-month__name { margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--ia-ink-2); }
.st-month__days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }

.st-day {
    aspect-ratio: 1;
    border-radius: 3px;
    display: grid;
    place-items: center;
    font-size: 9.5px;
    font-variant-numeric: tabular-nums;
    color: var(--ia-faint);
}

.st-day.is-we { background: var(--ia-we); color: var(--ia-ink-soft); }
.st-day.is-off { background: var(--ia-primary); color: var(--ia-on-primary); font-weight: 600; }
.st-day.is-today { box-shadow: inset 0 0 0 1.5px var(--ia-ink); }

.st-hl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 24px; }
.st-hl__row { display: flex; gap: 10px; font-size: 13px; line-height: 1.45; }

.st-hl__when {
    min-width: 104px;
    flex: none;
    font-weight: 600;
    color: var(--ia-ink-2);
    font-variant-numeric: tabular-nums;
}

.st-hl__name { color: var(--ia-ink-soft); }

/* ------------------------------------------------------------------ narrow */

/* Below 720px of content (§2): every setting stacks with its control
   left-aligned under the label; the notification table loses «Кому» and its
   channel columns shrink to 48px; the access columns shrink; the year goes
   to three columns; journal rows collapse to one column. */
@container st (max-width: 719px) {
    .st-set { grid-template-columns: minmax(0, 1fr); gap: 10px; }
    .st-set__ctl { justify-content: flex-start; }
    .st-err { text-align: left; }

    .st-ntf { grid-template-columns: minmax(0, 1fr) 48px 48px 48px; }
    .st-ntf .st-who { display: none; }

    .st-acc { grid-template-columns: minmax(0, 1fr) 76px 96px; }

    .st-year { grid-template-columns: repeat(3, minmax(0, 1fr)); }

    .st-log { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    .st-hl { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    .st-sw,
    .st-sw::after { transition: none; }
    .st-saved { animation: none; }
}
