/* Дизайн система на портала — общи токени и компоненти. Мисленото
   е тази палитра/подредба да се пренесе и в бъдещото Flutter приложение
   (виж CLAUDE.md, "Roadmap"), затова токените са изнесени в :root. */

:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-surface-2: #fafbfc;
    --color-border: #e3e6ea;
    --color-border-strong: #d3d7dd;
    --color-text: #1a1d24;
    --color-text-muted: #656d78;
    --color-text-faint: #939aa5;

    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-primary-soft: #eef0fe;

    --color-success: #0f9d58;
    --color-success-soft: #e5f7ed;
    --color-warning: #b7791f;
    --color-warning-soft: #fdf3e0;
    --color-danger: #d43f3f;
    --color-danger-soft: #fbe9e9;
    --color-info: #2563a8;
    --color-info-soft: #e7f0fa;
    --color-neutral-soft: #eef0f3;

    --sidebar-width: 248px;
    --content-max: 1500px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(20, 22, 30, 0.06);
    --shadow-md: 0 4px 16px rgba(20, 22, 30, 0.08);
    --font-sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.6em; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; margin-top: 2rem; color: var(--color-text); }
h2:first-child { margin-top: 0; }
p { margin: 0 0 0.75em; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
small { color: var(--color-text-muted); }

/* ---------- App shell ---------- */

.app { display: flex; min-height: 100vh; align-items: stretch; }

.nav-toggle-input { display: none; }
.nav-scrim { display: none; }

.sidebar {
    width: var(--sidebar-width);
    flex: none;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.15rem 1.25rem;
    font-weight: 700;
    font-size: 1.05rem;
    border-bottom: 1px solid var(--color-border);
}
.brand-mark {
    width: 30px; height: 30px; border-radius: var(--radius-sm);
    background: var(--color-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 800;
}

.sidebar-nav { flex: 1; padding: 0.9rem 0.7rem; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.55rem 0.75rem; margin-bottom: 0.15rem;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted); font-weight: 500; font-size: 0.92rem;
}
.nav-item:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.nav-item.active { background: var(--color-primary-soft); color: var(--color-primary); }
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-badge {
    margin-left: auto; background: var(--color-danger); color: #fff;
    font-size: 0.72rem; font-weight: 700; border-radius: 999px;
    padding: 0.05rem 0.45rem; min-width: 1.3em; text-align: center;
}
.nav-section-gap { height: 0.75rem; }

.sidebar-footer { border-top: 1px solid var(--color-border); padding: 0.85rem 1rem; }
.company-switch select {
    width: 100%; margin-bottom: 0.6rem;
}
.user-chip {
    width: 100%; text-align: left; background: none; border: none; padding: 0.4rem 0.1rem;
    font: inherit; color: var(--color-text-muted); cursor: pointer;
}
.user-chip:hover { color: var(--color-danger); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: none;
    align-items: center; gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky; top: 0; z-index: 5;
}
.nav-burger {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    background: var(--color-surface-2); font-size: 1.1rem; cursor: pointer;
}

.content { flex: 1; padding: 1.75rem clamp(1rem, 3vw, 2.5rem); max-width: var(--content-max); width: 100%; }

/* ---------- Auth (login) shell ---------- */

.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card {
    width: 100%; max-width: 380px; background: var(--color-surface);
    border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md); padding: 2rem;
}

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

.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.page-header h1 { margin-bottom: 0.15rem; }
.page-header .subtitle { color: var(--color-text-muted); font-size: 0.9rem; }
.page-header .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.5rem 0.9rem; border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-strong); background: var(--color-surface);
    color: var(--color-text); font: inherit; font-weight: 600; font-size: 0.88rem;
    cursor: pointer; line-height: 1.2;
}
.btn:hover { background: var(--color-surface-2); text-decoration: none; }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.82rem; }
.btn-ghost { background: none; border-color: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }

.back-link { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.88rem; color: var(--color-text-muted); margin-bottom: 0.9rem; }
.back-link:hover { color: var(--color-primary); }

/* ---------- Cards / panels ---------- */

.card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
    padding: 1.1rem 1.25rem; margin-bottom: 1.25rem;
}

