/* =========================================================
   Slab Brain — Delivery (SlabSign) app styles
   Built on sb-design-system.css (load that FIRST).
   All colour/spacing/type from design tokens.
   Zero hardcoded hex / rgb / named colours.
   ========================================================= */

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

html { font-family: var(--font-ui); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-ui-lg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ── Nav ──────────────────────────────────────────────── */
.d-nav {
  position: sticky;
  top: 0;
  z-index: var(--z-overlay);
  background: var(--color-bg);
  border-bottom: var(--border-hairline);
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
}

.d-nav__inner {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.d-nav__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
}

.d-nav__logo {
  height: 36px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
}

.d-nav__name {
  font-size: var(--text-ui-md);
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
}

.d-nav__links {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.d-nav__links a {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-ui-sm);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color var(--t-base), background var(--t-base);
}

.d-nav__links a:hover {
  color: var(--color-text-primary);
  background: var(--color-surface);
  text-decoration: none;
}

.d-nav__links a.active {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.d-nav__links a svg,
.d-nav__links a .nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Mobile hamburger */
.d-nav__toggle {
  display: none;
  background: none;
  border: var(--border-standard);
  border-radius: var(--radius-md);
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-primary);
  padding: 0;
}

/* ── Page wrapper ─────────────────────────────────────── */
.d-page {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16);
}

.d-page--narrow {
  max-width: 720px;
}

/* ── Page header ──────────────────────────────────────── */
.d-header {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: var(--border-hairline);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.d-header__left {}
.d-header__kicker {
  font-size: var(--text-ui-xs);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin-bottom: var(--space-1);
}
.d-header__title {
  font-size: var(--text-ui-xl);
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.25;
}
.d-header__sub {
  margin-top: var(--space-1);
  font-size: var(--text-ui-md);
  color: var(--color-text-secondary);
}
.d-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ── Home portal cards ────────────────────────────────── */
.d-portal {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-5);
  margin-top: var(--space-6);
}

@media (max-width: 900px) {
  .d-portal { grid-template-columns: 1fr; }
}

.d-portal-card {
  background: var(--color-surface-raised);
  border: var(--border-hairline);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--t-base), transform var(--t-base);
}

.d-portal-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.d-portal-card__icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.d-portal-card__icon svg { width: 24px; height: 24px; }

.d-portal-card__title {
  font-size: var(--text-ui-lg);
  font-weight: 600;
  color: var(--color-text-primary);
}

.d-portal-card__desc {
  font-size: var(--text-ui-md);
  color: var(--color-text-secondary);
  flex: 1;
}

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-ui-md);
  font-weight: 500;
  line-height: 1;
  border: var(--border-standard);
  background: var(--color-surface-raised);
  color: var(--color-text-primary);
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--t-base), transform var(--t-fast), background var(--t-base);
  white-space: nowrap;
}
.btn:hover { background: var(--color-surface); text-decoration: none; color: var(--color-text-primary); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.btn--primary {
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-color: transparent;
}
.btn--primary:hover { opacity: 0.88; background: var(--color-accent); color: var(--color-accent-text); }

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

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

.btn--lg { height: 48px; padding: 0 var(--space-6); font-size: var(--text-ui-lg); }
.btn--sm { height: 32px; padding: 0 var(--space-3); font-size: var(--text-ui-sm); }
.btn--full { width: 100%; }

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Form controls ────────────────────────────────────── */
.lbl {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--text-ui-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

.inp {
  width: 100%;
  height: 44px;
  padding: 0 var(--space-4);
  background: var(--color-surface-raised);
  border: var(--border-standard);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-ui-lg);
  color: var(--color-text-primary);
  transition: border-color var(--t-base);
  appearance: none;
}
.inp:focus { outline: none; border: var(--border-focus); }
.inp::placeholder { color: var(--color-text-tertiary); }
.inp:disabled { opacity: 0.5; cursor: not-allowed; }

select.inp { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238C8479' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

textarea.inp { height: auto; min-height: 88px; padding: var(--space-3) var(--space-4); resize: vertical; line-height: 1.55; }

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

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 600px) { .field-row { grid-template-columns: 1fr; } }

/* ── Cards / surfaces ─────────────────────────────────── */
.card {
  background: var(--color-surface-raised);
  border: var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.card--surface {
  background: var(--color-surface);
  box-shadow: none;
}

/* ── Invoice table ────────────────────────────────────── */
.inv-table-wrap {
  border: var(--border-hairline);
  border-radius: var(--radius-lg);
  /* Scroll wide tables (e.g. Track's 14 columns) instead of clipping the
     rightmost Edit/Delete columns. No min-width — only scrolls when content
     actually overflows, so narrower tables are unaffected. */
  overflow-x: auto;
  background: var(--color-surface-raised);
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
}

.inv-table thead th {
  font-size: var(--text-ui-xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  background: var(--color-surface);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-standard);
  text-align: left;
  white-space: nowrap;
}

.inv-table thead th.drag-col { width: 32px; }

.inv-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-hairline);
  vertical-align: middle;
  font-size: var(--text-ui-md);
  color: var(--color-text-primary);
}

