:root {
    --bg: #ffffff;
    --text: #000000;
    --hint: #8e8e93;
    --link: #2481cc;
    --button: #2481cc;
    --button-text: #ffffff;
    --secondary-bg: #f1f1f4;
    --section-bg: #ffffff;
    --header-bg: #ffffff;
    --accent: #2481cc;
    --destructive: #e53935;
    --separator: #d9d9de;
    --income: #2e9d57;
    --expense: #e0463f;
    --safe-top: 0px;
    --safe-bottom: 0px;
    --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--secondary-bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.35;
}

#app { min-height: 100vh; }

.page {
    padding: calc(12px + var(--safe-top)) 16px calc(88px + var(--safe-bottom));
    max-width: 640px;
    margin: 0 auto;
}

h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 18px 0 8px; font-weight: 600; }
.hint { color: var(--hint); font-size: 14px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 12px; }
.income { color: var(--income); }
.expense { color: var(--expense); }

.card {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
}

.splash {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--hint);
}

.spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--separator);
    border-top-color: var(--button);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Кнопки */
.btn {
    appearance: none;
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 16px;
    font-weight: 600;
    background: var(--button);
    color: var(--button-text);
    cursor: pointer;
}
.btn.secondary { background: var(--secondary-bg); color: var(--text); }
.btn.danger { background: transparent; color: var(--destructive); }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: .5; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.actions .btn { padding: 12px 2px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 8px; font-size: 12px; background: var(--secondary-bg); color: var(--hint); margin-left: 4px; }
.badge.warn { background: color-mix(in srgb, #f5a623 22%, var(--section-bg)); color: var(--text); }
.qr-text { white-space: pre-wrap; word-break: break-all; background: var(--secondary-bg); border-radius: 10px; padding: 10px; font-size: 13px; margin: 8px 0; max-height: 200px; overflow: auto; }
.actions .btn span.big { font-size: 24px; }

/* Поля */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }
input, select, textarea {
    width: 100%;
    font: inherit;
    padding: 11px 12px;
    border-radius: 10px;
    border: 1px solid var(--separator);
    background: var(--section-bg);
    color: var(--text);
}
input.amount { font-size: 32px; font-weight: 700; text-align: center; padding: 14px; }
input[type=checkbox] { width: auto; }
.check { display: flex; align-items: center; gap: 10px; margin: 8px 0; }

.seg { display: flex; background: var(--secondary-bg); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button {
    flex: 1; border: 0; background: transparent; color: var(--text); padding: 8px; border-radius: 8px; font: inherit; font-size: 14px;
}
.seg button.on { background: var(--section-bg); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* Сетка категорий */
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-item {
    border: 2px solid transparent;
    background: var(--secondary-bg);
    border-radius: 12px;
    padding: 8px 2px;
    text-align: center;
    font-size: 11px;
    color: var(--text);
    cursor: pointer;
}
.cat-item .emoji { display: block; font-size: 24px; margin-bottom: 2px; }
.cat-item.on { border-color: var(--button); background: color-mix(in srgb, var(--button) 12%, var(--section-bg)); }

/* Списки операций */
.day-title { margin: 16px 4px 6px; font-size: 13px; color: var(--hint); display: flex; justify-content: space-between; }
.list { background: var(--section-bg); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--separator); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item .ico { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }
.item .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sum { font-weight: 600; white-space: nowrap; text-align: right; }

/* Прогресс-бары */
.bar { height: 8px; background: var(--secondary-bg); border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; border-radius: 4px; background: var(--income); transition: width .3s; }
.bar > div.warn { background: #f5a623; }
.bar > div.over { background: var(--expense); }

/* Графики */
.chart-box { position: relative; height: 200px; }
.donut-wrap { position: relative; height: 190px; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.legend { margin-top: 10px; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* Сводка */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat .label { font-size: 13px; color: var(--hint); }
.stat .value { font-size: 20px; font-weight: 700; }
.balance { font-size: 30px; font-weight: 700; margin: 2px 0 8px; }

/* Нижнее меню */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0;
    display: flex;
    background: var(--section-bg);
    border-top: 1px solid var(--separator);
    padding-bottom: var(--safe-bottom);
    z-index: 10;
}
.tabbar a {
    flex: 1; text-align: center; padding: 8px 0 6px; color: var(--hint); text-decoration: none; font-size: 11px;
}
.tabbar a .ico { display: block; font-size: 20px; }
.tabbar a.active { color: var(--button); font-weight: 600; }

/* Сообщения */
.banner { padding: 10px 12px; border-radius: 10px; margin-bottom: 10px; font-size: 14px; }
.banner.error { background: color-mix(in srgb, var(--destructive) 14%, var(--section-bg)); color: var(--destructive); }
.banner.warn { background: color-mix(in srgb, #f5a623 18%, var(--section-bg)); }
.banner.ok { background: color-mix(in srgb, var(--income) 15%, var(--section-bg)); }

.mic {
    width: 112px; height: 112px; border-radius: 50%; border: 0; font-size: 44px;
    background: var(--button); color: var(--button-text); margin: 16px auto; display: block;
}
.mic.rec { background: var(--expense); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 16px rgba(224,70,63,.18); } }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); }

#blazor-error-ui {
    background: #ffe9e8; color: #8a1f1f; bottom: 0; display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .reload { margin-left: 8px; }
