/* ==========================================================================
   CLN / SVPro Expenses — оформление по образцу демо-версии Muse.
   Светлая тёплая тема: белые карточки (радиус ~14px, мягкие тени) на
   светло-сером тёплом фоне, колонка мобильной ширины по центру.
   Акцент — тёплое золото обеих фирм; фирменный код везде:
   CLN = янтарь/золото, SVPro = синий.
   Гармония (проход 2026-11-01): единый ритм отступов — структурный 12px,
   внутри групп 8px, вертикальная шкала 4/8/12/16/20; одна система радиусов
   (карточки 14, блоки/поля/кнопки 12, мелкие контролы 10, оверлеи 20);
   одинаковая внутренняя кромка 16px (20px на десктопе) у всех секций.
   Фикс переполнения (2026-11-01): гриды — repeat(2, minmax(0, 1fr)),
   у плиток/блоков min-width: 0, подписи плиток ужимаются с многоточием,
   суммы не сжимаются — карточки больше не распирает на телефоне.
   ========================================================================== */

:root {
    --bg: #f5f2ec;
    --card: #ffffff;
    --ink: #1d1a16;
    --ink-2: #55504a;
    --muted: #91897d;
    --line: #e8e2d4;
    --line-soft: #f1ecdf;
    --field-line: #ddd5c3;
    --amber: #d97706;
    --amber-dark: #b45309;
    --amber-tint: #fdf6e9;
    --amber-border: #f0ddb6;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --blue-tint: #eef3fe;
    --blue-border: #bfd2f8;
    --green: #128a3e;
    --gst-tint: #fbf3cf;
    --gst-border: #e8dda6;
    --gst-ink: #8a6500;
    --dark: #1a1b1f;
    --red: #d3202c;
    --red-bg: #fdf0f0;
    --track: #e0d9c8;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(93, 74, 32, 0.05), 0 8px 24px rgba(93, 74, 32, 0.07);
    --shadow-lg: 0 24px 60px rgba(30, 26, 18, 0.28);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.45;
    padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px));
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
h3 { margin: 16px 0 8px; font-size: 15px; font-weight: 800; color: var(--ink); }

/* Фирменный код: название фирмы — её цветом, везде в приложении */
.firm-cln { color: var(--amber-dark); font-weight: 800; }
.firm-svpro { color: var(--blue-dark); font-weight: 800; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--field-line);
    background: var(--card);
    color: var(--ink);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease,
        box-shadow 0.15s ease, transform 0.05s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #fbf8f1; text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:focus-visible {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.22);
}
.btn.primary {
    background: var(--dark);
    border-color: var(--dark);
    color: #fff;
    box-shadow: 0 4px 14px rgba(26, 27, 31, 0.25);
}
.btn.primary:hover { background: #2a2b31; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: rgba(29, 26, 22, 0.06); }
.btn.wide { width: 100%; padding: 12px 14px; }
.btn.person {
    flex: 1 1 0;
    min-width: 0;
    padding: 12px 8px;
    font-size: 14.5px;
    font-weight: 700;
    color: var(--ink);
    border: 1px solid;
    box-shadow: var(--shadow);
}
#btnPersOleksandr { background: var(--blue-tint); border-color: var(--blue-border); }
#btnPersOleksandr:hover { background: #e2ecfe; }
#btnPersVitalii { background: var(--amber-tint); border-color: var(--amber-border); }
#btnPersVitalii:hover { background: #fbeed3; }
.inline-form { display: inline; }

/* ---------- Шапка: тонкая полоса с двумя баннерами ---------- */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--line);
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
}
.logo-strip {
    display: flex;
    gap: 8px;
    align-items: stretch;
    max-width: 608px;
    margin: 0 auto;
    width: 100%;
}
.logo-strip img {
    flex: 1 1 0;
    min-width: 0;
    height: 40px;
    object-fit: contain;
    background: #0c0c0e;
    border: 1px solid rgba(0, 0, 0, 0.25);
    border-radius: 10px;
    padding: 3px 6px;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 608px;
    margin: 8px auto 0;
}
.topbar-user .who {
    font-weight: 700;
    color: var(--ink);
    margin-right: auto;
    font-size: 14.5px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Каркас ---------- */
main {
    padding: 16px 16px 0;
    max-width: 640px;
    margin: 0 auto;
}
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}

/* ---------- Кнопки личных расходов (вверху, не закреплены) ---------- */
.person-buttons { display: flex; gap: 12px; margin-bottom: 12px; }

