/* ===========================================================================
   BulkTracker — interface styles

   Design brief: tight and dense. Staff are at a counter with a patient in
   front of them; everything they need should be on one screen without
   scrolling, and nothing should feel like an enterprise system.

   Base font is 13.5px and spacing steps are 4px. That is deliberately
   smaller than a typical web app — it is what lets a full stock list and a
   dispensing form share one view.
   =========================================================================== */

:root {
    /* Surfaces */
    --bg:            #f4f6f8;
    --surface:       #ffffff;
    --surface-alt:   #fafbfc;
    --border:        #dde2e8;
    --border-strong: #c3ccd6;

    /* Text */
    --text:    #1c2530;
    --muted:   #667180;
    --faint:   #8d97a4;

    /* Accents */
    --primary:      #0b6bcb;
    --primary-dark: #075aad;
    --primary-soft: #e8f1fc;

    --success:      #0f7b3f;
    --success-soft: #e6f4ec;
    --warning:      #9a6400;
    --warning-soft: #fdf3e0;
    --danger:       #c02626;
    --danger-soft:  #fdecec;

    /* Topbar */
    --topbar:      #1b2733;
    --topbar-soft: #2a3947;

    /* Spacing scale */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;

    --radius:    5px;
    --radius-sm: 3px;

    --shadow:    0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .10);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 13.5px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
h3 { font-size: 13.5px; }