.inv-table tbody tr:last-child td { border-bottom: none; }
.inv-table tbody tr:hover td { background: var(--color-accent-subtle); }

.inv-table .td-right { text-align: right; white-space: nowrap; }
.inv-table .td-actions { white-space: nowrap; }

/* Drag handle */
.drag-handle {
  cursor: grab;
  color: var(--color-text-tertiary);
  display: flex;
  align-items: center;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 16px; height: 16px; }
.sortable-ghost { opacity: 0.4; }
.sortable-chosen td { background: var(--color-accent-subtle) !important; }

/* Invoice customer name cell */
.inv-name { font-weight: 500; color: var(--color-text-primary); }
.inv-meta { font-size: var(--text-ui-sm); color: var(--color-text-secondary); margin-top: 2px; }

/* Secondary/de-emphasized text (e.g. Fetch-from-SPS panel copy + status text) */
.muted { color: var(--color-text-secondary); }

/* ── Status chips ─────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-ui-xs);
  font-weight: 500;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.chip--neutral { background: var(--color-surface); color: var(--color-text-secondary); border: var(--border-hairline); }
.chip--success { background: var(--color-success-subtle); color: var(--color-success); }
.chip--warning { background: var(--color-danger-subtle); color: var(--color-danger); }
.chip--accent  { background: var(--color-accent-subtle); color: var(--color-accent); }

/* ── Mobile invoice cards ─────────────────────────────── */
.inv-mobile-list {
  display: none;
  flex-direction: column;
  gap: var(--space-3);
}

.inv-card {
  background: var(--color-surface-raised);
  border: var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.inv-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.inv-card__name {
  font-size: var(--text-ui-lg);
  font-weight: 600;
  color: var(--color-text-primary);
}

.inv-card__meta {
  font-size: var(--text-ui-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}

.inv-card__actions {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.inv-card__row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) 0;
  border-bottom: var(--border-hairline);
}
.inv-card__row:last-of-type { border-bottom: none; }
.inv-card__label {
  font-size: var(--text-ui-sm);
  color: var(--color-text-tertiary);
  flex-shrink: 0;
}
.inv-card__value {
  font-size: var(--text-ui-sm);
  color: var(--color-text-primary);
  text-align: right;
}

@media (max-width: 800px) {
  .inv-table-wrap { display: none; }
  .inv-mobile-list { display: flex; }
}

/* ── Toolbar (filter row above tables) ────────────────── */
.d-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.d-toolbar__spacer { flex: 1; }

/* ── Signature pad ────────────────────────────────────── */
.sig-wrap {
  margin: var(--space-4) 0;
}

.sig-label {
  font-size: var(--text-ui-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

#signature-pad {
  width: 100%;
  max-width: 540px;
  height: 200px;
  border: var(--border-standard);
  border-radius: var(--radius-lg);
  background: var(--color-surface-raised);
  display: block;
  touch-action: none;
}

.sig-actions {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
}

/* ── PDF viewer ───────────────────────────────────────── */
#pdf-iframe {
  width: 100%;
  min-height: 700px;
  border: var(--border-hairline);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  display: block;
}

/* ── Alerts / error / success ─────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-ui-md);
}
.alert--error {
  background: var(--color-danger-subtle);
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
}
.alert--success {
  background: var(--color-success-subtle);
  border: 1px solid var(--color-success);
  color: var(--color-success);
}

/* ── Modal ────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--color-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--color-surface-raised);
  border: var(--border-hairline);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  padding: var(--space-6);
  animation: dModalIn 0.2s ease-out;
}
@keyframes dModalIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.modal-card--wide { max-width: 800px; }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.modal-title {
  font-size: var(--text-ui-xl);
  font-weight: 600;
  color: var(--color-text-primary);
}
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  padding: 0;
  transition: color var(--t-base), background var(--t-base);
}
.modal-close:hover { color: var(--color-text-primary); background: var(--color-surface); }
.modal-close svg { width: 20px; height: 20px; }

.modal-footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: var(--border-hairline);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

@media (max-width: 560px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-card { max-width: 100%; max-height: 90vh; border-radius: var(--radius-2xl) var(--radius-2xl) 0 0; }
}

/* ── Empty state ──────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-6);
  color: var(--color-text-tertiary);
}
.empty-state__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--color-border-strong);
}
.empty-state__icon svg { width: 100%; height: 100%; }
.empty-state__title {
  font-size: var(--text-ui-lg);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}
.empty-state__sub {
  font-size: var(--text-ui-md);
  color: var(--color-text-tertiary);
}

/* ── Spinner (button loading state) ──────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: dSpin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes dSpin { to { transform: rotate(360deg); } }

/* ── Divider ──────────────────────────────────────────── */
.divider {
  border: none;
  border-top: var(--border-hairline);
  margin: var(--space-5) 0;
}

/* ── Upload drop zone ─────────────────────────────────── */
.drop-zone {
  border: 1.5px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  transition: border-color var(--t-base), background var(--t-base);
  cursor: pointer;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}
.drop-zone__icon {
  width: 40px;
  height: 40px;
  margin: 0 auto var(--space-3);
  color: var(--color-text-tertiary);
}
.drop-zone__icon svg { width: 100%; height: 100%; }
.drop-zone__text {
  font-size: var(--text-ui-md);
  color: var(--color-text-secondary);
}
.drop-zone__hint {
  font-size: var(--text-ui-sm);
  color: var(--color-text-tertiary);
  margin-top: var(--space-1);
}

/* ── Loading overlay ──────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-toast);
  display: none;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-bg) 85%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.loading-overlay.active { display: flex; }
.loading-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.loading-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  animation: dSpin 0.9s linear infinite;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: var(--radius-md);
}
.loading-text {
  text-align: center;
  font-size: var(--text-ui-md);
  font-weight: 500;
  color: var(--color-text-primary);
}

/* ── Login page ───────────────────────────────────────── */
.login-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
  background: var(--color-bg);
}
.login-col {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
}
.login-brand__logo {
  height: 52px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
}
.login-brand__name {
  font-size: var(--text-ui-xl);
  font-weight: 600;
  color: var(--color-text-primary);
}
.login-brand__sub {
  font-size: var(--text-ui-xs);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}
