/* ---------- Шрифты и базовые переменные ---------- */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Manrope:wght@400;500;600;700&display=swap');

:root {
    --bg: #f5f1ea;
    --surface: #ffffff;
    --surface-2: #faf6ef;
    --ink: #1a1a1a;
    --ink-soft: #555;
    --ink-muted: #888;
    --line: #e5dfd3;
    --line-strong: #d4cdbe;
    --primary: #1f4d3c;
    --primary-soft: #e8f0eb;
    --accent: #c4622d;
    --danger: #a8301c;
    --warn: #b88416;
    --ok: #2d7d4a;
    --info: #3a6b8c;
    --shadow-sm: 0 1px 2px rgba(20,20,20,.04), 0 1px 3px rgba(20,20,20,.06);
    --shadow-md: 0 4px 16px rgba(20,20,20,.08);
    --radius: 6px;
    --radius-lg: 10px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: 'Manrope', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin: 0 0 .6em;
}
h1 { font-size: 2rem; line-height: 1.15; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: #1a2622;
    color: #d8dad6;
    padding: 28px 0;
    position: sticky; top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar .brand {
    padding: 0 24px 24px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    margin-bottom: 16px;
}
.sidebar .brand-name {
    font-family: 'Fraunces', serif;
    font-size: 1.3rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.01em;
}
.sidebar .brand-sub {
    font-size: .75rem;
    color: #8a9590;
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: .12em;
}
.sidebar nav a {
    display: flex; align-items: center;
    gap: 10px;
    padding: 10px 24px;
    color: #c5c9c5;
    font-size: .92rem;
    border-left: 3px solid transparent;
    transition: all .15s;
}
.sidebar nav a:hover {
    background: rgba(255,255,255,.04);
    color: #fff;
    text-decoration: none;
}
.sidebar nav a.active {
    background: rgba(196,98,45,.08);
    color: #fff;
    border-left-color: var(--accent);
}
.sidebar nav .group-title {
    padding: 18px 24px 6px;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .15em;
    color: #6a7570;
}
.sidebar .user-box {
    margin-top: auto;
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .85rem;
}
.sidebar .user-box .name { color: #fff; font-weight: 600; }
.sidebar .user-box .role { color: #8a9590; font-size: .78rem; }
.sidebar .user-box a { color: #c4622d; font-size: .82rem; }

.main {
    padding: 32px 40px;
    max-width: 1200px;
}

/* ---------- Топбар (заголовок + действия) ---------- */
.page-head {
    display: flex; justify-content: space-between; align-items: flex-end;
    margin-bottom: 28px;
    gap: 24px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--ink-soft); margin-top: 4px; font-size: .95rem; }

.crumbs {
    font-size: .82rem;
    color: var(--ink-muted);
    margin-bottom: 8px;
}
.crumbs a { color: var(--ink-soft); }

/* ---------- Карточки ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}
.card-head {
    display: flex; justify-content: space-between; align-items: center;
    margin: -4px 0 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}
.card-head h2, .card-head h3 { margin: 0; }

/* ---------- Сетка KPI ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.kpi {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
}
.kpi::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--primary);
}
.kpi.is-income::before { background: var(--ok); }
.kpi.is-expense::before { background: var(--accent); }
.kpi.is-profit::before { background: var(--primary); }
.kpi.is-warn::before { background: var(--warn); }
.kpi .label {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-muted);
    font-weight: 600;
}
.kpi .value {
    font-family: 'Fraunces', serif;
    font-size: 1.8rem;
    font-weight: 600;
    margin-top: 6px;
    color: var(--ink);
}
.kpi .hint { font-size: .82rem; color: var(--ink-soft); margin-top: 4px; }

/* ---------- Таблицы ---------- */
.tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
}
.tbl th {
    text-align: left;
    padding: 10px 14px;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-muted);
    font-weight: 700;
    border-bottom: 1px solid var(--line-strong);
    background: var(--surface-2);
}
.tbl td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .num.neg { color: var(--danger); }
.tbl .num.pos { color: var(--ok); }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px;
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
}
.btn:hover { background: #163a2c; text-decoration: none; color: #fff; }
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #861f10; }
.btn.ghost { background: transparent; color: var(--primary); padding: 6px 12px; }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.sm { padding: 5px 12px; font-size: .82rem; }

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

/* ---------- Формы ---------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}
.form-row {
    margin-bottom: 16px;
}
.form-row label, .form-grid label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 4px;
}
.form-row .hint, .form-grid .hint {
    font-size: .78rem;
    color: var(--ink-muted);
    margin-top: 4px;
}
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=email], select, textarea {
    width: 100%;
    padding: 9px 12px;
    font-family: inherit;
    font-size: .95rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: 0;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31,77,60,.12);
}
textarea { min-height: 80px; resize: vertical; }
input[type=file] {
    padding: 6px;
    background: var(--surface-2);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    width: 100%;
    font-size: .9rem;
}

.form-actions {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    display: flex; gap: 10px;
}

/* ---------- Бейджи ---------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.badge-ok    { background: #e1f0e6; color: var(--ok); }
.badge-bad   { background: #f5e2dd; color: var(--danger); }
.badge-warn  { background: #f7eed7; color: var(--warn); }
.badge-info  { background: #e0eaf1; color: var(--info); }
.badge-muted { background: #ece8df; color: var(--ink-soft); }

/* ---------- Уведомления (flash) ---------- */
.flash {
    padding: 12px 18px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: .92rem;
    border-left: 4px solid;
}
.flash.success { background: #e1f0e6; border-color: var(--ok); color: #1a4f30; }
.flash.error   { background: #f5e2dd; border-color: var(--danger); color: #75200f; }
.flash.info    { background: #e0eaf1; border-color: var(--info); color: #224961; }
.flash.warn    { background: #f7eed7; border-color: var(--warn); color: #7a5610; }

/* ---------- Прогресс-бар бюджета ---------- */
.progress {
    background: var(--line);
    height: 8px;
    border-radius: 100px;
    overflow: hidden;
    margin-top: 8px;
}
.progress > span {
    display: block;
    height: 100%;
    background: var(--primary);
    border-radius: 100px;
    transition: width .3s;
}
.progress > span.over { background: var(--danger); }
.progress > span.warn { background: var(--warn); }

/* ---------- Логин ---------- */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 20% 30%, rgba(31,77,60,.08), transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(196,98,45,.06), transparent 50%),
        var(--bg);
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    width: 100%; max-width: 380px;
    box-shadow: var(--shadow-md);
}
.login-box h1 {
    font-size: 1.6rem;
    text-align: center;
    margin-bottom: 4px;
}
.login-box .sub {
    text-align: center;
    color: var(--ink-soft);
    font-size: .9rem;
    margin-bottom: 28px;
}

/* ---------- Чек-фото ---------- */
.receipt-thumb {
    display: inline-block;
    width: 60px; height: 60px;
    border-radius: var(--radius);
    background: var(--surface-2) center/cover no-repeat;
    border: 1px solid var(--line);
    transition: transform .15s;
}
.receipt-thumb:hover { transform: scale(1.05); }

.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--ink-muted);
}
.empty h3 { font-family: 'Fraunces', serif; color: var(--ink-soft); margin-bottom: 8px; }

/* ---------- Утилиты ---------- */
.row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--ink-muted); }
.small { font-size: .85rem; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }

/* ---------- Адаптивность ---------- */
@media (max-width: 800px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; padding: 16px 0; }
    .sidebar .user-box { border-top: 0; padding-top: 8px; }
    .main { padding: 20px; }
}

/* ---------- Уведомления / dropdowns ---------- */
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.tbl.small td, .tbl.small th { padding: 6px 10px; font-size: .8rem; }

/* ---------- Стили для печати финального отчёта ---------- */
@media print {
    body { background: white !important; }
    .app { display: block !important; }
    .sidebar, .flash, .crumbs, .actions { display: none !important; }
    .main { padding: 0 !important; max-width: 100% !important; }
    a { color: inherit; text-decoration: none; }
    .card { box-shadow: none !important; border: 1px solid #ddd; }
    @page { size: A4; margin: 18mm 16mm; }
}
