/* ============================================================
   EatMe Учёт — дизайн-система v2 (mobile-first)
   Современный SaaS: нейтральная база, изумрудный акцент, Inter
   ============================================================ */

:root {
    --accent: #0E9374;
    --dark: #0B6E57;
    --accent-ink: #0B6E57;
    --accent-soft: #E2F3ED;
    --bg: #F5F6F5;
    --caramel: #ECEDEA;
    --text: #181D23;
    --muted: #6A7380;
    --card: #FFFFFF;
    --hairline: #E3E5E1;
    --ok-bg: #E2F3ED;
    --ok: #0E9374;
    --err-bg: #FBEBEC;
    --err: #CE454F;
    --warn-bg: #FBF1DC;
    --warn-ink: #8A5E0A;
    --radius: 14px;
    --radius-sm: 11px;
    --shadow: 0 1px 2px rgba(24, 29, 35, 0.05);
    --shadow-lift: 0 2px 6px rgba(24, 29, 35, 0.07), 0 12px 32px rgba(24, 29, 35, 0.09);
    --tabbar-h: 66px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 26px);
}

a { color: var(--accent); }

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

/* ---------- Шапка ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 18px 12px;
    background: rgba(255, 255, 255, 0.88);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--hairline);
    color: var(--text);
}

.app-title {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}

.app-title .logo-dot {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    background: linear-gradient(135deg, #12A77F, #0B6E57);
    color: #fff;
    flex: 0 0 auto;
}

.app-title .logo-dot svg { width: 17px; height: 17px; }

.app-title .logo-sub {
    color: var(--accent);
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    border: 1px solid var(--hairline);
    background: #fff;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    text-decoration: none;
    transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.settings-link:active { color: var(--accent-ink); border-color: var(--accent); transform: scale(0.94); }

.logout-form { margin: 0; }

.logout-btn {
    background: #fff;
    color: var(--muted);
    border: 1px solid var(--hairline);
    border-radius: 999px;
    padding: 8px 16px;
    min-height: 40px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.logout-btn:active { color: var(--err); border-color: var(--err); }

/* ---------- Каркас ---------- */

.app-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 16px 8px;
}

h2 {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--text);
}

h3 { letter-spacing: -0.015em; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 2px 0 16px;
}

.page-head h2 { margin: 0; }

/* ---------- Карточки и списки ---------- */

.card {
    background: var(--card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

a.card {
    transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

a.card:active {
    transform: scale(0.99);
    border-color: #D3D7D2;
}

.card-title {
    margin: 0 0 6px;
    font-size: 17px;
    color: var(--text);
}

.empty-state {
    text-align: center;
    padding: 34px 20px;
}

.empty-state::before {
    content: '🌿';
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    margin: 0 auto 12px;
    border-radius: 18px;
    background: var(--accent-soft);
    font-size: 26px;
}

.empty-state p { margin: 6px 0; }

/* ---------- Кнопки ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 46px;
    min-width: 46px;
    padding: 11px 20px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 15.5px;
    font-weight: 700;
    letter-spacing: -0.005em;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(11, 110, 87, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.14);
    transition: transform 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}

.btn:active {
    background: var(--dark);
    transform: scale(0.98);
}

.btn:disabled { opacity: 0.6; }

.btn-secondary {
    background: var(--caramel);
    color: var(--text);
    box-shadow: none;
}

.btn-secondary:active { background: #DFE1DC; }

/* ---------- Флеш-сообщения ---------- */

.flash {
    max-width: 688px;
    margin: 12px auto 0;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--hairline);
    border-left: 4px solid var(--ok);
    background: var(--ok-bg);
    color: var(--dark);
    font-weight: 600;
    box-shadow: var(--shadow);
}

.flash-error { border-left-color: var(--err); background: var(--err-bg); color: var(--err); }

.flash-warning { border-left-color: #D9A400; background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- Нижняя навигация (плавающая) ---------- */

.tabbar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    z-index: 20;
    display: flex;
    height: var(--tabbar-h);
    padding: 6px;
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(18px) saturate(1.5);
    backdrop-filter: blur(18px) saturate(1.5);
    border: 1px solid var(--hairline);
    border-radius: 18px;
    box-shadow: 0 8px 28px rgba(24, 29, 35, 0.14);
}

.tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 44px;
    border-radius: 13px;
    color: var(--muted);
    text-decoration: none;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    transition: color 0.15s ease, background 0.15s ease;
}

.tabbar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 26px;
    border-radius: 9px;
    transition: background 0.15s ease;
}

