:root {
  color-scheme: light;
  --bg: #f2f6fb;
  --panel: #ffffff;
  --line: #d4deea;
  --text: #112036;
  --muted: #5a6d86;
  --primary: #145fc4;
  --primary-soft: #e8f1ff;
  --success: #1f7a42;
  --success-soft: #e9f8ef;
  --danger: #b63434;
  --danger-soft: #fdecec;
  --shadow: 0 8px 24px rgba(16, 42, 75, 0.08);
  --warn: #c97000;
  --warn-soft: #fff7e6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: linear-gradient(170deg, #e8f1ff 0%, var(--bg) 55%);
  color: var(--text);
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* ── Auth ── */
.auth-card {
  max-width: 340px;
  margin: 80px auto 0;
  padding: 32px 28px 24px;
}

.auth-logo {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.auth-card > .muted {
  text-align: center;
  margin-bottom: 0;
}

.auth-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 22px 0 14px;
  text-align: left;
}

.auth-field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 5px;
}

.auth-initials-input {
  width: 100%;
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: 10px;
  padding: 11px 14px;
}

.auth-pin-input {
  width: 100%;
  font-size: 20px;
  letter-spacing: 0.25em;
  text-align: center;
  border-radius: 10px;
  padding: 11px 14px;
}

.full-width {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 10px;
}

