/* PMS admin shell. Deliberately plain: this is a back-office tool that runs on
   whatever machine is behind the counter, so it prioritises legibility and
   keyboard use over decoration. Bump ?v= in index.html on every edit. */

:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --ink: #16202a;
    --muted: #63727f;
    --line: #dfe5ea;
    --accent: #1668b3;
    --accent-ink: #ffffff;
    --warn-bg: #fff5e0;
    --warn-line: #e6c164;
    --error: #b3261e;
    --ok: #17694a;
}

* { box-sizing: border-box; }

/* The browser's own [hidden] rule is `display: none`, but ANY author rule that
   sets display beats it — author styles always win over the UA stylesheet,
   specificity notwithstanding. Both .login-wrap and .modal-backdrop set
   display:flex, so `hidden` silently stopped hiding them: the login form
   rendered above the app shell while signed in, and a closed modal kept
   showing. This restores `hidden` to meaning hidden, for every element. */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 19px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 26px 0 8px; }

.muted { color: var(--muted); }
.error { color: var(--error); }
code {
    background: #eef1f4;
    padding: 1px 5px;
    border-radius: 3px;
    font: 13px/1.4 Consolas, "Courier New", monospace;
}

/* --- Login --------------------------------------------------------------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card { width: 100%; max-width: 360px; }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
}
label {
    display: block;
    margin: 14px 0 4px;
    font-size: 13px;
    font-weight: 600;
}
input {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    font: inherit;
    background: #fff;
    color: var(--ink);
}
input:focus, button:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
button {
    margin-top: 18px;
    padding: 9px 16px;
    border: 0;
    border-radius: 5px;
    background: var(--accent);
    color: var(--accent-ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
button:disabled { opacity: .55; cursor: default; }
button.ghost {
    margin: 0;
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
    font-weight: 500;
}

/* --- Shell --------------------------------------------------------------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.spacer { flex: 1; }
.whoami { text-align: right; line-height: 1.2; }
.role-chip {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 10px;
    background: #e7eef6;
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
}

.layout { display: flex; align-items: flex-start; }
.sidenav {
    width: 210px;
    flex: none;
    padding: 14px 10px;
    border-right: 1px solid var(--line);
    background: var(--panel);
    min-height: calc(100vh - 47px);
}
.nav-item {
    display: block;
    width: 100%;
    margin: 0 0 2px;
    padding: 8px 10px;
    text-align: left;
    background: transparent;
    color: var(--ink);
    font-weight: 500;
    border-radius: 5px;
}
.nav-item:hover { background: #eef2f6; }
.nav-item.active { background: var(--accent); color: var(--accent-ink); }
.nav-note {
    margin-top: 18px;
    padding: 10px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

/* min-width:0 lets this flex child actually shrink. Without it a flex item
   refuses to go below its content width and pushes the page sideways. */
.content { flex: 1; min-width: 0; padding: 22px 26px; max-width: 1100px; }

/* The back office is a desktop tool, but it should not break if someone docks
   the window to half a screen. */
@media (max-width: 820px) {
    .layout { flex-direction: column; }
    .sidenav {
        width: 100%;
        min-height: 0;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
    .content { padding: 16px; }
}

/* --- Bits ---------------------------------------------------------------- */
.banner {
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 16px;
}
.banner.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 8px;
}
.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px 14px;
}
.stat .n { font-size: 22px; font-weight: 700; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    font: 12px/1.6 Consolas, monospace;
}

/* A wide table scrolls inside its own box. Without this the payables and
   purchase-history tables push the whole page sideways on a narrow window. */