.tabbar-icon svg { width: 21px; height: 21px; }

.tabbar-item.active { color: var(--accent-ink); }

.tabbar-item.active .tabbar-icon { background: var(--accent-soft); }

.tabbar-item:active { background: rgba(14, 147, 116, 0.07); }

@media (min-width: 720px) {
    .tabbar {
        max-width: 560px;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* ---------- Поиск и фильтры ---------- */

.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.search-bar input {
    flex: 1;
    min-height: 46px;
    padding: 11px 16px;
    border: 1px solid var(--hairline);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    box-shadow: var(--shadow);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 147, 116, 0.18);
}

.chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 8px;
    margin-bottom: 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--hairline);
    background: #fff;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip.active {
    background: var(--text);
    border-color: var(--text);
    color: #fff;
}

/* ---------- Строки материалов/композиций ---------- */

a.card.material-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: inherit;
    text-decoration: none;
}

.material-main { min-width: 0; }

.material-name {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
}

.material-cat { font-size: 13px; }

.material-meta { text-align: right; flex: 0 0 auto; }

.material-stock {
    font-weight: 800;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.material-cost {
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

/* ---------- Формы ---------- */

.form-field { margin-bottom: 14px; }

.form-field label,
.form-label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.01em;
}

.form-field input,
.form-field select,
.form-field textarea,
.row-newname,
.cat-row input {
    width: 100%;
    min-height: 46px;
    padding: 11px 14px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field textarea { resize: vertical; }

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.row-newname:focus,
.cat-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 147, 116, 0.18);
}

.field-error {
    margin-top: 5px;
    color: var(--err);
    font-size: 14px;
    font-weight: 600;
}

.card-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.card-actions form { margin: 0; }

.props {
    margin: 0 0 12px;
    display: grid;
    gap: 8px;
}

.prop {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px dashed var(--hairline);
    padding-bottom: 7px;
}

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

.prop dd {
    margin: 0;
    font-weight: 700;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.badge-archived {
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--caramel);
    color: var(--text);
    font-size: 12.5px;
    font-weight: 700;
}

.archive-toggle {
    margin: 18px 0 8px;
    text-align: center;
    font-size: 14px;
}

/* ---------- Строки документа (приход и др.) ---------- */

.purchase-row {
    position: relative;
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: 14px 46px 6px 14px;
    margin-bottom: 12px;
    background: #fff;
    box-shadow: var(--shadow);
}

.row-remove {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(24, 29, 35, 0.06);
    color: var(--muted);
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.row-remove:active { background: var(--err-bg); color: var(--err); }

.row-remove:disabled {
    opacity: 0.35;
    cursor: default;
}

.row-hint {
    min-height: 18px;
    margin-top: 2px;
    font-size: 13px;
    color: var(--muted);
}

.row-material { position: relative; }

.row-suggest {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 30;
    max-height: 260px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lift);
    -webkit-overflow-scrolling: touch;
}

.row-suggest-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 11px 14px;
    border: none;
    border-bottom: 1px solid var(--hairline);
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}

.row-suggest-item:last-child { border-bottom: none; }

.row-suggest-item:active { background: var(--accent-soft); }

