@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@600;700&display=swap');

:root {
    --navy: #0b1f36;
    --navy-soft: #123456;
    --bg: #f5f7fb;
    --text: #182230;
    --muted: #667085;
    --line: #d0d5dd;
    --green: #138a4b;
    --red: #c43d3d;
    --white: #ffffff;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}
h1, h2, h3 { font-family: Outfit, Inter, sans-serif; margin: 0 0 14px; }
a { color: inherit; }
.app { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar {
    background: var(--navy);
    color: var(--white);
    padding: 24px 18px;
}
.brand { font-family: Outfit, sans-serif; font-size: 22px; font-weight: 700; margin-bottom: 30px; }
.mobile-header { display: none; }
.menu-toggle { display: none; }
.nav a {
    display: block;
    padding: 12px 14px;
    border-radius: 8px;
    text-decoration: none;
    margin-bottom: 6px;
    color: #e8eef6;
}
.nav a:hover { background: var(--navy-soft); }
.content { padding: 28px; overflow-x: hidden; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 22px; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.tile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.tile {
    display: block;
    min-height: 150px;
    padding: 22px;
    border-radius: 8px;
    background: var(--white);
    border: 1px solid #eaecf0;
    box-shadow: 0 1px 3px rgba(16, 24, 40, .06);
    text-decoration: none;
}
.tile span {
    display: block;
    color: var(--muted);
    font-weight: 700;
    margin-top: 12px;
}
.tile strong {
    display: block;
    font-family: Outfit, Inter, sans-serif;
    font-size: 24px;
    line-height: 1.15;
}
.tile:hover { border-color: var(--navy); }
.card {
    background: var(--white);
    border: 1px solid #eaecf0;
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 1px 3px rgba(16, 24, 40, .06);
}
.stat { font-size: 32px; font-weight: 700; margin-top: 8px; }
.muted { color: var(--muted); }
.btn, button {
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    background: var(--navy);
    color: var(--white);
    text-decoration: none;
    display: inline-block;
}
.btn.secondary { background: #e8eef6; color: var(--navy); }
.btn.green, button.green { background: var(--green); }
.btn.red, button.red { background: var(--red); }
.btn.small, button.small { padding: 7px 10px; font-size: 13px; }
form { margin: 0; }
label { display: block; font-weight: 700; margin: 12px 0 6px; }
input, textarea, select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    background: var(--white);
}
textarea { min-height: 88px; resize: vertical; }
.inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.inline > * { flex: 1 1 180px; }
.inline-search {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;
}
.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: start;
}
.contact-row {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fafb;
    margin-bottom: 12px;
}
.typeahead-results {
    margin-top: 12px;
}
.customer-result {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    text-decoration: none;
}
.customer-result:hover {
    border-color: var(--navy);
    background: #e8eef6;
}
.customer-result span {
    color: var(--muted);
    font-weight: 700;
}
.product-control {
    display: grid;
    gap: 16px;
}
.product-panel {
    display: grid;
    gap: 14px;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--white); }
th, td { padding: 12px; border-bottom: 1px solid #eaecf0; text-align: left; vertical-align: top; }
th { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0; }
.pill { display: inline-block; padding: 4px 8px; border-radius: 8px; font-weight: 700; font-size: 12px; background: #e8eef6; }
.positive { color: var(--green); font-weight: 700; }
.negative { color: var(--red); font-weight: 700; }
.balance-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}
.balance-chip {
    display: grid;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid var(--line);
}
.balance-chip span {
    font-weight: 800;
}
.balance-chip small {
    color: var(--muted);
    font-weight: 700;
}
.balance-warning {
    background: #fff4cc;
    color: #8a5a00;
    border-color: #f2c94c;
}
.credit-control {
    display: grid;
    gap: 14px;
}
.action-radios {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.action-radios label {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #e8eef6;
    color: var(--navy);
    cursor: pointer;
}
.action-radios input {
    width: auto;
    margin-right: 6px;
}
.action-radios label:has(input:checked) {
    background: var(--navy);
    color: var(--white);
    border-color: var(--navy);
}
.action-panel {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fafb;
}
.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    background: var(--navy);
    color: white;
    padding: 13px 16px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
    z-index: 10;
}
.qr-code {
    width: 220px;
    max-width: 100%;
    height: auto;
    display: block;
    margin: 12px 0;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.code-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}
.code-grid code {
    display: block;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    font-weight: 800;
    text-align: center;
}
.hidden { display: none !important; }
.spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 3px solid #cfd8e3;
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--navy); }
.login-card { width: min(440px, 100%); background: white; border-radius: 8px; padding: 28px; }
.empty { padding: 22px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); background: #fff; }
.alert {
    padding: 13px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 700;
}
.alert.error {
    color: #9f1f1f;
    background: #fff1f1;
    border: 1px solid #f3b7b7;
}
details { margin: 10px 0; }
summary { cursor: pointer; font-weight: 700; padding: 8px 0; }
.mobile-stack { display: grid; gap: 12px; }
.pagination {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 14px;
}

@media (max-width: 860px) {
    body { padding-top: 64px; }
    .app { display: block; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 20;
        min-height: 64px;
        padding: 0;
        box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
    }
    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 64px;
        padding: 12px 16px;
        background: var(--navy);
    }
    .mobile-header .brand {
        margin: 0;
        line-height: 1.1;
    }
    .desktop-brand { display: none; }
    .menu-toggle {
        display: inline-grid;
        place-items: center;
        gap: 4px;
        width: 44px;
        height: 44px;
        padding: 0;
        background: #e8eef6;
        color: var(--navy);
        border-radius: 8px;
    }
    .menu-toggle span {
        display: block;
        width: 22px;
        height: 2px;
        background: var(--navy);
        border-radius: 2px;
    }
    .nav {
        position: fixed;
        top: 64px;
        right: 0;
        bottom: 0;
        width: min(320px, 86vw);
        display: block;
        padding: 16px;
        background: var(--navy);
        transform: translateX(100%);
        transition: transform .2s ease;
        overflow-y: auto;
    }
    body.menu-open .nav { transform: translateX(0); }
    body.menu-open::after {
        content: "";
        position: fixed;
        inset: 64px 0 0 0;
        background: rgba(12, 24, 38, .46);
        z-index: 10;
    }
    .nav a {
        display: block;
        margin-bottom: 8px;
        padding: 14px;
        font-size: 16px;
    }
    .content { padding: 18px; }
    .grid, .two, .tile-grid { grid-template-columns: 1fr; }
    .topbar { display: block; }
    .inline-search { grid-template-columns: 1fr; }
    .section-heading { display: grid; }
    .customer-result { display: grid; }
    th, td { padding: 10px; }
}
