:root {
  --button-height-sm: 32px;
  --button-height-md: 38px;
  --button-height-lg: 44px;
  --input-height: 40px;
  --sidebar-item-height: 40px;
  --card-padding: var(--space-5);
  --table-cell-padding: 12px 14px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--size-md);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

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

img {
  max-width: 100%;
  display: block;
}

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

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea,
[role="button"] {
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

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

.hidden {
  display: none !important;
}

.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;
}

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--topbar-height);
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--size-lg);
  font-weight: var(--weight-semibold);
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) 0;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--sidebar-item-height);
  padding: 0 var(--space-5);
  color: var(--color-text-soft);
  border-left: 2px solid transparent;
  font-weight: var(--weight-medium);
}

.sidebar-nav-item:hover {
  background: var(--color-surface-subtle);
  color: var(--color-text);
  text-decoration: none;
}

.sidebar-nav-item[aria-current="page"] {
  background: var(--color-primary-soft);
  border-left-color: var(--color-primary);
  color: var(--color-primary);
}

.sidebar .user-box {
  margin-top: auto;
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: grid;
  gap: var(--space-1);
}

.sidebar .brand-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--topbar-height);
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--color-border);
}

.sidebar .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: var(--size-sm);
  font-weight: var(--weight-bold);
}

.sidebar .brand-text {
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.sidebar .user-name {
  font-weight: var(--weight-semibold);
}

.sidebar .user-email {
  color: var(--color-text-muted);
  font-size: var(--size-sm);
}

.main-content {
  flex: 1;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--topbar-height);
  padding: 0 var(--space-6);
  background: rgba(255, 255, 255, 0.75);
  border-bottom: 1px solid var(--color-border);
  backdrop-filter: blur(12px);
}

.topbar-left,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-title {
  font-size: var(--size-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.topbar .user-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar .user-label {
  font-size: var(--size-sm);
  color: var(--color-text-soft);
}

.role-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--size-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 999px;
  line-height: 1;
}

.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

.sidebar-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  margin: 3px auto;
  background: currentColor;
  border-radius: 999px;
}

@media (prefers-color-scheme: dark) {
  .topbar {
    background: rgba(15, 23, 42, 0.72);
  }
}

.topbar .meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: var(--size-sm);
  font-weight: var(--weight-semibold);
}

.page-shell {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-6);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: var(--size-3xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.03em;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.card-body {
  padding: var(--card-padding);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--button-height-md);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font-size: var(--size-md);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-neutral-0);
  border-color: var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-primary-active);
  border-color: var(--color-primary-active);
}

.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-surface-subtle);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-soft);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-surface-subtle);
}

.btn-danger {
  background: var(--color-danger-50);
  color: var(--color-danger-700);
  border-color: var(--color-danger-100);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger-100);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: var(--button-height-sm);
  padding: 0 var(--space-3);
  font-size: var(--size-sm);
}

.btn-lg {
  min-height: var(--button-height-lg);
  padding: 0 var(--space-5);
}

.btn[aria-busy="true"],
.btn.is-loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn[aria-busy="true"]::after,
.btn.is-loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-top-color: transparent;
  border-radius: 50%;
  position: absolute;
  animation: spin 0.7s linear infinite;
}

.btn-secondary.is-loading::after,
.btn-ghost.is-loading::after {
  border-color: rgba(17, 24, 39, 0.4);
  border-top-color: transparent;
}

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

.form-group {
  margin-bottom: var(--space-4);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--size-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.form-helper {
  margin-top: var(--space-2);
  font-size: var(--size-sm);
  color: var(--color-text-muted);
}

.field-message {
  min-height: 18px;
  margin-top: var(--space-2);
  font-size: var(--size-sm);
  color: var(--color-danger-700);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
  width: 100%;
  min-height: var(--input-height);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-3);
  color: var(--color-text);
}

textarea {
  min-height: 96px;
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-muted);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}

input.invalid,
select.invalid,
textarea.invalid {
  border-color: var(--color-danger-500);
  box-shadow: var(--focus-ring-danger);
}

.password-wrap {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  min-height: auto;
  padding: var(--space-2);
}

.alert {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-subtle);
  color: var(--color-text-soft);
}

.alert-error {
  background: var(--color-danger-50);
  border-color: var(--color-danger-100);
  color: var(--color-danger-700);
}