.row-suggest-name {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.row-suggest-meta { font-size: 13px; flex: 0 0 auto; color: var(--muted); }

.row-suggest-empty {
    padding: 12px 14px;
    color: var(--muted);
    font-size: 14px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.rows-total {
    margin: 14px 0 4px;
    font-size: 19px;
    font-weight: 800;
    color: var(--text);
    text-align: right;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

/* ---------- Списки и карточки приходов ---------- */

a.card.purchase-row-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: inherit;
    text-decoration: none;
}

.purchase-main { min-width: 0; }

.purchase-date { font-weight: 700; }

.purchase-supplier { font-size: 13px; }

.purchase-meta { text-align: right; flex: 0 0 auto; }

.purchase-total {
    font-weight: 800;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.purchase-count { font-size: 13px; }

.badge-source {
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--caramel);
    color: var(--text);
    font-size: 12.5px;
    font-weight: 700;
}

.lines { display: grid; gap: 10px; }

.line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    border-bottom: 1px dashed var(--hairline);
    padding-bottom: 8px;
}

.line:last-child { border-bottom: none; }

.line-main { min-width: 0; }

.line-name {
    font-weight: 600;
    text-decoration: none;
    color: var(--text);
}

.line-detail { font-size: 13px; }

.line-meta { text-align: right; flex: 0 0 auto; }

.line-delta { font-weight: 700; color: var(--text); }

.line-sum { font-size: 14px; font-variant-numeric: tabular-nums; }

.purchase-photo {
    max-width: 100%;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

/* ---------- Бейджи ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge-ok { background: var(--ok-bg); color: var(--ok); }

.badge-lack { background: var(--err-bg); color: var(--err); }

.badge-neutral { background: var(--caramel); color: var(--text); }

.card-warn { border: 2px solid #D9A400; background: var(--warn-bg); }

/* ---------- Композиции ---------- */

.comp-fin {
    font-size: 13px;
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

.comp-margin { font-size: 15px; }

.card.deficit {
    background: var(--err-bg);
    border-color: rgba(206, 69, 79, 0.3);
}

.card.deficit h3 {
    margin-top: 0;
    color: var(--err);
}

.card.deficit ul {
    margin: 0;
    padding-left: 20px;
    color: var(--err);
}

/* ---------- Дашборд склада ---------- */

.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 22px;
}

.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 6px 12px;
    border-radius: var(--radius);
    background: #fff;
    border: 1px solid var(--hairline);
    color: var(--text);
    font-weight: 700;
    font-size: 13.5px;
    text-align: center;
    text-decoration: none;
    box-shadow: var(--shadow);
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.quick-action:active {
    transform: scale(0.97);
    border-color: var(--accent);
}

.quick-action-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent-ink);
}

.quick-action-icon svg { width: 20px; height: 20px; }

.dash-section { margin-bottom: 24px; }

.dash-section h3 {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.dash-lack {
    font-size: 13px;
    color: var(--err);
    margin-top: 2px;
}

/* ---------- Чек (OCR + экран проверки) ---------- */

.receipt-drop,
.form-field label.receipt-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 26px 16px;
    border: 2px dashed rgba(14, 147, 116, 0.4);
    border-radius: var(--radius);
    background: rgba(14, 147, 116, 0.05);
    color: var(--text);
    cursor: pointer;
    text-align: center;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.receipt-drop:active {
    background: rgba(14, 147, 116, 0.1);
    transform: scale(0.99);
}

.receipt-drop svg {
    width: 34px;
    height: 34px;
    color: var(--accent);
}

.receipt-drop-title {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.01em;
}

.receipt-drop-hint {
    font-size: 13px;
    color: var(--muted);
}

.receipt-preview {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 8px 0;
    box-shadow: var(--shadow);
}

.ocr-progress {
    height: 8px;
    border-radius: 999px;
    background: rgba(14, 147, 116, 0.14);
    overflow: hidden;
    margin: 10px 0 4px;
}

.ocr-progress-bar {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--accent);
    transition: width 0.2s ease;
}

.receipt-raw {
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.receipt-row-skip .form-field {
    opacity: 0.4;
}

.receipt-weight-hint {
    margin: -4px 0 8px;
    padding: 7px 11px;
    border-radius: var(--radius-sm);
    background: var(--warn-bg);
    color: var(--warn-ink);
    font-size: 13px;
    font-weight: 600;
}

.review-badge {
    display: inline-flex;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 700;
}

.review-badge-ok { background: var(--ok-bg); color: var(--ok); }

.review-badge-warn { background: var(--warn-bg); color: var(--warn-ink); }

.sticky-submit {
    position: sticky;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
    z-index: 15;
    width: 100%;
    margin-top: 12px;
    box-shadow: 0 8px 20px rgba(11, 110, 87, 0.3);
}

/* ---------- Вход (auth) ---------- */

.login-wrap {
    display: flex;
    justify-content: center;
    padding-top: 7vh;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 28px 22px 22px;
    box-shadow: var(--shadow-lift);
}

.login-brand {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    border-radius: 18px;
    background: linear-gradient(135deg, #12A77F, #0B6E57);
    box-shadow: 0 8px 20px rgba(11, 110, 87, 0.3);
}

.login-brand svg { width: 36px; height: 36px; color: #fff; }

.login-card h2 {
    text-align: center;
    margin: 0 0 18px;
}

.login-card .flash {
    margin: 0 0 12px;
}

.login-submit { width: 100%; }

/* ---------- Настройки ---------- */

.cat-list {
    display: grid;
    gap: 8px;
    margin-bottom: 12px;
}

.cat-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0;
}

.cat-row input { flex: 1; min-width: 0; }

.cat-row .btn { flex: 0 0 auto; }

.cat-add {
    padding-top: 12px;
    border-top: 1px dashed var(--hairline);
}
