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

:root {
    --navy: #101827;
    --ink: #1b273b;
    --muted: #7e8a9d;
    --line: #e8edf3;
    --bg: #f4f6fa;
    --blue: #4169e1;
    --red: #d94c55;
    --amber: #c98519;
    --green: #16845b
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px 'DM Sans', sans-serif
}

.hidden {
    display: none !important
}

.layout {
    display: flex;
    min-height: 100vh
}

.sidebar {
    width: 245px;
    background: var(--navy);
    color: white;
    padding: 25px 17px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 7px 35px
}

.brand b,
.brand small {
    display: block
}

.brand small {
    color: #93a0b5;
    font-size: 11px;
    margin-top: 3px
}

.logo {
    width: 39px;
    height: 39px;
    background: var(--blue);
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-weight: 800;
    color: white
}

.sidebar nav {
    display: grid;
    gap: 7px
}

.nav {
    border: 0;
    background: none;
    color: #9eabc0;
    text-align: left;
    padding: 13px;
    border-radius: 8px;
    font: 600 13px 'DM Sans';
    cursor: pointer
}

.nav.active,
.nav:hover {
    background: #263650;
    color: white
}

.side-bottom {
    margin-top: auto;
    color: #9eabc0;
    font-size: 11px;
    display: grid;
    gap: 14px;
    padding: 10px
}

.logout {
    background: none;
    border: 1px solid #40506a;
    color: white;
    padding: 9px;
    border-radius: 7px;
    cursor: pointer
}

.main {
    width: calc(100% - 245px);
    padding: 29px 36px;
    max-width: 1600px;
    margin: auto
}

.top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px
}

.top small {
    font-size: 10px;
    color: #8b97a9;
    letter-spacing: 1.5px;
    font-weight: 800
}

.top h1 {
    font-size: 25px;
    margin: 5px 0
}

.top-buttons,
.tools {
    display: flex;
    gap: 9px;
    align-items: center
}

.primary,
.secondary {
    border: 0;
    border-radius: 8px;
    padding: 11px 15px;
    font: 700 12px 'DM Sans';
    cursor: pointer
}

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

.secondary {
    background: white;
    border: 1px solid var(--line);
    color: #344158
}

.view {
    display: block
}

.hero {
    background: linear-gradient(110deg, #243e77, #4169d9);
    color: white;
    border-radius: 14px;
    padding: 24px 28px;
    margin-bottom: 16px
}

.hero small {
    font-size: 10px;
    letter-spacing: 1.5px;
    color: #c8d6ff
}

.hero h2 {
    font-size: 22px;
    margin: 8px 0
}

.hero p {
    margin: 0;
    color: #dce5ff;
    font-size: 12px
}

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

.stats article,
.panel {
    background: white;
    border: 1px solid var(--line);
    border-radius: 11px
}

.stats article {
    padding: 17px
}

.stats span {
    display: block;
    color: #69768a;
    font-size: 11px
}

.stats b {
    display: block;
    font-size: 28px;
    margin-top: 8px
}

.stats .red b {
    color: var(--red)
}

.stats .amber b {
    color: var(--amber)
}

.panel {
    padding: 18px;
    margin-bottom: 15px
}

.panel h3 {
    font-size: 14px;
    margin: 0 0 13px
}

.panel-head,
.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px
}

.panel-head h3,
.section-head h2 {
    margin: 0 0 4px
}

.panel-head p,
.section-head p {
    font-size: 11px;
    color: var(--muted);
    margin: 0
}

.link {
    border: 0;
    background: none;
    color: var(--blue);
    font: 700 11px 'DM Sans';
    cursor: pointer
}

.section-head h2 {
    font-size: 19px
}

.section-head .tools input,
.section-head select {
    min-width: 190px
}

.tools input,
.tools select,
.form input {
    border: 1px solid #e1e6ee;
    border-radius: 8px;
    padding: 10px;
    font: 12px 'DM Sans';
    background: white;
    outline: none
}

.table-wrap {
    overflow: auto
}

.panel.table-wrap {
    padding: 0
}

table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap
}

th {
    background: #fafbfd;
    color: #8994a5;
    font-size: 10px;
    text-transform: uppercase;
    text-align: left;
    padding: 13px
}

td {
    padding: 13px;
    border-top: 1px solid #eff2f6;
    font-size: 11px;
    color: #526076
}

td strong {
    color: #202d42
}

.empty {
    text-align: center;
    color: #9aa4b4;
    padding: 25px
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px
}

.scanbox {
    height: 220px;
    border-radius: 9px;
    background: #111b2b;
    color: #9caac0;
    display: grid;
    place-items: center;
    margin: 12px 0
}

