:root {
    --bg: #f3f6fb;
    --bg-strong: #0d1b2a;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --text: #122033;
    --text-muted: #5c6f86;
    --border: #dbe4ef;
    --primary: #ef7d32;
    --primary-strong: #d8651b;
    --accent: #0e7490;
    --success: #1f9d64;
    --danger: #c93f3f;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --shadow-sm: 0 8px 22px rgba(13, 27, 42, 0.06);
    --shadow-md: 0 16px 36px rgba(13, 27, 42, 0.12);
    --font-body: 'Manrope', sans-serif;
    --font-head: 'Space Grotesk', sans-serif;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    background:
        radial-gradient(circle at 0% 0%, #d7ecff 0%, transparent 28%),
        radial-gradient(circle at 100% 0%, #fbe3d3 0%, transparent 25%),
        linear-gradient(180deg, #f9fbff 0%, var(--bg) 45%, #eef3f9 100%);
    padding-bottom: 84px;
}

body.is-public {
    background: linear-gradient(180deg, #0d1b2a 0%, #14253b 45%, #1c3656 100%);
    color: #f2f6fb;
}

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 22px 16px;
}

.app-header {
    max-width: 760px;
    margin: 0 auto;
    padding: 14px 16px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #f6a260 0%, var(--primary) 100%);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-head);
    font-weight: 700;
}

.brand-text {
    font-family: var(--font-head);
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
}

.header-action {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-decoration: none;
    font-weight: 700;
}

h1, h2, h3 {
    font-family: var(--font-head);
    letter-spacing: -0.01em;
}

h1 { font-size: 1.8rem; margin-bottom: 8px; }
h2 { font-size: 1.3rem; margin-bottom: 8px; }
h3 { font-size: 1.06rem; margin-bottom: 6px; }
p { margin-bottom: 12px; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-sm { font-size: 0.88rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: #0b647d; }

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

.page-head > div {
    min-width: 0;
}

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

.card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.card-link:hover {
    border-color: #c8d8ea;
    box-shadow: var(--shadow-md);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 46px;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.96rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    transition: transform 120ms ease, filter 120ms ease;
}

.btn:hover { filter: brightness(0.98); }
.btn:active { transform: translateY(1px); }

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, #ff9e56 0%, var(--primary) 100%);
}

.btn-secondary {
    color: var(--text);
    background: #f8fbff;
    border: 1px solid var(--border);
}

.btn-danger {
    color: #fff;
    background: linear-gradient(135deg, #e76f6f 0%, var(--danger) 100%);
}

.btn-sm {
    width: auto;
    min-height: 36px;
    padding: 8px 12px;
    font-size: 0.85rem;
}

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    min-height: 46px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.96rem;
    -webkit-appearance: none;
    appearance: none;
}

textarea.form-control { min-height: 110px; }

.form-control:focus {
    outline: none;
    border-color: #8eb4d8;
    box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.14);
}

.form-error {
    font-size: 0.8rem;
    color: var(--danger);
    margin-top: 4px;
}

.flash-container {
    max-width: 760px;
    margin: 0 auto;
    padding: 12px 16px 0;
}

.flash {
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    margin-bottom: 8px;
    border: 1px solid;
    font-size: 0.9rem;
    font-weight: 600;
}

.flash-success { color: #0f7048; border-color: #80d9b2; background: #e9fbf3; }
.flash-danger { color: #8f2626; border-color: #e8a5a5; background: #feefef; }
.flash-info { color: #1e5670; border-color: #a6cde0; background: #edf7fc; }

.bottom-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 10px;
    background: rgba(13, 27, 42, 0.92);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(12px);
    display: flex;
    justify-content: space-around;
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: rgba(227, 237, 248, 0.72);
    font-size: 0.66rem;
    font-weight: 700;
    min-width: 54px;
    text-decoration: none;
}

.nav-item.active { color: #fff; }
.nav-item svg { width: 20px; height: 20px; }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.auth-header {
    text-align: center;
    margin-bottom: 18px;
    padding-top: 32px;
}

.auth-header h1,
.auth-header p,
.auth-footer {
    color: #d7e8fb;
}

.auth-panel {
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
}

.auth-footer a { color: #fff; text-decoration: underline; }

.line-item {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 10px;
}

.line-item-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.line-item-numbers {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
}

.line-item-numbers .form-group { margin-bottom: 0; }
.line-item-numbers label { font-size: 0.74rem; }
.line-item-numbers .form-control { min-height: 38px; font-size: 0.84rem; padding: 8px 9px; }

.line-total {
    min-height: 38px;
    display: flex;
    align-items: center;
    padding: 8px 9px;
    border-radius: 10px;
    background: #fff;
    border: 1px dashed #c9d8e8;
    font-size: 0.86rem;
    font-weight: 700;
}

.remove-item { margin-top: 8px; width: auto; }

.totals-panel {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 0.93rem;
}

.total-final {
    border-top: 2px solid #18324f;
    margin-top: 8px;
    padding-top: 10px;
    font-size: 1.12rem;
    font-weight: 800;
}

.vat-toggle {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.vat-toggle input[type="checkbox"] { width: 18px; height: 18px; }
.vat-toggle label { margin-bottom: 0; font-size: 0.9rem; }

.vat-rate-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.vat-rate-inline input {
    width: 82px;
    min-height: 34px;
    padding: 6px 8px;
}

.autocomplete-wrap { position: relative; }

.customer-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 50;
    max-height: 220px;
    overflow-y: auto;
}

.dropdown-item {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:active { background: #f6fbff; }

.status-pill {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.status-draft { color: #415b78; background: #eaf1fa; }
.status-sent { color: #0f5f77; background: #ddf4fb; }
.status-accepted { color: #116940; background: #dff9ec; }
.status-declined { color: #8f2e2e; background: #ffe9e9; }
.status-paid { color: #116940; background: #dff9ec; }
.status-overdue { color: #8f2e2e; background: #ffe9e9; }
.status-cancelled { color: #5f6670; background: #edf1f5; }
.status-scheduled { color: #415b78; background: #eaf1fa; }
.status-in_progress { color: #0f5f77; background: #ddf4fb; }
.status-completed { color: #116940; background: #dff9ec; }

.sticky-actions {
    position: sticky;
    bottom: 80px;
    background: linear-gradient(180deg, rgba(243, 246, 251, 0.74), rgba(243, 246, 251, 1));
    padding: 10px 0;
    display: flex;
    gap: 8px;
}

.sticky-actions .btn { flex: 1; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.stat-card {
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: #fff;
    padding: 14px;
    box-shadow: var(--shadow-sm);
}

.stat-card.stat-success {
    background: linear-gradient(180deg, #f1fff8 0%, #e1f8ec 100%);
    border-color: #afe3c7;
}

.stat-value {
    font-family: var(--font-head);
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    margin-top: 4px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 700;
}

.quick-links {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.quick-link-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 700;
}

.list-item-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.list-item-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

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

.split-actions > * { flex: 1; }

.filter-grid {
    display: grid;
    grid-template-columns: 1fr 130px;
    gap: 8px;
}

.search-bar { margin-top: 10px; }

.error-screen {
    text-align: center;
    padding: 54px 16px;
}

.error-code {
    font-family: var(--font-head);
    font-size: 3.5rem;
    line-height: 1;
    margin-bottom: 6px;
    color: var(--primary);
}

.error-code.error-danger { color: var(--danger); }

@media (max-width: 560px) {
    .line-item-numbers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .quick-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stats-grid { grid-template-columns: 1fr; }
    .filter-grid { grid-template-columns: 1fr; }
}