.auth-err {
  min-height: 18px;
  margin-top: 10px;
  text-align: center;
  font-size: 13px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel.block {
  margin: 14px 0;
}

.danger {
  background: var(--danger-soft);
  border-color: #f6bdbd;
  color: #7d1616;
}

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

.topbar-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.topbar-meta {
  font-size: 13px;
  color: var(--muted);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}

h1, h2, h3 {
  margin: 0;
}

h1 {
  margin-bottom: 8px;
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.muted {
  color: var(--muted);
  margin: 8px 0 0;
  font-size: 14px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.toolbar .grow {
  min-width: 260px;
  flex: 1;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.check-inline input {
  width: auto;
}

.check-inline > span {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  font-weight: 600;
}

.hint {
  margin: 10px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.full {
  grid-column: 1 / -1;
}

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

label {
  display: block;
}

label > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font: inherit;
  color: var(--text);
  background: white;
}

input:focus, select:focus {
  outline: 2px solid #bfd8ff;
  border-color: var(--primary);
}

.btn {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
}

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

.btn.success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.supplier-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 12px;
  overflow: hidden;
}

.list-section {
  margin-top: 14px;
}

.list-section h4 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.supplier-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #f5f9ff 0%, #f7fcf9 100%);
}

.supplier-name {
  font-weight: 700;
}

.supplier-stats {
  font-size: 12px;
  color: var(--muted);
}

.site-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.site-col {
  border-right: 1px solid var(--line);
  min-height: 70px;
}

.site-col:last-child {
  border-right: 0;
}

.site-col h4 {
  margin: 0;
  padding: 8px 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.site-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.item-name {
  font-weight: 600;
  font-size: 14px;
}

.item-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.item-controls {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.badge {
  border-radius: 999px;
  font-size: 11px;
  padding: 4px 8px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.pending {
  background: #fff3d8;
  color: #7e5a00;
}

.badge.ordered {
  background: #e9f3ff;
  color: #0f4f8e;
}

.priority-now {
  color: #b63434;
  font-weight: 700;
}

.priority-1month {
  color: #8a6600;
  font-weight: 700;
}

.priority-2months {
  color: #1f7a42;
  font-weight: 700;
}

.inline-check {
  margin-right: 6px;
}

.empty {
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .form-grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .toolbar .grow {
    min-width: 100%;
  }
}

@media (max-width: 760px) {
  .site-grid {
    grid-template-columns: 1fr;
  }
  .site-col {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .site-col:last-child {
    border-bottom: 0;
  }
}

/* ─────────────────────────────────────────
   Nurse Panel
   ───────────────────────────────────────── */

#nurse-panel {
  max-width: 600px;
  margin: 0 auto;
}

.nurse-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.nurse-search-input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: white;
}

.nurse-search-input:focus {
  outline: 2px solid #bfd8ff;
  border-color: var(--primary);
}

/* Sub-tabs inside nurse panel */
.nurse-tabs {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 16px;
}

.nurse-tab {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 9px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.nurse-tab.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(16, 42, 75, 0.12);
}

/* ─────────────────────────────────────────
   Nurse Panel — tap-to-flag design (.ns-*)
   ───────────────────────────────────────── */

/* Sticky header */
.ns-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 10px 0 0;
}

.ns-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.ns-search-wrap {
  flex: 1;
  position: relative;
}

.ns-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.ns-search-wrap input {
  padding-left: 38px;
  font-size: 16px; /* prevents iOS zoom */
  border-radius: 12px;
}

.ns-refresh-btn {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.ns-refresh-btn:active { background: var(--bg); }

/* Sub-tabs (Stock Check / On Order) */
.ns-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.ns-tab {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  color: var(--muted);
  transition: all 0.15s;
}
.ns-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ── Category blocks ── */
.ns-cat-block {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 8px;
  overflow: hidden;
}

.ns-cat-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: white;
  border: none;
  font: inherit;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.ns-cat-header:active { background: var(--bg); }
.ns-cat-block.ns-cat-open .ns-cat-header {
  border-bottom: 1px solid var(--line);
}

.ns-cat-icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

.ns-cat-name {
  font-size: 15px;
  font-weight: 700;
  flex: 1;
  color: var(--text);
}

.ns-chevron {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.ns-cat-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  flex-shrink: 0;
}

/* Accordion body — hidden by default, shown when open */
.ns-cat-body {
  display: none;
}
.ns-cat-block.ns-cat-open .ns-cat-body {
  display: block;
}

/* ── Variant group (level 2) ── */
.ns-grp-block {
  border-top: 1px solid var(--line);
}
.ns-grp-block:first-child { border-top: none; }

.ns-grp-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px 11px 20px;
  background: #f7f9fd;
  border: none;
  font: inherit;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.ns-grp-header:active { background: var(--line); }
.ns-grp-block.ns-grp-open .ns-grp-header {
  border-bottom: 1px solid var(--line);
}

.ns-grp-name {
  font-size: 13px;
  font-weight: 700;
  flex: 1;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ns-grp-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  flex-shrink: 0;
}

.ns-grp-body {
  display: none;
}
.ns-grp-block.ns-grp-open .ns-grp-body {
  display: block;
}

/* Indent rows inside a group */
.ns-grp-body .ns-row {
  padding-left: 28px;
}
.ns-grp-body .ns-row-flagged {
  padding-left: 25px;
}

/* ── Product rows ── */
.ns-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  min-height: 56px;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.ns-row:last-child { border-bottom: none; }
.ns-row:active { background: var(--bg); }

.ns-row-flagged {
  background: #eef4ff;
  border-left: 3px solid var(--primary);
  padding-left: 13px;
}
.ns-row-flagged:active { background: #daeaff; }

.ns-row-ordered {
  background: var(--success-soft);
  cursor: default;
  opacity: 0.85;
}
.ns-row-ordered:active { background: var(--success-soft); }

.ns-row-left {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.ns-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: block;
  line-height: 1.3;
}

.ns-pack {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

/* Colour dot (TePe/Optim) */
.ns-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(0,0,0,0.14);
  display: inline-block;
}

/* Flag indicator (right side) */
.ns-flag-indicator {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ADD pill (unflagged) */
.ns-plus-ring {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--primary);
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.04em;
  white-space: nowrap;
  background: var(--primary-soft);
}

/* ✓ check (flagged) */
.ns-check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  font-size: 13px;
  font-weight: 700;
  color: white;
  line-height: 1;
}

/* On-order chip */
.ns-ordered-chip {
  font-size: 12px;
  font-weight: 700;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid #b2dfc5;
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Floating review bar ── */
.ns-review-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: transparent;
  pointer-events: none;
}

.ns-review-btn {
  display: block;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 16px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(20, 95, 196, 0.45);
  pointer-events: all;
  transition: background 0.15s, transform 0.1s;
}
.ns-review-btn:active {
  background: #0f4faa;
  transform: scale(0.98);
}

/* ── Bottom sheet ── */
.ns-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 20, 40, 0.45);
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(2px);
}

.ns-sheet {
  background: white;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 32px rgba(16, 42, 75, 0.15);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.ns-sheet-handle {
  width: 44px;
  height: 5px;
  background: var(--line);
  border-radius: 999px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.ns-sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 18px 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}

.ns-sheet-title {
  font-size: 17px;
  font-weight: 700;
}

.ns-sheet-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.ns-sheet-close {
  background: var(--bg);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 16px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ns-sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0;
}

.ns-sheet-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

/* Sheet rows */
.ns-sheet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  min-height: 60px;
}
.ns-sheet-row:last-child { border-bottom: none; }

/* Quantity stepper in sheet */
.ns-sq {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1.5px solid var(--primary);
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.ns-sq-btn {
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  font-size: 22px;
  font-weight: 500;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.ns-sq-btn:active { background: var(--primary-soft); }

.ns-sq-val {
  min-width: 32px;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  border-left: 1.5px solid var(--primary);
  border-right: 1.5px solid var(--primary);
  line-height: 44px;
}

/* On Order summary */
.ns-onorder-summary {
  font-size: 15px;
  font-weight: 600;
  color: var(--success);
  padding: 14px 16px 6px;
}

/* ── Empty / hint states ── */
.nurse-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.nurse-hint {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 4px 10px;
  margin: 0;
}

/* Bottom padding so floating bar doesn't overlap last item */
#nurse-stockcheck-board,
#nurse-ordered-board {
  padding-bottom: 88px;
}

/* ─────────────────────────────────────────
   Staff Panel
   ───────────────────────────────────────── */

#staff-panel {
  max-width: 900px;
  margin: 0 auto;
}

.staff-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}

.staff-form-card h3 {
  margin-bottom: 14px;
}

.staff-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 14px;
}