.scan-input {
    margin-top: 15px
}

.scan-input input {
    flex: 1;
    min-width: 0
}

.muted {
    font-size: 10px;
    color: var(--muted);
    line-height: 1.6
}

.picked {
    background: #f4f6fa;
    border-radius: 8px;
    padding: 13px;
    font-size: 11px;
    color: #788499;
    margin: 12px 0
}

.picked b {
    display: block;
    color: #25334a;
    font-size: 14px;
    margin-bottom: 4px
}

.form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 11px
}

.form label {
    display: grid;
    gap: 6px;
    font-size: 10px;
    font-weight: 700;
    color: #66748a
}

.form input {
    width: 100%;
    min-width: 0
}

.wide {
    grid-column: 1/-1
}

.form button:disabled {
    opacity: .45;
    cursor: not-allowed
}

.modal {
    position: fixed;
    inset: 0;
    background: #11182799;
    display: grid;
    place-items: center;
    padding: 15px;
    z-index: 30
}

.modal-card {
    background: white;
    width: min(560px, 100%);
    border-radius: 14px;
    padding: 23px;
    box-shadow: 0 20px 60px #0003
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 18px
}

.modal-head h2 {
    font-size: 19px;
    margin: 0 0 5px
}

.modal-head p {
    font-size: 11px;
    color: var(--muted);
    margin: 0
}

.x {
    border: 0;
    background: #f0f2f6;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 20px;
    cursor: pointer
}

.pill {
    display: inline-block;
    padding: 5px 8px;
    border-radius: 20px;
    font-size: 9px;
    font-weight: 800
}

.expired {
    background: #fff0f0;
    color: #c43c47
}

.near {
    background: #fff5e5;
    color: #ad6c0c
}

.safe {
    background: #e8f7f0;
    color: #16845b
}

.action {
    border: 0;
    background: none;
    color: var(--blue);
    cursor: pointer;
    font: 700 11px 'DM Sans'
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(130deg, #101827, #263e70)
}

.login-card {
    background: white;
    border-radius: 15px;
    padding: 32px;
    width: min(390px, 100%);
    display: grid;
    gap: 13px
}

.login-card .logo {
    margin-bottom: 3px
}

.login-card h1 {
    font-size: 20px;
    margin: 0
}

.login-card p {
    font-size: 11px;
    color: var(--muted);
    margin: 0 0 8px
}

.login-card label {
    display: grid;
    gap: 6px;
    font-size: 11px;
    font-weight: 700
}

.login-card input {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px
}

.error {
    color: var(--red);
    font-size: 11px
}

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #17243a;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 12px;
    z-index: 50
}

@media(max-width:900px) {
    .stats {
        grid-template-columns: repeat(2, 1fr)
    }

    .main {
        padding: 22px
    }

    .sidebar {
        width: 205px
    }

    .main {
        width: calc(100% - 205px)
    }
}

@media(max-width:650px) {
    .layout {
        display: block
    }

    .sidebar {
        width: 100%;
        padding: 12px;
        position: sticky;
        top: 0;
        z-index: 10
    }

    .brand {
        padding: 0 5px 10px
    }

    .sidebar nav {
        display: flex;
        overflow: auto
    }

    .nav {
        white-space: nowrap;
        padding: 9px;
        font-size: 11px
    }

    .side-bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 4px 0
    }

    .main {
        width: 100%;
        padding: 17px 13px
    }

    .top {
        margin-bottom: 17px
    }

    .top h1 {
        font-size: 21px
    }

    .top-buttons .secondary {
        display: none
    }

    .stats {
        gap: 8px
    }

    .stats article {
        padding: 13px
    }

    .stats b {
        font-size: 24px
    }

    .two-col {
        grid-template-columns: 1fr
    }

    .section-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px
    }

    .section-head .tools {
        width: 100%;
        flex-wrap: wrap
    }

    .section-head .tools input {
        flex: 1;
        min-width: 125px
    }

    .form {
        gap: 9px
    }

    .hero {
        padding: 20px
    }

    .hero h2 {
        font-size: 19px
    }
}

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #10182766;
    display: grid;
    place-items: center;
    cursor: wait
}

.loading-card {
    background: white;
    color: var(--ink);
    border-radius: 14px;
    padding: 25px 32px;
    display: grid;
    justify-items: center;
    gap: 15px;
    box-shadow: 0 12px 45px #0003
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e8edf3;
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: expira-spin .8s linear infinite
}

@keyframes expira-spin {
    to {
        transform: rotate(360deg)
    }
}

@media(prefers-reduced-motion:reduce) {
    .loading-spinner {
        animation-duration: 2s
    }
}

