/* ── Malt Media Invoicing Portal ── */
:root {
    --mustard: #B8892A;
    --black: #0A0A0A;
    --burgundy: #7A2535;
    --white: #FAFAFA;
    --grey-light: #F0EDEA;
    --grey-mid: #C8C3BD;
    --grey-dark: #6B6560;
    --sidebar-width: 220px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--grey-light);
    color: var(--black);
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--black);
    color: var(--white);
    padding: 2rem 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 0 1.5rem 2rem;
    border-bottom: 2px solid var(--mustard);
}

.sidebar-logo {
    width: 80px;
    height: auto;
    display: block;
    margin-bottom: 8px;
}

.sidebar-subtitle {
    display: block;
    color: var(--grey-mid);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: left;
}

.nav-links {
    list-style: none;
    margin-top: 1.5rem;
}

.nav-links a {
    display: block;
    padding: 0.75rem 1.5rem;
    color: var(--grey-mid);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-links a:hover {
    color: var(--white);
    background: rgba(184, 137, 42, 0.1);
}

.nav-links a.active {
    color: var(--mustard);
    border-left-color: var(--mustard);
    background: rgba(184, 137, 42, 0.08);
}

/* ── Main content ── */
.content {
    margin-left: var(--sidebar-width);
    padding: 2rem 2.5rem;
    flex: 1;
    max-width: 1100px;
}

h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--black);
}

h1 .accent { color: var(--mustard); }

/* ── Flash messages ── */
.flash-messages { margin-bottom: 1.5rem; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.flash-success { background: #d4edda; color: #155724; }
.flash-error { background: #f8d7da; color: #721c24; }
.flash-warning { background: #fff3cd; color: #856404; }

/* ── Cards / Stats ── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    border: 1px solid var(--grey-mid);
}

.stat-card .label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--grey-dark);
    margin-bottom: 0.4rem;
}

.stat-card .value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--black);
}

.stat-card .value.mustard { color: var(--mustard); }
.stat-card .value.burgundy { color: var(--burgundy); }

/* ── Tables ── */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--grey-mid);
}

th {
    background: var(--black);
    color: var(--mustard);
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--grey-light);
    font-size: 0.88rem;
}

tr:last-child td { border-bottom: none; }
tr:hover { background: rgba(184, 137, 42, 0.04); }

/* ── Status badges ── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-draft { background: var(--grey-light); color: var(--grey-dark); }
.badge-sent { background: #d4edda; color: #155724; }
.badge-paid { background: #d1ecf1; color: #0c5460; }
.badge-overdue { background: #f8d7da; color: var(--burgundy); }
.badge-written-off { background: var(--grey-mid); color: var(--black); }
.badge-partial { background: #fff3cd; color: #856404; }
.badge-partial-overdue { background: #f8d7da; color: var(--burgundy); }

/* ── Buttons ── */
.btn {
    display: inline-block;
    padding: 0.55rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.2s;
}

.btn:hover { opacity: 0.85; }

.btn-primary {
    background: var(--mustard);
    color: var(--white);
}

.btn-secondary {
    background: var(--black);
    color: var(--white);
}

.btn-burgundy {
    background: var(--burgundy);
    color: var(--white);
}

.btn-small {
    padding: 0.3rem 0.7rem;
    font-size: 0.78rem;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--grey-mid);
    color: var(--grey-dark);
}

.btn-outline:hover {
    border-color: var(--mustard);
    color: var(--mustard);
}

/* ── Forms ── */
.form-card {
    background: var(--white);
    border-radius: 8px;
    padding: 2rem;
    border: 1px solid var(--grey-mid);
    max-width: 700px;
}

.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--grey-dark);
    margin-bottom: 0.4rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--grey-mid);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--white);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--mustard);
    box-shadow: 0 0 0 2px rgba(184, 137, 42, 0.15);
}

.form-group textarea { min-height: 80px; resize: vertical; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
    accent-color: var(--mustard);
}

/* ── Filter tabs ── */
.filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.filter-tabs a {
    padding: 0.45rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--grey-dark);
    background: var(--white);
    border: 1px solid var(--grey-mid);
    transition: all 0.2s;
}