/* ---------- Итоги ---------- */
.sum-total { text-align: center; padding-bottom: 16px; }
.sum-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.sum-value {
    font-size: 40px;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
.sum-value.low { color: var(--red); font-size: 46px; }
.sum-warn {
    display: inline-block;
    margin-top: 8px;
    padding: 5px 12px;
    background: var(--red-bg);
    border: 1px solid #f2c1c4;
    border-radius: 999px;
    color: var(--red);
    font-weight: 700;
    font-size: 13.5px;
}
/* Остатки по картам — отдельными крупными блоками, как общий итог */
.balances {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}
.bal {
    min-width: 0;
    border: 1px solid;
    border-radius: 12px;
    padding: 16px 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.bal .k {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.bal .bal-value {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.15;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.bal-cln { background: var(--amber-tint); border-color: var(--amber-border); }
.bal-svpro { background: var(--blue-tint); border-color: var(--blue-border); }
.sum-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.tile {
    min-width: 0;
    border: 1px solid;
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}
.tile .k {
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tile .v {
    flex: none;
    color: var(--ink);
    font-weight: 600;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.tile-cln { background: var(--amber-tint); border-color: var(--amber-border); }
.tile-svpro { background: var(--blue-tint); border-color: var(--blue-border); }
.tile-gst {
    background: var(--gst-tint);
    border-color: var(--gst-border);
    grid-column: 1 / -1;
}
.sum-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.sum-actions .btn { flex: 1 1 40%; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-actions .inline-form { display: flex; flex: 1 1 100%; min-width: 0; }
.sum-actions .inline-form .btn { flex: 1; }

/* ---------- Поиск и фильтр ---------- */
.search-title {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.1px;
    color: var(--ink);
}
.search input[type="search"] {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    color: var(--ink);
    border: 1px solid var(--field-line);
    border-radius: 12px;
    background: #fff;
    margin-bottom: 12px;
    -webkit-appearance: none;
    appearance: none;
}
.search input[type="search"]:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.22);
}
.range-line {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: 2px;
}
.range-line span {
    color: var(--ink);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.range-row {
    display: flex;
    gap: 12px;
    align-items: center;
}
.range-row .btn { flex: 0 0 auto; }

/* Двойной ползунок: два input поверх одного трека, заливка между бегунками */
.dual-range {
    --lo: 0%;
    --hi: 100%;
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    height: 38px;
}
.dual-range::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(to right,
        var(--track) 0%, var(--track) var(--lo),
        var(--amber) var(--lo), var(--amber) var(--hi),
        var(--track) var(--hi), var(--track) 100%);
}
.dual-range input[type="range"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    pointer-events: none;
    cursor: pointer;
}
.dual-range input[type="range"]::-webkit-slider-runnable-track {
    height: 38px;
    background: transparent;
    border: none;
}
.dual-range input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    pointer-events: auto;
    width: 26px;
    height: 26px;
    margin-top: 6px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid var(--amber);
    box-shadow: 0 2px 8px rgba(180, 83, 9, 0.30);
    cursor: grab;
}
.dual-range input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; }
.dual-range input[type="range"]::-moz-range-track {
    height: 38px;
    background: transparent;
    border: none;
}
.dual-range input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid var(--amber);
    box-shadow: 0 2px 8px rgba(180, 83, 9, 0.30);
    cursor: grab;
}
.dual-range input[type="range"]:focus-visible { outline: none; }
.dual-range input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.22), 0 2px 8px rgba(180, 83, 9, 0.30);
}
.dual-range input[type="range"]:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.22), 0 2px 8px rgba(180, 83, 9, 0.30);
}
.search-info {
    margin-top: 12px;
    font-weight: 700;
    font-size: 14px;
    color: var(--ink);
}

/* ---------- Журнал по месяцам ---------- */
.month {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    overflow: hidden;
}
.month-head {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: #fdfaf3;
    cursor: pointer;
    padding: 12px 16px;
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease;
}
.month-head:hover { background: #faf3e2; }
.month-head:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--amber);
}
.month .m-title {
    display: block;
    font-weight: 700;
    font-size: 16px;
    text-transform: capitalize;
}
.month .m-stats {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: break-word;
}
.month .m-open {
    display: block;
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 600;
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: break-word;
}
.month.empty .month-head { opacity: 0.55; }
.month-body { border-top: 1px solid var(--line-soft); }