.staff-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.staff-row.staff-inactive {
  opacity: 0.5;
}

.staff-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.staff-info {
  flex: 1;
  min-width: 0;
}

.staff-name {
  font-weight: 600;
  font-size: 14px;
}

.staff-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 3px;
  flex-wrap: wrap;
}

.staff-role-badge {
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
}

.staff-role-badge.role-admin    { background: #f0e8ff; color: #6d28d9; }
.staff-role-badge.role-manager  { background: var(--primary-soft); color: var(--primary); }
.staff-role-badge.role-nurse    { background: var(--success-soft); color: var(--success); }

.staff-site {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border-radius: 6px;
  padding: 2px 7px;
}

.staff-inactive-label {
  font-size: 11px;
  color: var(--danger);
  font-weight: 600;
}

.btn-danger-soft {
  background: var(--danger-soft);
  border-color: #f6bdbd;
  color: var(--danger);
  font-size: 12px;
  padding: 5px 10px;
  flex-shrink: 0;
}

/* ─────────────────────────────────────────
   Responsive
   ───────────────────────────────────────── */
@media (max-width: 700px) {
  .staff-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .auth-card {
    margin-top: 30px;
  }

  .page {
    padding: 12px 12px 0;
  }

  .ns-header {
    padding: 8px 0 0;
  }

  .ns-row {
    padding: 12px 12px;
    min-height: 60px;
  }
  .ns-row-flagged {
    padding-left: 9px;
  }

  .ns-name {
    font-size: 14px;
  }

  .ns-cat-header {
    padding: 10px 12px;
  }

  .ns-review-btn {
    font-size: 15px;
    padding: 14px 16px;
  }

  .ns-sheet {
    max-height: 88vh;
  }
}