.filter-tabs a:hover { border-color: var(--mustard); color: var(--mustard); }

.filter-tabs a.active {
    background: var(--mustard);
    color: var(--white);
    border-color: var(--mustard);
}

.client-filter {
    margin-left: auto;
    padding: 0.45rem 0.8rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--grey-dark);
    background: var(--white);
    border: 1px solid var(--grey-mid);
    cursor: pointer;
    font-family: inherit;
}

.client-filter:focus {
    outline: none;
    border-color: var(--mustard);
}

/* ── Actions cell ── */
.actions { white-space: nowrap; }
.actions a, .actions form { display: inline-block; }
.actions form { margin: 0; }

/* ── Batch preview ── */
.batch-client {
    background: var(--white);
    border: 1px solid var(--grey-mid);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.batch-client h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--black);
}

.batch-client .checkbox-group { margin-bottom: 0.75rem; }

/* ── Sortable headers ── */
th.sortable a {
    color: var(--mustard);
    text-decoration: none;
    display: block;
}

th.sortable a:hover {
    text-decoration: underline;
}

/* ── Currency toggle ── */
.toggle-currency {
    margin-left: 0.5rem;
    vertical-align: middle;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
}

/* ── Partial payment input ── */
.paid-cell { min-width: 130px; }

.partial-form {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
}

.partial-input {
    width: 80px;
    padding: 2px 6px;
    border: 1px solid var(--grey-mid);
    border-radius: 4px;
    font-size: 0.78rem;
    font-family: inherit;
}

.partial-input:focus {
    outline: none;
    border-color: var(--mustard);
}

/* ── Month groups (tracking) ── */
.month-group {
    margin-bottom: 2rem;
}

.month-header {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--black);
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--mustard);
}

.month-count {
    font-weight: 400;
    color: var(--grey-dark);
    font-size: 0.9rem;
}

/* ── Utility ── */
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.text-right { text-align: right; }
.text-muted { color: var(--grey-dark); font-size: 0.82rem; }

/* ── Mobile top bar (hidden on desktop) ── */
.topbar { display: none; }
.sidebar-overlay { display: none; }

/* ──────────────────────────────────────────────────────────────────────────
   Responsive: phones & small tablets
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    body:not(.login-body) { display: block; }

    /* Fixed top bar with hamburger */
    .topbar {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        position: fixed;
        top: 0; left: 0; right: 0;
        height: calc(56px + env(safe-area-inset-top));
        padding: 0 1rem;
        padding-top: env(safe-area-inset-top);
        background: var(--black);
        border-bottom: 2px solid var(--mustard);
        z-index: 1000;
    }

    .hamburger {
        background: none;
        border: none;
        color: var(--mustard);
        font-size: 1.5rem;
        line-height: 1;
        cursor: pointer;
        padding: 0.25rem 0.5rem;
    }

    .topbar-logo { height: 26px; width: auto; }

    /* Sidebar slides in from the left as an off-canvas drawer */
    .sidebar {
        width: 260px;
        z-index: 1002;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        padding-top: calc(2rem + env(safe-area-inset-top));
    }

    body.sidebar-open .sidebar { transform: translateX(0); }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1001;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    /* Content sits below the top bar, full width */
    .content {
        margin-left: 0;
        max-width: 100%;
        padding: calc(56px + env(safe-area-inset-top) + 1rem) 1rem 1.5rem;
    }

    h1 { font-size: 1.35rem; }

    /* Stats stack into a single column */
    .stats-row { grid-template-columns: 1fr; }

    /* Form two-column rows collapse */
    .form-row { grid-template-columns: 1fr; }
    .form-card { padding: 1.25rem; }

    /* Wide tables scroll horizontally instead of overflowing the screen */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    /* Filter tabs wrap; client dropdown drops to its own row */
    .filter-tabs { flex-wrap: wrap; }
    .client-filter { margin-left: 0; width: 100%; }

    /* Larger tap targets for buttons in tables */
    .btn-small { padding: 0.4rem 0.7rem; }
}
