:root {
    --ink: #1a2332;
    --ink-soft: #5b6472;
    --bg: #f4f6f9;
    --card: #ffffff;
    --border: #e3e7ee;
    --brand: #7a1f3d;
    --brand-soft: #fbe9ee;
    --green: #1b7a4d;
    --green-soft: #e7f6ee;
    --red: #b3261e;
    --red-soft: #fbe9e8;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

#login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 340px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

.login-card h1 {
    font-size: 20px;
    margin: 0 0 4px;
    color: var(--brand);
}

.login-card .sub {
    color: var(--ink-soft);
    font-size: 13px;
    margin-bottom: 24px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    margin-top: 14px;
}

input, select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}

textarea { resize: vertical; }

button {
    cursor: pointer;
    font-family: inherit;
}

.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: 6px;
    border: none;
    font-size: 14px;
    font-weight: 600;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: #611830; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f0f2f5; }
.btn-danger { background: var(--red-soft); color: var(--red); border: 1px solid #f2c9c6; }
.btn-full { width: 100%; margin-top: 20px; }

.error-msg {
    background: var(--red-soft);
    color: var(--red);
    padding: 9px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-top: 14px;
}

#app { display: none; min-height: 100vh; }
#app.visible { display: flex; }

.sidebar {
    width: 220px;
    background: var(--brand);
    color: #fff;
    padding: 22px 0;
    flex-shrink: 0;
    position: relative;
    transition: margin-left 0.2s ease, transform 0.2s ease;
}

.sidebar-hide-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 6px;
    background: rgba(255,255,255,0.12);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    line-height: 1;
}
.sidebar-hide-btn:hover { background: rgba(255,255,255,0.22); }

.sidebar-show-btn {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 40;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    font-size: 17px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    display: none;
}

.sidebar-backdrop { display: none; }

/* Desktop/tablet: sidebar pushes content; toggled = collapsed off to the left. */
@media (min-width: 769px) {
    #app.sidebar-toggled .sidebar { margin-left: -220px; }
    #app.sidebar-toggled .sidebar-show-btn { display: block; }
}

.sidebar .brand {
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    margin-bottom: 12px;
}

.sidebar .brand strong { display: block; font-size: 16px; }
.sidebar .brand span { font-size: 12px; opacity: 0.75; }

.nav-item {
    display: block;
    padding: 11px 20px;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 14px;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.active { background: rgba(255,255,255,0.14); border-left-color: #fff; font-weight: 600; color: #fff; }

.sidebar .user-box {
    margin-top: auto;
    padding: 16px 20px 0;
    border-top: 1px solid rgba(255,255,255,0.15);
    font-size: 12px;
}

.sidebar .user-box .role-pill {
    display: inline-block;
    background: rgba(255,255,255,0.15);
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    margin-top: 4px;
}

.sidebar .logout-link {
    display: block;
    margin-top: 10px;
    color: #fff;
    opacity: 0.8;
    cursor: pointer;
    font-size: 12px;
}

.main { flex: 1; padding: 28px 36px; max-width: 1200px; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
}

.page-header h2 { margin: 0; font-size: 22px; }
.page-header .sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}

.stat-card .label { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat-card.positive .value { color: var(--green); }
.stat-card.negative .value { color: var(--red); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; padding: 10px 12px; color: var(--ink-soft); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; border-bottom: 1px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill-issued { background: var(--green-soft); color: var(--green); }
.pill-void { background: var(--red-soft); color: var(--red); text-decoration: line-through; }

.amount-in { color: var(--green); font-weight: 600; }
.amount-out { color: var(--red); font-weight: 600; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-grid .full { grid-column: 1 / -1; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }

.modal-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(20,20,30,0.4);
    align-items: center; justify-content: center;
    z-index: 100;
}
.modal-backdrop.visible { display: flex; }
.modal {
    background: #fff;
    border-radius: var(--radius);
    padding: 28px;
    width: 480px;
    max-height: 88vh;
    overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.empty-state { text-align: center; padding: 40px; color: var(--ink-soft); font-size: 13px; }

.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab { padding: 9px 16px; cursor: pointer; font-size: 13px; color: var(--ink-soft); border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.report-summary { display: flex; gap: 24px; margin-bottom: 18px; }
.report-summary .item { }
.report-summary .item .label { font-size: 12px; color: var(--ink-soft); }
.report-summary .item .value { font-size: 18px; font-weight: 700; }

.hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

/* Mobile: sidebar is an overlay, hidden by default; toggled = shown over a
   backdrop. Placed after every base rule it touches (.sidebar, .main) so it
   actually wins the cascade - same-specificity selectors resolve by source
   order, and an @media block earlier in the file loses to a later plain rule
   even when its condition matches. */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        z-index: 60;
        margin-left: 0 !important;
        transform: translateX(-100%);
        overflow-y: auto;
    }
    .sidebar-show-btn { display: block; }
    #app.sidebar-toggled .sidebar { transform: translateX(0); }
    #app.sidebar-toggled .sidebar-show-btn { display: none; }
    #app.sidebar-toggled .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(20,20,30,0.45);
        z-index: 55;
    }
    /* Top padding clears the fixed hamburger button (38px tall, 14px from the
       top) so it floats above the page title instead of covering its letters. */
    .main { padding: 68px 16px 20px; }
}

@media print {
    .no-print { display: none !important; }
}