.alert-success {
  background: var(--color-success-50);
  border-color: rgba(16, 185, 129, 0.25);
  color: var(--color-success-700);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.table-wrap table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.table-wrap thead th {
  background: var(--color-surface-subtle);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--size-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: var(--table-cell-padding);
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table-wrap tbody td {
  padding: var(--table-cell-padding);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  background: var(--color-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-wrap tbody tr:hover td {
  background: var(--color-surface-subtle);
}

.table-wrap tbody tr:last-child td {
  border-bottom: none;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: var(--space-2);
  padding: var(--space-12) var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
}

.empty-state strong {
  color: var(--color-text);
  font-size: var(--size-xl);
}

.skeleton-row {
  height: 14px;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-neutral-100) 25%, var(--color-neutral-200) 50%, var(--color-neutral-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 var(--space-2);
  border-radius: 999px;
  font-size: var(--size-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.badge-low {
  background: var(--color-warning-50);
  color: var(--color-warning-700);
}

.badge-success {
  background: var(--color-success-50);
  color: var(--color-success-700);
}

.badge-danger {
  background: var(--color-danger-50);
  color: var(--color-danger-700);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--size-sm);
}

.pagination .page-status {
  margin-right: var(--space-2);
}

.toast-container {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.toast {
  min-width: 220px;
  max-width: 320px;
  background: var(--color-neutral-900);
  color: var(--color-neutral-0);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm);
}

.toast.success {
  background: var(--color-success-700);
}

.toast.error {
  background: var(--color-danger-700);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  z-index: 100;
}

.modal {
  width: min(100%, 520px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: var(--size-xl);
}

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  min-height: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--color-surface-subtle);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
}

.auth-brand-pane {
  display: none;
}

.auth-form-pane {
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: linear-gradient(180deg, var(--color-bg) 0%, var(--color-neutral-50) 100%);
}

/* Fixed brand colours below (not the theme-aware surface/text tokens) —
   this panel is a constant brand statement, not something that should
   flip with the visitor's light/dark preference. */
@media (min-width: 900px) {
  .auth-shell {
    grid-template-columns: 1fr 1fr;
  }

  .auth-brand-pane {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-12);
    background: var(--color-primary-900);
  }

  .auth-brand-mark {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    font-weight: var(--weight-bold);
    font-size: var(--size-lg);
  }

  .auth-brand-title {
    margin: 0;
    font-size: var(--size-4xl);
    font-weight: var(--weight-bold);
    letter-spacing: -0.03em;
    color: #ffffff;
  }

  .auth-brand-tagline {
    margin: 0;
    max-width: 380px;
    color: var(--color-primary-100);
    font-size: var(--size-lg);
    line-height: 1.6;
  }
}

.auth-card {
  width: min(100%, 420px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xs);
  padding: var(--space-8);
}

.auth-card h1 {
  margin: 0 0 var(--space-2);
  font-size: var(--size-4xl);
  letter-spacing: -0.04em;
}

.auth-card .subtitle {
  margin: 0 0 var(--space-6);
  color: var(--color-text-muted);
}

.auth-card .switch-link {
  margin-top: var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--size-sm);
}

.auth-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: calc(var(--space-4) * -1) 0 var(--space-5);
  flex-wrap: wrap;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--size-sm);
  color: var(--color-text-soft);
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  accent-color: var(--color-primary);
}

.checkbox-label.is-disabled {
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.auth-disabled-link {
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  cursor: not-allowed;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.password-requirements {
  list-style: none;
  margin: calc(var(--space-4) * -1) 0 var(--space-4);
  padding: 0;
}

.requirement {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--size-sm);
  color: var(--color-text-muted);
}

.requirement-icon-unmet,
.requirement-icon-met {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

.requirement-icon-met {
  display: none;
  color: var(--color-success-700);
}

.requirement-icon-unmet {
  color: var(--color-text-muted);
}

.requirement.met {
  color: var(--color-success-700);
}

.requirement.met .requirement-icon-met {
  display: block;
}

.requirement.met .requirement-icon-unmet {
  display: none;
}

.eyebrow {
  margin: 0 0 var(--space-1);
  font-size: var(--size-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary);
}

.text-muted {
  color: var(--color-text-muted);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.section-header h2 {
  margin: 0;
  font-size: var(--size-xl);
  letter-spacing: -0.02em;
}

/* ---------- Stat cards (dashboard) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}

.stat-card .label {
  font-size: var(--size-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
}

.stat-card .value {
  font-size: var(--size-4xl);
  font-weight: var(--weight-bold);
  margin-top: var(--space-2);
  font-variant-numeric: tabular-nums;
}

.stat-card.alert .value {
  color: var(--color-danger-700);
}

.dashboard-skeleton {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.skeleton-metric {
  height: 120px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: linear-gradient(90deg, var(--color-surface-subtle) 0%, var(--color-surface-muted) 50%, var(--color-surface-subtle) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.25s ease-in-out infinite;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: var(--space-5);
  margin-top: var(--space-6);
  align-items: start;
}

/* ---------- Recent stock movements list (dashboard) ---------- */
.movement-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.movement-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
}

.movement-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.movement-meta,
.movement-time {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--size-sm);
  color: var(--color-text-muted);
}

.movement-empty {
  list-style: none;
  padding: var(--space-4);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  text-align: center;
}

/* ---------- Toolbar (search / filters) ---------- */
.toolbar {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.toolbar-field {
  min-width: 180px;
  flex: 1 1 220px;
}

.toolbar-search {
  flex: 1.3 1 280px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.toolbar input,
.toolbar select {
  max-width: 100%;
}

.toolbar-panel {
  margin-bottom: var(--space-4);
}

.toolbar-panel .card-body {
  padding: var(--space-4);
}

/* ---------- Product image thumbnails ---------- */
.product-card {
  overflow: hidden;
}

.product-card .card-body {
  padding: 0;
}

.thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--color-surface-subtle);
  border: 1px solid var(--color-border);
}

.thumb.placeholder {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--color-neutral-100), var(--color-neutral-200));
}

