:root {
    --bg: #f3f6f8;
    --bg-accent: #e7eef2;
    --surface: #ffffff;
    --text: #1d2b33;
    --muted: #5f7380;
    --line: #d7e0e6;
    --brand: #1f6f78;
    --brand-soft: #d7ebee;
    --brand-dark: #15545b;
    --danger: #b42318;
    --ok: #067647;
    --shadow: 0 10px 30px rgba(29, 43, 51, 0.06);
    --radius: 14px;
    --font: "Manrope", "Segoe UI", sans-serif;
    --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(1200px 500px at 10% -10%, #d9eef1 0%, transparent 55%),
        radial-gradient(900px 400px at 100% 0%, #e8f1f6 0%, transparent 50%),
        var(--bg);
    min-height: 100vh;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }
code, .mono { font-family: var(--mono); font-size: 0.92em; }

.app {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: linear-gradient(180deg, #f8fbfc 0%, #eef5f7 100%);
    border-right: 1px solid var(--line);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.sidebar-brand, .auth-brand {
    display: flex;
    gap: 12px;
    align-items: center;
}
.logo-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 1.05rem; }
.brand-tag { color: var(--muted); font-size: 0.82rem; }
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-link {
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text);
    font-weight: 500;
}
.nav-link:hover, .nav-link.is-active {
    background: var(--brand-soft);
    color: var(--brand-dark);
}
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.user-chip {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    display: grid;
    gap: 2px;
}
.user-chip span { color: var(--muted); font-size: 0.85rem; word-break: break-all; }

.main { padding: 28px 32px 48px; }
.page-header h1 { margin: 0 0 20px; font-size: 1.7rem; font-weight: 700; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 18px;
}
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 1.1rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { display: block; margin-top: 6px; font-size: 1.6rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 10px 14px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    background: var(--bg-accent);
    color: var(--text);
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: #fef3f2; color: var(--danger); border-color: #fecdca; }
.btn-sm { padding: 6px 10px; font-size: 0.88rem; }
.btn-block { width: 100%; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    background: #fff;
}
.field.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 24px;
}
.form-grid, .filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
}
.field-actions { display: flex; gap: 8px; align-items: end; padding-bottom: 2px; }
.stack { display: grid; gap: 14px; }
.mt { margin-top: 16px; }
.muted { color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.82rem; font-weight: 600; }

.alert {
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border: 1px solid var(--line);
}
.alert-success { background: #ecfdf3; border-color: #abefc6; color: var(--ok); }
.alert-error { background: #fef3f2; border-color: #fecdca; color: var(--danger); }

.badge {
    display: inline-flex;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--bg-accent);
    font-size: 0.78rem;
    font-weight: 600;
}
.badge-ok { background: #dcfae6; color: var(--ok); }
.badge-err { background: #fee4e2; color: var(--danger); }

.kv { display: grid; gap: 10px; margin: 0; }
.kv > div { display: grid; grid-template-columns: 200px 1fr; gap: 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
    background: var(--brand-soft);
    border-radius: 12px;
    padding: 10px 12px;
    display: grid;
    gap: 4px;
}
.chip-label { font-size: 0.78rem; color: var(--brand-dark); font-weight: 700; }

.pager { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.pager-link {
    min-width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    border: 1px solid var(--line);
    color: var(--text);
}
.pager-link.is-active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Auth */
.auth-body { display: grid; place-items: center; padding: 24px; }
.auth-shell { width: min(420px, 100%); display: grid; gap: 18px; }
.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 28px 24px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; }

/* Cheque like OFD */
.cheque-page { display: grid; justify-items: center; gap: 16px; }
.cheque-toolbar { width: min(540px, 100%); }
.cheque {
    width: min(540px, 100%);
    background: transparent;
}
.cheque-body {
    background: #fff;
    border-left: 1px solid #ededed;
    border-right: 1px solid #ededed;
    padding: 28px 36px 20px;
    color: #304d5d;
}
.cheque-wave {
    height: 8px;
    background:
        radial-gradient(circle at 8px 0, transparent 7px, #fff 8px) repeat-x,
        linear-gradient(#fff, #fff);
    background-size: 16px 8px, 100% 100%;
}
.cheque-wave-top { transform: rotate(180deg); }
.cheque-wave-bottom { margin-top: -1px; }
.cheque-org { text-align: center; display: grid; gap: 10px; font-size: 13px; line-height: 1.35; }
.cheque-org-name { font-weight: 700; font-size: 12px; text-transform: uppercase; }
.cheque-title {
    text-align: center;
    color: #639fa4;
    font-weight: 700;
    font-size: 14px;
    margin: 36px 0 28px;
    letter-spacing: 0.02em;
}
.cheque-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 11px;
    line-height: 1.25;
    padding-top: 10px;
}
.cheque-row span { color: #304d5d; }
.cheque-row strong { font-weight: 500; text-align: right; }
.cheque-meta, .cheque-items, .cheque-total, .cheque-fiscal {
    border-bottom: 1px solid #e8e8e8;
    padding-bottom: 20px;
    margin-bottom: 8px;
}
.cheque-item { padding: 18px 0 8px; border-bottom: 1px solid #f0f0f0; }
.cheque-item:last-child { border-bottom: 0; }
.cheque-item-name { font-size: 12px; }
.cheque-item-price { text-align: right; font-size: 11px; padding-top: 8px; }
.cheque-total-line {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    font-weight: 700;
    padding: 12px 0 4px;
}
.cheque-footer {
    text-align: center;
    color: #4ba1a5;
    padding: 24px 0 8px;
}
.cheque-footer p { margin: 0 0 18px; font-size: 13px; font-weight: 600; }
.cheque-qr { display: block; margin: 0 auto 12px; }

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .stats { grid-template-columns: 1fr 1fr; }
    .main { padding: 18px 16px 40px; }
    .kv > div { grid-template-columns: 1fr; gap: 2px; }
    .cheque-body { padding: 24px 18px; }
}
