/* ============================================================
   DESIGN TOKENS — v2, modernized UI chrome
   Documents (invoices/receipts/credit notes) stay sharp-edged
   and paper-like via --radius-doc. The app shell itself (cards,
   buttons, nav, inputs) gets softer, more contemporary depth.
   ============================================================ */
:root {
    --ink:          #101826;
    --ink-soft:      #2C3A4E;
    --paper:        #F6F5F1;
    --paper-raised: #FFFFFF;
    --line:         #E4E0D4;
    --brass:        #B8873A;
    --brass-dark:   #8E6825;
    --brass-light:  #E7CFA0;
    --success:      #3B7A57;
    --success-bg:   #E7F0EA;
    --danger:       #A73E3E;
    --danger-bg:    #F5E7E7;
    --warn:         #B8873A;
    --warn-bg:      #F5EEDF;
    --info-bg:      #E8EFFB;
    --info:         #2A5DAB;

    --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
    --font-body:    'Inter', 'Segoe UI', sans-serif;
    --font-mono:    'JetBrains Mono', 'Courier New', monospace;

    --radius:       10px;   /* app chrome: cards, buttons, inputs, badges */
    --radius-sm:    7px;
    --radius-doc:   3px;    /* printable documents only — ledger/paper feel */

    --shadow-card:     0 1px 2px rgba(16,24,38,0.05), 0 1px 1px rgba(16,24,38,0.04);
    --shadow-raised:   0 4px 14px rgba(16,24,38,0.09), 0 1px 3px rgba(16,24,38,0.06);
    --shadow-floating: 0 12px 32px rgba(16,24,38,0.16), 0 2px 6px rgba(16,24,38,0.08);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }
*:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 0.4em;
    letter-spacing: -0.01em;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
a { color: var(--ink); }
.icon { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; }

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

