:root {
    --brand: #2728C4;
    --brand-hover: #1f20a0;
    --brand-tint: #EEEEFC;
    --brand-tint-2: #E1E1FA;
    --ink: #14161F;
    --ink-soft: #4B4E5C;
    --muted: #8A8D9B;
    --border: #E7E8F0;
    --bg: #F6F7FB;
    --card: #FFFFFF;
    --green: #17875A;
    --green-tint: #E4F7EF;
    --amber: #9A6B00;
    --amber-tint: #FFF3D6;
    --red: #C0392B;
    --red-tint: #FDECEA;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(20,22,31,0.04), 0 1px 8px rgba(20,22,31,0.04);
    --shadow-md: 0 4px 16px rgba(20,22,31,0.08);
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    margin: 0;
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== App shell: sidebar + content ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px 18px;
}
.sidebar-logo img { height: 28px; }
.sidebar-logo .app-tag {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-top: 1px;
}
.sidebar-nav { padding: 6px 12px; flex: 1; }
.sidebar-section-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 14px 12px 6px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    font-weight: 500;
    font-size: 13.5px;
    margin-bottom: 2px;
    transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.nav-item.active { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.nav-item svg { flex-shrink: 0; opacity: 0.85; }
.nav-item.active svg { opacity: 1; }
.nav-item.primary {
    background: var(--brand);
    color: #fff;
    justify-content: center;
    margin: 6px 0 14px;
    font-weight: 600;
}
.nav-item.primary:hover { background: var(--brand-hover); color: #fff; }

.sidebar-footer {
    padding: 14px 20px 18px;
    border-top: 1px solid var(--border);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 10px;
}
.sidebar-user .avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--brand-tint-2);
    color: var(--brand);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12px;
    flex-shrink: 0;
}
.sidebar-user .name { font-weight: 600; font-size: 13px; color: var(--ink); }
.sidebar-footer .logout-link {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--muted); font-weight: 500;
}
.sidebar-footer .logout-link:hover { color: var(--red); text-decoration: none; }

.main {
    flex: 1;
    min-width: 0;
}
.main-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 36px 60px;
}

/* ===== Page header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.page-header .sub { color: var(--muted); font-size: 13px; margin-top: 5px; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--brand);
    color: #fff;
    border: 1px solid var(--brand);
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--card); color: var(--ink-soft); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); color: var(--ink); border-color: var(--border); }
.btn-danger { background: var(--card); color: var(--red); border: 1px solid var(--red-tint); }
.btn-danger:hover { background: var(--red-tint); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn svg { width: 15px; height: 15px; }

/* ===== Cards ===== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}
.card-tight { padding: 0; overflow: hidden; }

/* ===== Stat cards ===== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
}
.stat-card .stat-label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 8px;
}
.stat-card .stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.stat-card .stat-value.green { color: var(--green); }
.stat-card .stat-value.brand { color: var(--brand); }
.stat-card .stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; }
table th, table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 13px;
}
table th {
    background: var(--bg);
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
}
table tbody tr:last-child td { border-bottom: none; }
table tbody tr:hover { background: var(--bg); }
.table-scroll { overflow-x: auto; border-radius: var(--radius); }
.table-scroll table { min-width: 100%; }

/* dense table for line-item editing */
.dense-table th, .dense-table td { padding: 7px 8px; font-size: 12.5px; }

/* ===== Inputs ===== */
input[type=text], input[type=number], input[type=password], select, textarea {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    width: 100%;
    font-family: inherit;
    background: var(--card);
    color: var(--ink);
    transition: border-color .12s, box-shadow .12s;
}
input[type=text]:focus, input[type=number]:focus, input[type=password]:focus, select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-tint);
}
.line-input { width: 78px; }
.line-input-wide { width: 132px; }
/* hide number spinners for a cleaner dense table */
.dense-table input[type=number]::-webkit-outer-spin-button,
.dense-table input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.dense-table input[type=number] { -moz-appearance: textfield; }

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-draft { background: #F0F1F5; color: #6B6F80; }
.badge-sent { background: var(--amber-tint); color: var(--amber); }
.badge-received { background: var(--green-tint); color: var(--green); }
.badge-closed { background: var(--brand-tint); color: var(--brand); }

.totals-row { font-weight: 700; background: var(--brand-tint) !important; }
.totals-row td { border-bottom: none !important; }

/* ===== Login page ===== */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    background-image: radial-gradient(circle at 20% 20%, var(--brand-tint) 0%, transparent 45%),
                       radial-gradient(circle at 85% 80%, var(--brand-tint) 0%, transparent 40%);
}
.login-box {
    background: var(--card);
    padding: 40px 36px;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    width: 360px;
    text-align: center;
    border: 1px solid var(--border);
}
.login-box img { height: 40px; margin-bottom: 20px; }
.login-box h2 { margin: 0 0 22px; font-size: 17px; font-weight: 700; color: var(--ink-soft); }
.login-box input { margin-bottom: 12px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 4px; }

/* ===== Flash / alerts ===== */
.flash {
    display: flex; align-items: center; gap: 9px;
    padding: 11px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 13px;
    font-weight: 500;
}
.flash-error { background: var(--red-tint); color: var(--red); }
.flash-success { background: var(--green-tint); color: var(--green); }

.warning-box {
    display: flex; gap: 10px;
    background: var(--amber-tint);
    border: 1px solid #F5DFA0;
    color: #6B4E00;
    padding: 13px 16px;
    border-radius: var(--radius);
    font-size: 12.5px;
    line-height: 1.55;
    margin-bottom: 20px;
}
.warning-box svg { flex-shrink: 0; margin-top: 1px; }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }

.field-row { display: flex; gap: 16px; margin-bottom: 4px; flex-wrap: wrap; }
.field { flex: 1; min-width: 180px; margin-bottom: 16px; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }

.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.small { font-size: 12px; }
.section-title { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.section-desc { font-size: 12.5px; color: var(--muted); margin: 0 0 16px; }

.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--muted);
}
.empty-state svg { margin-bottom: 12px; opacity: 0.5; }
.empty-state p { margin: 4px 0; font-size: 13.5px; }

/* Print view */
@media print {
    .no-print { display: none !important; }
    .sidebar { display: none !important; }
    .app-shell { display: block; }
    body { background: #fff; }
    .main-inner { max-width: 100%; padding: 0; }
    .card { border: none; box-shadow: none; padding: 0; }
}

@media (max-width: 900px) {
    .sidebar { width: 68px; }
    .sidebar-logo .app-tag, .nav-item span.label, .sidebar-user .name { display: none; }
    .sidebar-logo img { height: 24px; }
    .main-inner { padding: 22px 16px 50px; }
}
