:root {
  --navy: #0b1426;
  --navy-raised: #14233a;
  --navy-line: #24344d;
  --teal: #147e79;
  --teal-dark: #116762;
  --teal-bright: #55d4c4;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e4e9f0;
  --text: #17243b;
  --muted: #5a6a7f;
  --danger: #b3261e;
  --ok: #0f6b4f;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

/* Author display rules must never resurrect a hidden control. */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

img,
svg {
  max-width: 100%;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 12px;
  z-index: 60;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--teal);
  color: #ffffff;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  left: 12px;
}

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

/* Sidebar */

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--navy);
  color: #c7d2e3;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, #1b3556, #142d47);
  border: 1px solid #2b5874;
  color: #7ce6d9;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
}

.brand-text {
  color: #ffffff;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.3px;
}

.brand-sub {
  color: #8fa3bf;
  font-size: 11px;
  letter-spacing: 0.4px;
}

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

.nav-item {
  min-height: 44px;
  width: 100%;
  display: flex;
  align-items: center;
  border: 0;
  border-radius: 10px;
  background: none;
  color: #aab7c9;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
}

.nav-item:hover {
  background: #16263d;
  color: #ffffff;
}

.nav-item[aria-current="page"] {
  background: linear-gradient(90deg, #173d56, #19334e);
  color: #ecffff;
  box-shadow: inset 3px 0 0 var(--teal-bright);
}

.side-status {
  margin-top: auto;
  border-top: 1px solid var(--navy-line);
  padding: 14px 8px 0;
}

.side-status-title {
  margin: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #8fa3bf;
}

.side-status-value {
  margin: 8px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
  color: #e7eefb;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal-bright);
  flex: 0 0 8px;
}

.side-status-note {
  margin: 6px 0 0;
  font-size: 12px;
  color: #93a6c1;
}

/* Main shell */

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 28px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

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

.topbar-title {
  margin: 2px 0 0;
  font-size: 16px;
  font-weight: 750;
}

.mode-pill {
  margin: 0;
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f9fb;
  color: #43536a;
  font-size: 12px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.mode-pill[data-state="ok"] {
  background: #edf8f4;
  border-color: #bfe6d7;
  color: var(--ok);
}

.mode-pill[data-state="error"] {
  background: #fdecea;
  border-color: #f3c3bd;
  color: var(--danger);
}

main {
  width: 100%;
  max-width: 1180px;
  padding: 24px 28px 56px;
}

.view[hidden] {
  display: none;
}

h1,
h2,
h3 {
  line-height: 1.25;
  letter-spacing: -0.2px;
}

h1 {
  margin: 0 0 6px;
  font-size: 26px;
}

h2 {
  margin: 0 0 6px;
  font-size: 21px;
}

h3 {
  margin: 16px 0 4px;
  font-size: 16px;
}

h1:focus-visible,
h2:focus-visible {
  outline: 3px solid #6ecfc4;
  outline-offset: 4px;
}

.lead {
  margin: 0 0 16px;
  max-width: 72ch;
  color: var(--muted);
}

.notice {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid #cfe4e2;
  border-radius: 10px;
  background: #f0f8f7;
  color: #245a56;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

/* Four metrics need four columns on a wide screen; the shared middle and
   mobile breakpoints (1000px / 800px) already fold this grid to 2×2 and then 1. */
.stat-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.stat-label {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

.stat-value {
  margin: 8px 0 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
  overflow-wrap: anywhere;
}

.panel {
  min-width: 0;
  margin-bottom: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.panel-meta {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.panel-meta:empty {
  display: none;
}

.state-list {
  margin: 8px 0 0;
  padding-left: 20px;
  font-size: 14px;
  color: #3c4b61;
}

.state-list li {
  margin: 6px 0;
  overflow-wrap: anywhere;
}

/* Form */

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
  margin-bottom: 14px;
  font-size: 16px;
  font-weight: 750;
}

.field {
  margin-bottom: 16px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 650;
}

.req {
  color: var(--danger);
}

input,
textarea,
select,
button {
  font: inherit;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #cfd8e3;
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid #6ecfc4;
  outline-offset: 2px;
}

input[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
  background: #fff7f6;
}

fieldset:disabled input,
fieldset:disabled textarea,
fieldset:disabled button {
  opacity: 0.6;
  cursor: not-allowed;
}

.hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.field-error {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  overflow-wrap: anywhere;
}

.field-error:empty {
  display: none;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid #ced8e3;
  border-radius: 10px;
  background: #ffffff;
  color: #33455c;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover {
  background: #f7fafc;
}

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

.btn.primary:hover {
  background: var(--teal-dark);
}

.btn.small {
  min-height: 44px;
  padding: 8px 12px;
  font-size: 13px;
}

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

.status {
  margin: 12px 0 0;
  font-size: 14px;
  font-weight: 650;
  color: var(--ok);
  overflow-wrap: anywhere;
}

.status:empty {
  display: none;
}

.error {
  margin: 12px 0 0;
  font-size: 14px;
  font-weight: 650;
  color: var(--danger);
  overflow-wrap: anywhere;
}

.error:not(:empty) {
  padding: 10px 12px;
  border: 1px solid #f2c2bd;
  border-radius: 10px;
  background: #fdf1f0;
}

/* Lists */

.list {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
}

.row-main {
  flex: 1 1 220px;
  min-width: 0;
}

.row-title {
  margin: 0;
  font-size: 15px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.row-meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.qty-input {
  width: 110px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #cfd8e3;
  border-radius: 10px;
  text-align: center;
}

.qty-input[aria-invalid="true"] {
  border-color: var(--danger);
  background: #fff7f6;
}

.empty {
  margin: 12px 0 0;
  padding: 18px;
  border: 1px dashed #c9d4e0;
  border-radius: 10px;
  background: #fafbfd;
  color: #5d6d83;
  overflow-wrap: anywhere;
}

.empty[hidden] {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Session boot, account and access management */

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}

.boot-text {
  margin: 0;
  max-width: 46ch;
  color: var(--muted);
  font-weight: 650;
  overflow-wrap: anywhere;
}

.boot-text[data-state="error"] {
  color: var(--danger);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.account {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.account-id {
  min-width: 0;
  text-align: right;
}

.account-email {
  margin: 0;
  max-width: 30ch;
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.account-role {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-head h3 {
  margin: 16px 0 4px;
}

.temp-password {
  margin: 0 0 18px;
  padding: 16px;
  border: 1px solid #e2bd63;
  border-radius: 12px;
  background: #fff8e6;
  color: #574000;
}

.temp-warning {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.temp-value {
  margin: 0 0 12px;
}

.temp-value code {
  display: block;
  padding: 10px 12px;
  border: 1px dashed #b8923a;
  border-radius: 8px;
  background: #fffdf5;
  color: #3f2f00;
  font-size: 16px;
  font-weight: 700;
  overflow-wrap: anywhere;
  user-select: all;
}

/* Login and password screens */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, #0b1426, #14233a 58%, #0f2b35);
}

.login-card {
  width: 100%;
  max-width: 440px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgb(4 12 24 / 35%);
}

.login-brand {
  padding: 0;
  margin-bottom: 20px;
}

.login-brand .brand-text {
  color: var(--text);
}

.login-brand .brand-sub {
  color: var(--muted);
}

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

.login-note {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.login-form .form-actions {
  margin-top: 18px;
}

.login-submit {
  width: 100%;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 520px;
  margin: 0;
}

.auth-card h2 {
  margin-bottom: 8px;
}

/* Replenishment */

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
  margin: 0 0 14px;
}

.filter-btn {
  min-height: 44px;
}

.filter-btn[aria-pressed="true"] {
  border-color: var(--teal);
  background: #e8f5f3;
  color: var(--teal-dark);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.replen-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.replen-table caption {
  text-align: left;
}

.replen-table th,
.replen-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.replen-table th {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.replen-table tbody tr:last-child td {
  border-bottom: 0;
}

.replen-name .row-title {
  font-size: 14px;
}

.replen-order {
  font-weight: 750;
}

.replen-marker {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 650;
  color: #8a4b00;
}

/* Responsive */

@media (max-width: 1000px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 800px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    border-bottom: 1px solid var(--navy-line);
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav-item {
    width: auto;
    flex: 1 1 150px;
    justify-content: center;
  }

  .side-status {
    display: none;
  }

  .topbar {
    padding: 10px 14px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .account {
    width: 100%;
  }

  .account-id {
    text-align: left;
  }

  main {
    padding: 18px 14px 40px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  /* The replenishment table becomes stacked, labelled cards. */
  .table-wrap {
    overflow-x: visible;
  }

  .replen-table,
  .replen-table tbody,
  .replen-table tr,
  .replen-table td {
    display: block;
    width: 100%;
  }

  .replen-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .replen-table tr {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fbfcfe;
  }

  .replen-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    padding: 6px 0;
    border-bottom: 0;
  }

  .replen-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: var(--muted);
  }

  .replen-table td.replen-name {
    display: block;
    min-height: 0;
    margin-bottom: 4px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
  }

  .replen-table td.replen-name::before {
    display: block;
    margin-bottom: 4px;
  }
}

@media (max-width: 390px) {
  body {
    font-size: 14px;
  }

  main {
    padding: 14px 12px 32px;
  }

  h1 {
    font-size: 22px;
  }

  .panel {
    padding: 14px;
  }

  .mode-pill {
    padding: 6px 10px;
    font-size: 11px;
  }

  .row-actions {
    width: 100%;
  }

  .row-actions .btn {
    flex: 1 1 100%;
  }

  .qty-input {
    width: 100%;
  }

  .login-shell,
  .auth-screen {
    padding: 14px 10px;
  }

  .login-card {
    padding: 18px 14px;
    border-radius: 14px;
  }

  .auth-card {
    padding: 14px;
  }

  .account-email {
    max-width: 100%;
  }

  .section-head {
    align-items: flex-start;
  }

  .filter-btn {
    flex: 1 1 100%;
  }

  .replen-table td {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