.filter-bar {
    display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); padding: 0.9rem 1.1rem; margin-bottom: 1.25rem;
}
.filter-bar .field { display: flex; flex-direction: column; gap: 0.3rem; }
.filter-bar label { font-size: 0.78rem; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.filter-bar .field-check { flex-direction: row; align-items: center; gap: 0.4rem; }
.filter-bar .field-check label { text-transform: none; font-weight: 500; font-size: 0.88rem; }
.filter-bar .spacer { flex: 1; }
.filter-bar .links { display: flex; gap: 0.9rem; align-items: center; font-size: 0.86rem; padding-bottom: 0.5rem; }

/* ---------- Tables ---------- */

.table-card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-sm); overflow: hidden;
}
.table-scroll { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data-table th, table.data-table td { padding: 0.65rem 1rem; text-align: left; white-space: nowrap; }
table.data-table th {
    background: var(--color-surface-2); color: var(--color-text-muted);
    font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.02em;
    border-bottom: 1px solid var(--color-border);
}
table.data-table th a { color: inherit; }
table.data-table th a:hover { color: var(--color-primary); text-decoration: none; }
table.data-table td { border-bottom: 1px solid var(--color-border); color: var(--color-text); }
table.data-table td.wrap { white-space: normal; }
table.data-table tbody tr:hover { background: var(--color-surface-2); }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data-table .strong { font-weight: 650; }

/* Compact key/value table used on detail pages (not the list grid). */
table.kv { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.kv th {
    text-align: left; color: var(--color-text-muted); font-weight: 500;
    padding: 0.5rem 1rem 0.5rem 0; width: 11rem; vertical-align: top;
}
table.kv td { padding: 0.5rem 0; border-bottom: 1px solid var(--color-border); }
table.kv tr:last-child td, table.kv tr:last-child th { border-bottom: none; }

/* ---------- Badges ---------- */

.badge {
    display: inline-flex; align-items: center; padding: 0.15rem 0.55rem;
    border-radius: 999px; font-size: 0.76rem; font-weight: 650;
    background: var(--color-neutral-soft); color: var(--color-text-muted);
    white-space: nowrap;
}
.badge-pending, .badge-processing { background: var(--color-info-soft); color: var(--color-info); }
.badge-processed { background: var(--color-success-soft); color: var(--color-success); }
.badge-needs_review, .badge-unassigned { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-duplicate, .badge-failed { background: var(--color-danger-soft); color: var(--color-danger); }

.badge-doc-proforma { background: var(--color-neutral-soft); color: var(--color-text-muted); }
.badge-doc-credit_note, .badge-doc-debit_note { background: var(--color-info-soft); color: var(--color-info); }
.badge-doc-other { background: var(--color-neutral-soft); color: var(--color-text-muted); }

/* ---------- Alerts / messages ---------- */

.toast-stack { padding: 0 clamp(1rem, 3vw, 2.5rem); padding-top: 1rem; }
.alert {
    display: flex; align-items: flex-start; gap: 0.6rem;
    border-radius: var(--radius-sm); padding: 0.7rem 1rem; margin-bottom: 0.6rem;
    font-size: 0.9rem; border: 1px solid transparent;
}
.alert-success { background: var(--color-success-soft); color: #0b6b3d; border-color: #bfe8cf; }
.alert-error { background: var(--color-danger-soft); color: #9c2b2b; border-color: #f3c6c6; }
.alert-warning { background: var(--color-warning-soft); color: #8a5a10; border-color: #f0dcac; }
.alert-info, .alert-debug { background: var(--color-info-soft); color: #1c4d7a; border-color: #c6dcf0; }
.alert a { color: inherit; text-decoration: underline; }

/* ---------- Forms ---------- */

form .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.5rem; }
form .form-grid .full { grid-column: 1 / -1; }
.field-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--color-text-muted); margin-bottom: 0.3rem; }
.field-hint { display: block; font-size: 0.78rem; color: var(--color-text-faint); margin-top: 0.25rem; font-weight: 400; }

input[type=text], input[type=date], input[type=number], input[type=password], input[type=email], input[type=file], select, textarea {
    font: inherit; padding: 0.5rem 0.65rem; border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text);
    width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--color-primary-soft); border-color: var(--color-primary); }
input[type=file] { border-style: dashed; padding: 1.1rem 0.75rem; text-align: center; background: var(--color-surface-2); }
label { font-size: 0.92rem; }
.radio-row { display: flex; gap: 1.5rem; align-items: center; }
.radio-row label { display: flex; align-items: center; gap: 0.4rem; font-weight: 500; }
.checkbox-row { display: flex; align-items: center; gap: 0.4rem; }
button { cursor: pointer; }

/* ---------- Misc ---------- */

.empty-state {
    text-align: center; padding: 3rem 1.5rem; color: var(--color-text-muted);
    background: var(--color-surface); border: 1px dashed var(--color-border-strong); border-radius: var(--radius-md);
}
.section-divider { border: none; border-top: 1px solid var(--color-border); margin: 1.75rem 0; }
.muted { color: var(--color-text-muted); }
.mono { font-variant-numeric: tabular-nums; }
.pill-links { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pill-link {
    padding: 0.3rem 0.7rem; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
    background: var(--color-surface-2); border: 1px solid var(--color-border);
}
.pill-link.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .sidebar {
        position: fixed; z-index: 20; left: 0; top: 0; bottom: 0;
        transform: translateX(-100%); transition: transform 0.18s ease;
        box-shadow: var(--shadow-md);
    }
    .nav-toggle-input:checked ~ .sidebar { transform: translateX(0); }
    .nav-toggle-input:checked ~ .nav-scrim {
        display: block; position: fixed; inset: 0; background: rgba(20, 22, 30, 0.35); z-index: 15;
    }
    .topbar { display: flex; }
    .content { padding: 1.25rem 1rem; }
    .toast-stack { padding: 1rem 1rem 0; }
    form .form-grid { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .spacer { display: none; }
}