.table-scroll {
    overflow-x: auto;
    max-width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
}
th, td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    vertical-align: top;
}
th {
    background: #eef2f6;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
tr:last-child td { border-bottom: 0; }
td.mono { font-family: Consolas, monospace; font-size: 12px; }

.pill { padding: 1px 7px; border-radius: 9px; font-size: 11px; font-weight: 600; }
.pill.yes { background: #e2f2ea; color: var(--ok); }
.pill.no  { background: #fbe6e5; color: var(--error); }
.pill.warn { background: var(--warn-bg); color: #8a6100; }
.pill.rx  { background: #ede4f7; color: #5b3a8e; }
.pill.device { background: #e5eefb; color: var(--accent); }

/* Clickable product-type filter chips above the products list. */
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.filter-chips .chip { cursor: pointer; padding: 4px 12px; color: var(--ink); background: var(--panel); font: 12px/1.4 "Segoe UI", system-ui, sans-serif; user-select: none; }
.filter-chips .chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chips .chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --- Phase 2: inventory -------------------------------------------------- */
.nav-group {
    margin: 14px 0 4px;
    padding: 0 10px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.view-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.view-head h2 { margin: 0; }
.view-head button { margin: 0; }

.toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-bottom: 12px;
}
.toolbar input[type="text"], .toolbar input:not([type]) { max-width: 420px; }
label.inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-weight: 500;
    white-space: nowrap;
}
label.inline input { width: auto; }

button.danger { background: var(--error); }
button.small {
    margin: 0;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 500;
}
button.link {
    margin: 0;
    padding: 0;
    background: none;
    color: var(--accent);
    font-weight: 600;
    text-align: left;
    text-decoration: underline;
    cursor: pointer;
}

/* Expiry bucket cards: red for already-expired, amber for the near ones.
   The colour is doing real work here -- this is the screen that saves money. */
.stat.bucket { border-left: 4px solid var(--line); }
.stat.bucket.expired { border-left-color: var(--error); }
.stat.bucket.d30 { border-left-color: #e08a00; }
.stat.bucket.d60 { border-left-color: var(--warn-line); }
.stat.bucket.d90 { border-left-color: #9bb7cf; }
.stat.bucket.active { background: #eef2f6; }
.stat.bucket { cursor: pointer; }
.stat .sub { color: var(--muted); font-size: 12px; }

tr.row-expired td { background: #fdf0ef; }
tr.row-warn td { background: #fffaf0; }

/* --- Print (spec 5.6: PDF for the reports that get filed) ----------------
   No PDF library and no build step (spec 3): the accountant prints the report
   to PDF from the browser. This hides everything but the report body and adds
   a header, so a filed Sales Book or VAT worksheet looks like a document, not a
   screenshot of an app. */
.print-header { display: none; }
@media print {
    .topbar, .sidenav, .toolbar, .modal-backdrop, .nav-note { display: none !important; }
    .layout, .content { display: block; margin: 0; padding: 0; max-width: none; }
    .view { display: block !important; }
    .view:not(.printing) { display: none !important; }
    .print-header { display: block; margin-bottom: 12px; }
    .print-header h1 { font-size: 18px; margin: 0; }
    .print-header .meta { color: #444; font-size: 12px; }
    body { background: #fff; }
    table { border: 1px solid #999; font-size: 11px; }
    th, td { border-bottom: 1px solid #ccc; }
    .table-scroll { overflow: visible; }
    a[href]:after { content: ''; }
    button { display: none !important; }
}

/* --- Modal --------------------------------------------------------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16, 32, 42, .45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
    z-index: 50;
}
.modal {
    background: var(--panel);
    border-radius: 8px;
    width: 100%;
    max-width: 720px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { font-size: 20px; line-height: 1; padding: 2px 9px; }
.modal-body { padding: 18px; }
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    background: #fafbfc;
    border-radius: 0 0 8px 8px;
}
.modal-foot button { margin: 0; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { margin-top: 10px; }
.form-hint { color: var(--muted); font-size: 12px; margin: 3px 0 0; }
.check-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 12px;
}
fieldset {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 14px 14px;
    margin: 18px 0 0;
}
legend { padding: 0 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
