:root {
    --brand: #cf1518;
    --brand-dark: #9e1013;
    --ink: #18202a;
    --muted: #687385;
    --line: #dfe4ea;
    --panel: #ffffff;
    --page: #f2f4f7;
    --sidebar: #151922;
    --good: #087a4a;
    --warn: #a35400;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
}

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

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 18px;
    width: 238px;
    height: 100vh;
    padding: 18px 14px;
    background: var(--sidebar);
    border-right: 1px solid #2b313d;
    box-shadow: 12px 0 32px rgba(15,21,31,.08);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand img {
    width: 172px;
    max-width: 100%;
    height: auto;
    display: block;
    filter: brightness(0) invert(1);
}

.nav {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 8px;
}

.nav a,
.btn,
button,
input[type=submit] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--ink);
    font-weight: 700;
    cursor: pointer;
}

.nav a {
    justify-content: flex-start;
    border-color: transparent;
    background: rgba(255,255,255,.06);
    color: #f7f8fb;
}

.nav a:hover {
    background: rgba(207,21,24,.18);
    border-color: rgba(207,21,24,.35);
}

.btn.primary,
input.primary,
button.primary {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.btn.ghost {
    background: transparent;
}

.container {
    width: calc(100% - 238px);
    max-width: 1280px;
    margin: 0 0 0 238px;
    padding: 24px 18px 38px;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(360px, .75fr);
    align-items: stretch;
    padding: 0;
    background:
        radial-gradient(circle at 12% 18%, rgba(207,21,24,.16), transparent 28%),
        linear-gradient(135deg, #111722 0%, #222a35 52%, #f6f7f9 52%, #f6f7f9 100%);
}

.login-box {
    width: min(440px, calc(100% - 32px));
    align-self: center;
    justify-self: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 24px 70px rgba(24,32,42,.18);
}

.login-logo {
    width: 230px;
    max-width: 90%;
    display: block;
    margin-bottom: 20px;
}

.login-hero {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 22px;
    min-height: 100vh;
    padding: 52px;
    color: #fff;
}

.login-hero h1 {
    max-width: 620px;
    font-size: 42px;
}

.login-hero p {
    max-width: 560px;
    margin: 0;
    color: #d8dde7;
    font-size: 18px;
    line-height: 1.6;
}

.login-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    max-width: 620px;
}

.login-stat {
    padding: 14px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 8px;
    background: rgba(255,255,255,.08);
}

.login-stat b {
    display: block;
    font-size: 24px;
    margin-bottom: 4px;
}

.login-subtitle {
    margin: 6px 0 18px;
    color: var(--muted);
    line-height: 1.5;
}

.panel,
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 14px;
}

.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.col-6 { grid-column: span 6; }
.col-8 { grid-column: span 8; }
.col-12 { grid-column: span 12; }

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.item-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.item-row:last-child {
    border-bottom: 0;
}

label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input[type=text],
input[type=password],
input[type=email],
input[type=date],
input[type=number],
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

.customer-search-box {
    margin-bottom: 8px;
}

.table-search-panel {
    margin-bottom: 14px;
}

.customer-search-box::placeholder {
    color: #8b95a4;
}

textarea {
    min-height: 84px;
    resize: vertical;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.2;
}

h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

.metric {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.metric b {
    font-size: 26px;
}

.balance-good {
    color: var(--good);
}

.balance-due {
    color: var(--brand);
}

.summary-link {
    color: var(--ink);
}

.summary-link:hover {
    border-color: var(--brand);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

th, td {
    padding: 11px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.notice {
    margin: 10px 0;
    padding: 10px 12px;
    border-radius: 7px;
    background: #eef7f2;
    color: var(--good);
    font-weight: 700;
}

.error {
    background: #fff0f0;
    color: #ad1919;
}

.invoice {
    background: #fff;
    color: #111;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.invoice-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 2px solid #111;
    padding-bottom: 16px;
    margin-bottom: 18px;
}

.invoice-logo {
    width: 190px;
}

.total-box {
    margin-left: auto;
    width: min(360px, 100%);
}

.total-line {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
}

.total-line.grand {
    font-size: 20px;
    font-weight: 800;
    border-bottom: 0;
}

@media (max-width: 760px) {
    .topbar {
        position: sticky;
        width: 100%;
        height: auto;
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
        padding: 14px;
        border-right: 0;
        border-bottom: 1px solid #2b313d;
        box-shadow: 0 10px 26px rgba(15,21,31,.12);
    }

    .brand {
        justify-content: center;
    }

    .brand img {
        width: 168px;
    }

    .nav {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        overflow: visible;
    }

    .nav a,
    .nav .btn {
        justify-content: center;
        min-height: 44px;
        padding: 9px 8px;
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .container {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 12px 10px 28px;
    }

    .panel,
    .card {
        padding: 14px;
    }

    .item-row {
        display: block;
        padding: 14px;
        margin-bottom: 12px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: #fbfcfe;
    }

    .item-row .field {
        margin-bottom: 12px;
    }

    .item-row .field:last-child {
        margin-bottom: 0;
    }

    .login-shell {
        grid-template-columns: 1fr;
        background:
            linear-gradient(180deg, rgba(17,23,34,.94) 0%, rgba(17,23,34,.72) 34%, #f6f7f9 34%, #f6f7f9 100%);
    }

    .login-hero {
        min-height: auto;
        padding: 30px 22px 18px;
    }

    .login-hero h1 {
        font-size: 30px;
    }

    .login-hero p {
        font-size: 15px;
    }

    .login-stats {
        grid-template-columns: 1fr;
    }

    .login-box {
        margin: 12px 0 28px;
    }

    .col-3,
    .col-4,
    .col-6,
    .col-8,
    .col-2 {
        grid-column: span 12;
    }

    .title-row,
    .invoice-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .actions .btn,
    .actions input,
    .actions button {
        flex: 1 1 150px;
    }

    table {
        min-width: 620px;
    }
}

@media (min-width: 430px) and (max-width: 760px) {
    .nav {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media print {
    body {
        background: #fff;
    }

    .topbar,
    .no-print,
    .actions {
        display: none !important;
    }

    .container {
        width: 100%;
        padding: 0;
    }

    .invoice {
        border: 0;
        border-radius: 0;
    }
}