.sidebar {
    width: 240px;
    background: var(--ink);
    color: #C9D2DE;
    flex-shrink: 0;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
}
.sidebar .brand {
    padding: 0 22px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 14px;
}
.sidebar .brand .mark {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
    display: flex; align-items: center; gap: 8px;
}
.sidebar .brand .sub { font-size: 11px; color: #7C8AA0; margin-top: 4px; }

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 1px 10px;
    padding: 9px 12px;
    color: #B7C1D1;
    text-decoration: none;
    font-size: 13.5px;
    border-radius: var(--radius-sm);
    transition: background 0.15s var(--ease), color 0.15s var(--ease), transform 0.15s var(--ease);
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active {
    background: linear-gradient(135deg, rgba(184,135,58,0.22), rgba(184,135,58,0.10));
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(184,135,58,0.35);
}
.sidebar nav a.active .icon { stroke: var(--brass-light); }
.sidebar nav .section-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #5D6B80;
    padding: 16px 22px 6px;
}
.sidebar nav a.disabled {
    color: #4A5568;
    cursor: default;
    pointer-events: none;
}
.sidebar nav a.disabled .tag {
    font-size: 9px;
    background: rgba(255,255,255,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    margin-left: auto;
}

/* ---------- Topbar with org switcher ("the ledger tab") ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 60px;
    background: var(--paper-raised);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 0 rgba(16,24,38,0.02);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 26px;
    position: sticky; top: 0; z-index: 20;
}
.org-switch {
    display: flex; align-items: center; gap: 10px;
    position: relative;
    padding: 5px 10px 5px 6px;
    border-radius: var(--radius);
    transition: background 0.15s var(--ease);
}
.org-switch:hover { background: var(--paper); }
.org-seal {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(160deg, var(--ink) 0%, #1D2A3D 100%);
    color: var(--brass-light);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 12px;
    border: 1.5px solid var(--brass);
    box-shadow: 0 2px 6px rgba(16,24,38,0.15);
}
.org-switch select {
    border: none;
    background: transparent;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 14.5px;
    color: var(--ink);
    padding: 4px 2px;
    cursor: pointer;
}
.user-menu { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--ink-soft); }

.content { padding: 28px 32px 60px; max-width: 1180px; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; }
.page-head .eyebrow { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brass-dark); margin-bottom: 4px; font-weight: 600; }
.page-head h1 { font-size: 23px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 13px;
    padding: 10px 19px;
    border-radius: 9px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    letter-spacing: 0.01em;
    transition: transform 0.12s var(--ease), box-shadow 0.18s var(--ease), background 0.18s var(--ease), border-color 0.18s var(--ease), filter 0.15s var(--ease);
}
.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-primary { background: linear-gradient(180deg, #1D2A3D, var(--ink)); color: #fff; box-shadow: 0 1px 2px rgba(16,24,38,0.3), inset 0 1px 0 rgba(255,255,255,0.06); }
.btn-primary:hover { box-shadow: 0 6px 16px rgba(16,24,38,0.28); transform: translateY(-1.5px); }

.btn-brass { background: linear-gradient(180deg, #C99A52, var(--brass)); color: #fff; box-shadow: 0 1px 2px rgba(142,104,37,0.4), inset 0 1px 0 rgba(255,255,255,0.18); }
.btn-brass:hover { filter: brightness(1.06); box-shadow: 0 8px 20px rgba(142,104,37,0.38); transform: translateY(-1.5px); }

.btn-ghost { background: var(--paper-raised); color: var(--ink); border-color: var(--line); box-shadow: 0 1px 2px rgba(16,24,38,0.03); }
.btn-ghost:hover { border-color: #C7C1B0; box-shadow: var(--shadow-card); transform: translateY(-1px); }

.btn-danger { background: #fff; color: var(--danger); border-color: #E8CACA; }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); box-shadow: 0 4px 10px rgba(167,62,62,0.14); transform: translateY(-1px); }

.btn-sm { padding: 6px 13px; font-size: 12px; border-radius: 7px; }

/* Dashed "add" style for line-item / secondary-add actions */
.btn-add {
    background: transparent;
    border: 1.5px dashed #C7BFA8;
    color: var(--ink-soft);
    border-radius: var(--radius-sm);
}
.btn-add:hover { border-color: var(--brass); color: var(--brass-dark); background: rgba(184,135,58,0.05); }

/* ---------- Cards / tables ---------- */
.card {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 22px;
    margin-bottom: 20px;
    transition: box-shadow 0.2s var(--ease);
}
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-soft);
    border-bottom: 1.5px solid var(--ink);
    padding: 8px 10px;
}
td { padding: 12px 10px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
tr { transition: background 0.12s var(--ease); }
tr:hover td { background: rgba(184,135,58,0.045); }
.amount { font-family: var(--font-mono); text-align: right; }

/* ---------- Status seals (badges) ---------- */
.seal {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 9px;
    border-radius: 20px;
    border: 1px solid currentColor;
}
.seal-draft   { color: #6B7280; background: #F1F1EF; }
.seal-sent    { color: var(--info); background: var(--info-bg); }
.seal-partial { color: var(--warn); background: var(--warn-bg); }
.seal-paid    { color: var(--success); background: var(--success-bg); }
.seal-overdue { color: var(--danger); background: var(--danger-bg); }
.seal-void    { color: #6B7280; background: #ECECEC; text-decoration: line-through; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; letter-spacing: 0.01em; }
input, select, textarea {
    width: 100%;
    font-family: var(--font-body);
    font-size: 13.5px;
    padding: 10px 13px;
    border: 1.5px solid var(--line);
    border-radius: 8px;
    background: #FCFBF9;
    color: var(--ink);
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}
select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238A93A3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
    cursor: pointer;
}
input:hover, select:hover, textarea:hover { border-color: #CFC9BA; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brass);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(184,135,58,0.13);
}
input::placeholder, textarea::placeholder { color: #B3AFA3; }
.field { margin-bottom: 17px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hint { font-size: 11.5px; color: #8A93A3; margin-top: 4px; }

/* ---------- Invoice line-item builder ---------- */
.line-items-card {
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 12px;
}
.line-items-table { margin: 0; }
.line-items-table thead th {
    background: var(--paper);
    border-bottom: 1.5px solid var(--line);
    padding: 11px 14px;
    font-size: 10.5px;
}
.line-items-table th, .line-items-table td { padding: 10px 10px; border-bottom: 1px solid var(--line); }
.line-items-table tbody tr:last-child td { border-bottom: none; }
.line-items-table tbody tr:hover td { background: rgba(184,135,58,0.035); }
.line-items-table input, .line-items-table select { padding: 7px 10px; font-size: 13px; border-radius: 6px; }
.line-items-table .col-desc { width: 40%; }
.line-items-table .col-qty, .line-items-table .col-price, .line-items-table .col-tax { width: 12%; }
.line-items-table .remove-line-btn {
    width: 26px; height: 26px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid var(--line); color: #9AA1AC;
    cursor: pointer; transition: all 0.15s var(--ease); font-size: 13px; padding: 0;
}
.line-items-table .remove-line-btn:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

.totals-block {
    max-width: 340px; margin-left: auto; margin-top: 18px;
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 20px;
}
.totals-block .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; }
.totals-block .row.grand {
    border-top: 1.5px dashed #CFC9BA; margin-top: 4px;
    font-family: var(--font-display); font-weight: 700; font-size: 18px; padding-top: 12px;
    color: var(--brass-dark);
}

/* ---------- Alerts ---------- */
.alert { padding: 11px 15px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 54px 20px; color: var(--ink-soft); }
.empty-state h3 { color: var(--ink); }

/* ---------- Stat cards (dashboard) ---------- */
.stat-card {
    display: flex; align-items: flex-start; gap: 14px;
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 20px 22px;
    transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.stat-card:hover { box-shadow: var(--shadow-raised); transform: translateY(-2px); }
.stat-icon {
    width: 40px; height: 40px; border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon.brass   { background: var(--warn-bg); color: var(--brass-dark); }
.stat-icon.success { background: var(--success-bg); color: var(--success); }
.stat-icon.danger  { background: var(--danger-bg); color: var(--danger); }
.stat-icon .icon { width: 20px; height: 20px; }

/* ---------- Mobile: hamburger menu + off-canvas sidebar ---------- */
.hamburger-btn {
    display: none;
    align-items: center; justify-content: center;
    width: 38px; height: 38px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper-raised);
    cursor: pointer;
    flex-shrink: 0;
}
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
    .hamburger-btn { display: flex; }

    .app-shell { position: relative; }

    .sidebar {
        position: fixed;
        top: 0; bottom: 0; left: 0;
        width: 250px;
        z-index: 101;
        transform: translateX(-100%);
        transition: transform 0.25s var(--ease);
        overflow-y: auto;
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-floating); }

    .sidebar-backdrop.open {
        display: block;
        position: fixed; inset: 0;
        background: rgba(16,24,38,0.45);
        z-index: 100;
    }

    .topbar { padding: 0 14px; gap: 10px; }
    .org-switch select { font-size: 13px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .user-menu span { display: none; } /* hide name/role text on very small screens, keep logout icon+label */
    .content { padding: 16px 14px 40px; }

    .page-head { flex-direction: column; align-items: flex-start; gap: 12px; }
    .page-head > div:last-child { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }

    .field-row { grid-template-columns: 1fr; }

    /* Tables scroll horizontally inside their card instead of crushing columns */
    .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 620px; }
    .line-items-card table { min-width: 560px; }

    .stat-card, div[style*="grid-template-columns: repeat(3"],
    div[style*="grid-template-columns: repeat(4"],
    div[style*="grid-template-columns: repeat(5"] { grid-template-columns: 1fr !important; }
}

/* Print/doc-specific radius override lives inline on invoice/receipt/credit-note
   pages via #printable-* selectors using --radius-doc where needed. */