p { margin: 0 0 var(--sp-3); }
p:last-child { margin-bottom: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------------------
   Top bar — thin, dark, always visible. Holds identity and primary nav.
   --------------------------------------------------------------------------- */
.topbar {
    background: var(--topbar);
    color: #fff;
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    padding: 0 var(--sp-4);
    height: 44px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar__brand {
    font-weight: 650;
    font-size: 14px;
    letter-spacing: -.01em;
    color: #fff;
    white-space: nowrap;
}
.topbar__brand:hover { text-decoration: none; opacity: .9; }

.topbar__nav {
    display: flex;
    align-items: stretch;
    gap: 2px;
    height: 100%;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
}
.topbar__nav::-webkit-scrollbar { display: none; }

.topbar__link {
    display: flex;
    align-items: center;
    padding: 0 var(--sp-3);
    color: #b9c4d0;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
}
.topbar__link:hover { color: #fff; background: var(--topbar-soft); text-decoration: none; }
.topbar__link.is-active {
    color: #fff;
    border-bottom-color: var(--primary);
    background: var(--topbar-soft);
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    font-size: 12px;
    color: #9fadbb;
    white-space: nowrap;
}
.topbar__user strong { color: #fff; font-weight: 600; }
.topbar__user a { color: #9fadbb; }
.topbar__user a:hover { color: #fff; }

/* Role/site chip in the top bar — always shows which side you are acting as,
   because issuing and dispensing look similar and the consequences differ. */
.chip {
    display: inline-block;
    padding: 1px var(--sp-2);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
    background: var(--topbar-soft);
    color: #cdd8e3;
}

/* ---------------------------------------------------------------------------
   Page shell
   --------------------------------------------------------------------------- */
.shell {
    max-width: 1360px;
    margin: 0 auto;
    padding: var(--sp-4);
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-3);
    flex-wrap: wrap;
}
.page-head__title { display: flex; align-items: baseline; gap: var(--sp-3); }
.page-head__sub { color: var(--muted); font-size: 12.5px; }
.page-head__actions { display: flex; gap: var(--sp-2); }

/* Sub-navigation — tabs within a section, per the house pattern */
.subnav {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--sp-3);
    overflow-x: auto;
}
.subnav a {
    padding: var(--sp-2) var(--sp-3);
    font-size: 12.5px;
    font-weight: 500;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------------------------------------------------------------------------
   Panels
   --------------------------------------------------------------------------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: var(--sp-3);
}

.panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
    border-radius: var(--radius) var(--radius) 0 0;
}
.panel__title { font-size: 12.5px; font-weight: 650; letter-spacing: .01em; }
.panel__body { padding: var(--sp-3); }
.panel__body--flush { padding: 0; }

/* Grid for dashboards */
.grid { display: grid; gap: var(--sp-3); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }

/* Stat tiles */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--sp-3);
}
.stat__label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--faint);
    font-weight: 600;
    margin-bottom: 2px;
}
.stat__value { font-size: 22px; font-weight: 650; line-height: 1.1; }
.stat__note { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat--warning .stat__value { color: var(--warning); }
.stat--danger  .stat__value { color: var(--danger); }
.stat--success .stat__value { color: var(--success); }

/* ---------------------------------------------------------------------------
   Tables — the workhorse. Dense rows, clear numeric alignment.
   --------------------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

.table th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--faint);
    font-weight: 600;
    padding: var(--sp-2) var(--sp-3);
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
    white-space: nowrap;
    position: sticky;
    top: 44px;
    z-index: 5;
}

.table td {
    padding: 6px var(--sp-3);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: 0; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table__empty {
    padding: var(--sp-5);
    text-align: center;
    color: var(--muted);
    font-size: 12.5px;
}

/* A quantity, wherever it appears, reads the same way */
.qty { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.qty__exact { font-weight: 400; color: var(--faint); font-size: 11.5px; }

/* ---------------------------------------------------------------------------
   Badges
   --------------------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
}
.badge--neutral { background: #eef1f4; color: var(--muted); }
.badge--info    { background: var(--primary-soft); color: var(--primary-dark); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }

/* ---------------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------------- */
.field { margin-bottom: var(--sp-3); }
.field:last-child { margin-bottom: 0; }

.label {
    display: block;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 3px;
}
.label .req { color: var(--danger); font-weight: 400; }

.input, .select, .textarea {
    width: 100%;
    padding: 6px var(--sp-2);
    font: inherit;
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.input:disabled, .select:disabled { background: #f1f3f5; color: var(--muted); }
.input::placeholder { color: var(--faint); }

.textarea { min-height: 60px; resize: vertical; }

.input--lg { font-size: 16px; padding: var(--sp-2) var(--sp-3); }
.input--num { text-align: right; font-variant-numeric: tabular-nums; }

.hint { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.error-text { font-size: 11.5px; color: var(--danger); margin-top: 3px; }
.input.is-invalid { border-color: var(--danger); }

.field-row { display: flex; gap: var(--sp-2); align-items: flex-end; }
.field-row > * { flex: 1; }
.field-row > .shrink { flex: 0 0 auto; }

.checkbox { display: flex; align-items: center; gap: var(--sp-2); font-size: 12.5px; }
.checkbox input { width: 15px; height: 15px; margin: 0; accent-color: var(--primary); }

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 6px var(--sp-3);
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.3;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn--primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: #a51f1f; }

.btn--ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn--ghost:hover { background: var(--primary-soft); }

.btn--lg { font-size: 14px; padding: var(--sp-2) var(--sp-4); }
.btn--sm { font-size: 11.5px; padding: 3px var(--sp-2); }
.btn--block { width: 100%; }

/* ---------------------------------------------------------------------------
   Flash messages
   --------------------------------------------------------------------------- */
.flash {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    border: 1px solid;
    font-size: 12.5px;
    margin-bottom: var(--sp-3);
}
.flash--success { background: var(--success-soft); border-color: #b9e0c9; color: #0b5c2f; }
.flash--error   { background: var(--danger-soft);  border-color: #f2c2c2; color: #941f1f; }
.flash--info    { background: var(--primary-soft); border-color: #bcd9f5; color: var(--primary-dark); }

/* ---------------------------------------------------------------------------
   Sign-in
   --------------------------------------------------------------------------- */
.auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    background: var(--bg);
}
.auth__card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    padding: var(--sp-5);
}
.auth__brand { text-align: center; margin-bottom: var(--sp-4); }
.auth__brand h1 { font-size: 20px; letter-spacing: -.02em; }
.auth__brand p { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.auth__foot {
    margin-top: var(--sp-4);
    text-align: center;
    font-size: 11.5px;
    color: var(--faint);
}

/* Six-digit OTP entry — used once two-factor is switched on */
.otp-input {
    font-size: 26px;
    letter-spacing: .35em;
    text-align: center;
    font-variant-numeric: tabular-nums;
    padding: var(--sp-3);
}

/* ---------------------------------------------------------------------------
   Utilities
   --------------------------------------------------------------------------- */
.muted  { color: var(--muted); }
.faint  { color: var(--faint); }
.small  { font-size: 11.5px; }
.strong { font-weight: 600; }
.right  { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono   { font-variant-numeric: tabular-nums; }

.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-success { color: var(--success); }

.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }

.row   { display: flex; gap: var(--sp-2); align-items: center; }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--sp-2); }

.divider { height: 1px; background: var(--border); margin: var(--sp-3) 0; }

/* ---------------------------------------------------------------------------
   Responsive — a clinic counter may be on a tablet.
   Density relaxes slightly and touch targets grow.
   --------------------------------------------------------------------------- */
@media (max-width: 900px) {
    .grid--4 { grid-template-columns: repeat(2, 1fr); }
    .grid--3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .shell { padding: var(--sp-2); }
    .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }

    .topbar { height: auto; flex-wrap: wrap; padding: var(--sp-2); gap: var(--sp-2); }
    .topbar__nav { order: 3; width: 100%; }
    .topbar__link { padding: var(--sp-2); }

    .table th { position: static; }

    /* Bigger tap targets where fingers are actually used */
    .btn { padding: var(--sp-2) var(--sp-3); }
    .input, .select { padding: var(--sp-2); font-size: 16px; } /* 16px stops iOS zooming */

    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Wide content never makes the page itself scroll sideways */
.table-scroll { overflow-x: auto; }

@media print {
    .topbar, .page-head__actions, .btn, .subnav { display: none !important; }
    body { background: #fff; font-size: 11px; }
    .panel { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
}