.stock-expired {
    color: #b91c1c
}

.stock-damaged {
    color: #b45309
}

.stock-available {
    color: #15803d;
    font-weight: 700
}

#userRows form {
    padding: 16px
}

#stockSummary {
    margin-top: 12px
}

select {
    font: inherit;
    border: 1px solid #dce1e8;
    border-radius: 8px;
    padding: 10px;
    background: white;
    color: #172033;
    max-width: 100%;
    min-height: 38px
}

dialog {
    border: 0;
    border-radius: 14px;
    padding: 24px;
    width: min(520px, 90vw);
    box-shadow: 0 12px 50px #0004
}

dialog::backdrop {
    background: #10182788
}

.lookup-results {
    display: grid;
    gap: 3px
}

.lookup-results button {
    text-align: left;
    padding: 10px;
    border: 1px solid #dce1e8;
    background: white;
    border-radius: 6px;
    cursor: pointer
}

#notice {
    z-index: 9999
}

.modal-card {
    max-height: 90vh;
    overflow: auto
}

#userSearch,
#historySearch,
#damageHistorySearch {
    margin: 12px 0
}

/* Inventory dashboard and batch details */
.stock-chart-group {
    padding: 16px 0;
    border-bottom: 1px solid #e6e9f1
}

.stock-chart-group:last-child {
    border: 0
}

.stock-chart-layout {
    display: grid;
    grid-template-columns: 180px minmax(130px, 1fr) minmax(180px, 1.5fr);
    gap: 24px;
    align-items: center;
    padding: 16px 0
}

.donut {
    width: 170px;
    height: 170px;
    border-radius: 50%;
    display: grid;
    place-items: center
}

.donut>div {
    width: 126px;
    height: 126px;
    border-radius: 50%;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center
}

.donut strong {
    font-size: 25px
}

.donut small {
    color: #68768a
}

.chart-legend>div {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0
}

.chart-legend i {
    width: 10px;
    height: 10px;
    border-radius: 3px
}

.chart-legend strong {
    margin-left: auto
}

.bar-label {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    margin-top: 12px
}

.bar-track {
    height: 7px;
    background: #e8edf5;
    border-radius: 5px;
    overflow: hidden;
    margin-top: 5px
}

.bar-track>div {
    height: 100%;
    background: #405fd0;
    border-radius: 5px
}

.batch-dialog {
    width: min(960px, 94vw);
    max-width: 94vw
}

.danger-action {
    color: #b42335 !important
}

.toast.hidden {
    display: none
}

.stats article {
    border-top: 3px solid #405fd0
}

.stats article.red {
    border-top-color: #dc5260
}

.stats article.amber {
    border-top-color: #e7a323
}

@media(max-width:950px) {
    .stock-chart-layout {
        grid-template-columns: 170px 1fr
    }

    .top-stock {
        grid-column: 1/-1
    }
}

@media(max-width:500px) {
    .stock-chart-layout {
        grid-template-columns: 1fr
    }

    .donut {
        margin: auto
    }

    .top-stock {
        grid-column: auto
    }
}

/* Mobile and installed PWA layout */
.main,
.panel,
.two-col>* {
    min-width: 0
}

.scanbox {
    overflow: hidden
}

.scanbox video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    min-height: 0
}

.table-wrap {
    max-width: 100%;
    -webkit-overflow-scrolling: touch
}

.form label {
    min-width: 0
}

.form select {
    width: 100%;
    min-width: 0
}

.toast {
    bottom: calc(20px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 32px)
}

@media(max-width:650px) {
    .sidebar {
        padding-top: calc(12px + env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .main {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }

    .login-screen {
        min-height: 100dvh;
        padding-top: max(20px, env(safe-area-inset-top));
    }

    input,
    select,
    textarea,
    .tools input,
    .tools select,
    .form input {
        font-size: 16px !important;
    }

    .nav,
    .primary,
    .secondary,
    .action,
    .x {
        min-height: 44px;
    }

    .action {
        padding: 8px;
    }

    .x {
        min-width: 44px;
    }

    .top,
    .tools,
    .panel-head {
        flex-wrap: wrap;
    }

    .panel,
    .stats article {
        min-width: 0;
    }

    .modal-card,
    dialog {
        max-height: 85dvh;
        overflow: auto;
    }

    .modal-card {
        padding: 16px;
    }

    .form {
        grid-template-columns: minmax(0, 1fr);
    }

    .scanbox {
        height: 240px;
    }

    .stock-chart-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .donut {
        margin: auto;
    }

    .top-stock {
        grid-column: auto;
    }
}