.thumb.placeholder::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(107, 114, 128, 0.18);
  position: relative;
}

.thumb.placeholder::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 12px;
  border-radius: 30% 30% 12% 12%;
  margin-top: 12px;
  background: rgba(107, 114, 128, 0.14);
}

/* ---------- Table column/cell modifiers ---------- */
.image-col {
  width: 68px;
}

.numeric-col,
.data-numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.actions-col {
  width: 170px;
}

.actions-cell {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  align-items: center;
}

.cell-name {
  font-weight: var(--weight-semibold);
}

/* ---------- Role / movement / status badge colours ---------- */
.badge-admin {
  background: var(--color-neutral-800);
  color: var(--color-neutral-0);
}

.badge-staff {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.badge-viewer {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
}

.badge-in,
.badge-ok {
  background: var(--color-success-50);
  color: var(--color-success-700);
}

.badge-out {
  background: var(--color-danger-50);
  color: var(--color-danger-700);
}

/* ---------- Inline table-level error banner ---------- */
.table-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  background: var(--color-danger-50);
  color: var(--color-danger-700);
  border: 1px solid var(--color-danger-100);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
}

.sidebar .logout-btn {
  padding: 0 var(--space-5) var(--space-4);
}

@media (max-width: 768px) {
  .app-shell {
    position: relative;
    flex-direction: column;
  }

  .sidebar {
    width: min(82vw, 280px);
    height: 100vh;
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-102%);
    transition: transform 180ms ease;
    z-index: 30;
    border-right: 1px solid var(--color-border);
    border-bottom: none;
    box-shadow: var(--shadow-sm);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .app-shell.sidebar-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.32);
    z-index: 20;
  }

  .sidebar nav {
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 0;
  }

  .sidebar-nav-item {
    border-left: 2px solid transparent;
    border-bottom: none;
    padding: 0 var(--space-5);
  }

  .sidebar-nav-item[aria-current="page"] {
    border-bottom-color: transparent;
    border-left-color: var(--color-primary);
  }

  .topbar .user-meta {
    display: none;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .page-shell {
    padding: var(--space-4);
  }

  .form-row {
    grid-template-columns: 1fr;
  }

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

  .dashboard-skeleton {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* Below this width a data table stops trying to fit columns into the
   viewport and reflows each row into a labelled stacked card instead —
   never a horizontally-scrolling table on a phone. */
@media (max-width: 640px) {
  .table-wrap {
    border: none;
    border-radius: 0;
    background: transparent;
  }

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

  .table-wrap thead {
    display: none;
  }

  .table-wrap tbody tr {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    box-shadow: var(--shadow-xs);
  }

  .table-wrap tbody td {
    border: none;
    padding: var(--space-2) 0;
    white-space: normal;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    text-align: right;
  }

  .table-wrap tbody td[data-label]::before {
    content: attr(data-label);
    font-size: var(--size-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    text-align: left;
  }

  .table-wrap .image-col,
  .table-wrap .numeric-col,
  .table-wrap .actions-col {
    width: auto;
  }

  .table-wrap .actions-cell {
    justify-content: flex-start;
    padding-top: var(--space-2);
  }

  .toolbar-panel .card-body {
    padding: var(--space-3);
  }
}

@media (max-width: 480px) {
  .auth-card {
    padding: var(--space-5);
  }

  .topbar {
    padding: 0 var(--space-4);
  }

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