.login-card {
  background: var(--color-surface-raised);
  border: var(--border-hairline);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--shadow-md);
}
.login-card__title {
  font-size: var(--text-ui-lg);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-6);
  text-align: center;
}
.login-footer {
  text-align: center;
  font-size: var(--text-ui-sm);
  color: var(--color-text-tertiary);
}

/* ── PIN input (large tap target on tablet) ───────────── */
.pin-inp {
  width: 100%;
  height: 56px;
  padding: 0 var(--space-4);
  background: var(--color-surface-raised);
  border: var(--border-standard);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 28px;
  letter-spacing: 0.35em;
  color: var(--color-text-primary);
  text-align: center;
  transition: border-color var(--t-base);
}
.pin-inp:focus { outline: none; border: var(--border-focus); }
.pin-inp::placeholder { font-size: var(--text-ui-lg); letter-spacing: 0.05em; color: var(--color-text-tertiary); }

/* ── Footer ───────────────────────────────────────────── */
.d-footer {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  font-size: var(--text-ui-sm);
  color: var(--color-text-tertiary);
  border-top: var(--border-hairline);
}
.d-footer a { color: var(--color-accent); text-decoration: none; }
.d-footer a:hover { text-decoration: underline; }

/* ── Notes important highlight ────────────────────────── */
.notes-important td { background: var(--color-danger-subtle) !important; }

/* ── Responsive nav ───────────────────────────────────── */
@media (max-width: 768px) {
  .d-nav__toggle { display: flex; }
  .d-nav__links { display: none; }
  .d-nav__links.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--color-surface-raised);
    border-bottom: var(--border-hairline);
    box-shadow: var(--shadow-md);
    padding: var(--space-2) var(--space-4) var(--space-4);
    z-index: var(--z-overlay);
    gap: var(--space-1);
  }
  .d-nav__links.open a {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-ui-md);
    border-radius: var(--radius-md);
  }
  .d-page { padding: var(--space-6) var(--space-4) var(--space-12); }
  .d-header { margin-bottom: var(--space-5); }
}

/* ── Print ────────────────────────────────────────────── */
@media print {
  .d-nav, .d-footer, .d-toolbar, .btn, .modal-backdrop, .loading-overlay { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