/* ---------- Строки записей ---------- */
.entry {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-top: 1px solid var(--line-soft);
}
.entry:first-child { border-top: none; }
.entry .thumb {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #faf7ef;
    border: 1px solid var(--line-soft);
    border-radius: 10px;
}
.entry .thumb img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    border-radius: 6px;
}
.entry .main { flex: 1 1 auto; min-width: 0; }
.entry .item {
    font-weight: 600;
    font-size: 14.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.entry .sub {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.entry .sub a { font-weight: 600; }
.entry .amt {
    font-weight: 700;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.entry .amt.income { color: var(--green); }
.entry .amt.firm { color: var(--ink); }
.entry .amt.personal { color: var(--muted); font-weight: 600; }
.entry .acts { display: flex; gap: 2px; flex: 0 0 auto; }
.entry .acts button {
    border: none;
    background: transparent;
    font-size: 15px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: var(--ink-2);
    transition: background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.entry .acts button:hover { background: #f3eee1; }
.entry .acts button:active { background: #eae3d0; }
.entry .acts button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--amber);
}

/* ---------- Метки ---------- */
.chip {
    display: inline-block;
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0.04em;
    line-height: 1;
    padding: 3.5px 6px;
    border-radius: 999px;
    vertical-align: 2px;
    margin-left: 6px;
}
.chip.sv { background: #dbe7fe; color: #1749a8; }
.chip.gst { background: #fbf0cd; color: var(--gst-ink); }

/* ---------- Плавающая кнопка «+»: тёмный круг, золотой плюс ---------- */
#fabAdd {
    position: fixed;
    right: 18px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 1px solid rgba(233, 199, 102, 0.45);
    background: var(--dark);
    color: #e9c766;
    font-size: 34px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 10px 26px rgba(26, 27, 31, 0.40);
    transition: transform 0.08s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
#fabAdd:hover { box-shadow: 0 14px 32px rgba(26, 27, 31, 0.45); }
#fabAdd:active { transform: scale(0.94); }
#fabAdd:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.30), 0 10px 26px rgba(26, 27, 31, 0.40);
}

/* ---------- Модальные окна и формы ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(24, 21, 16, 0.55);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.modal-box {
    background: var(--card);
    width: 100%;
    max-width: 560px;
    max-height: 92dvh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
    box-shadow: var(--shadow-lg);
}
@media (min-width: 640px) {
    .modal { align-items: center; padding: 20px; }
    .modal-box { border-radius: 20px; }
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.2px; min-width: 0; }
.modal-head .btn { flex: 0 0 auto; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1 1 0; min-width: 0; padding: 12px 14px; }

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: 12px;
}
label input,
label select {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 12px;
    font-size: 16px;
    font-weight: 400;
    color: var(--ink);
    border: 1px solid var(--field-line);
    border-radius: 12px;
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
label input:focus,
label select:focus {
    outline: none;
    border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.22);
}
label input[type="file"] {
    font-size: 14px;
    padding: 10px 12px;
    color: var(--ink-2);
}
.form-2col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-2col label { margin-bottom: 12px; min-width: 0; }
.checkline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--ink);
    margin: 0 0 0 12px;
    vertical-align: middle;
}
.checkline input {
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    accent-color: var(--amber-dark);
    display: inline-block;
    flex: 0 0 auto;
}
.photo-current { margin: 0 0 12px; font-size: 14px; }
.photo-current a { font-weight: 600; }

.alert {
    background: var(--red-bg);
    border: 1px solid #f2c1c4;
    color: #a11622;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 500;
    margin: 12px 0;
}
.okline {
    color: var(--green);
    font-size: 14px;
    font-weight: 600;
    margin: 12px 0;
}

/* ---------- Личные списки, GST, пользователи ---------- */
.person-total {
    font-weight: 800;
    font-size: 17px;
    margin-top: 12px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.gst-result {
    font-size: 15px;
    line-height: 1.8;
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--gst-tint);
    border: 1px solid var(--gst-border);
    border-radius: 12px;
    overflow-wrap: break-word;
}
.gst-result b { font-variant-numeric: tabular-nums; }
.user-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line-soft);
    font-weight: 600;
}
.user-row > * { min-width: 0; }
.empty-note {
    color: var(--muted);
    padding: 16px;
    text-align: center;
    font-size: 14px;
}

/* ---------- Страницы входа / первой настройки ---------- */
.auth-body {
    min-height: 100dvh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: calc(40px + env(safe-area-inset-top, 0px)) 16px 40px;
    background: var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 430px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 20px;
}
.auth-card .logo-strip { max-width: none; margin-bottom: 8px; }
.auth-card .logo-strip img { height: 44px; }
.auth-card h1 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.3px;
    margin: 16px 0 8px;
}
.auth-card .muted { line-height: 1.55; margin: 0 0 8px; }
.auth-card form { margin-top: 12px; }
.auth-card .btn.primary { margin-top: 4px; }

/* ---------- Десктоп ---------- */
@media (min-width: 720px) {
    main { padding-top: 20px; }
    .card { padding: 20px; }
    .sum-value { font-size: 44px; }
    .bal .bal-value { font-size: 34px; }
    .sum-value.low { font-size: 50px; }
    .logo-strip img { height: 44px; }
    .month-head { padding: 12px 20px; }
    .entry { padding: 12px 20px; }
    #fabAdd { right: 30px; }
}

/* ---------- Узкие экраны: подписи и суммы плиток влезают без многоточия ---------- */
@media (max-width: 480px) {
    .sum-grid { gap: 10px; }
    .tile { padding: 10px 8px; gap: 6px; }
    .tile .k { font-size: 12px; letter-spacing: -0.2px; }
    .tile .v { font-size: 14.5px; }
    .bal { padding: 14px 8px; }
    .bal .bal-value { font-size: 28px; }
}
