/* MHT Purchase Manager — base styles
 * Design tokens borrowed from source-of-truth (Fanshawe red #C8102E)
 * but trimmed to the essentials. Page modules can extend with their own
 * scoped styles; nothing here uses !important so overrides stay clean.
 */

:root {
  --c-fan-red:        #C8102E;
  --c-fan-red-dark:   #9b0c24;
  --c-fan-red-soft:   #fdecef;

  --c-text:           #1d1d1f;
  --c-text-muted:     #5b5b63;
  --c-bg:             #f5f6f8;
  --c-card:           #ffffff;
  --c-border:         #d9dbe0;
  --c-border-soft:    #ececef;

  --c-success:        #10783a;
  --c-success-soft:   #e8f5ee;
  --c-warning:        #b56700;
  --c-warning-soft:   #fff4e3;
  --c-danger:         #b3261e;
  --c-danger-soft:    #fdecea;
  --c-info:           #1a4fa3;
  --c-info-soft:      #eaf1fc;

  --radius:           8px;
  --radius-sm:        6px;
  --shadow-sm:        0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:        0 4px 16px rgba(0,0,0,0.08);

  --font-sans:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                      Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  --font-mono:        ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* Honor the [hidden] attribute everywhere. Browsers default to
 * `[hidden] { display: none }`, but a class rule like `.login-screen { display: flex }`
 * silently overrides it. Without this line, setting `el.hidden = true` in JS would
 * appear to do nothing on flex/grid elements. !important is appropriate here because
 * `hidden` is meant to be the final word from the markup. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

a { color: var(--c-fan-red); }
a:hover { color: var(--c-fan-red-dark); }

.muted { color: var(--c-text-muted); }
.error { color: var(--c-danger); }
.success { color: var(--c-success); }

/* ── Header ─────────────────────────────────────────────── */
.app-header {
  background: var(--c-fan-red);
  color: white;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  /* iOS PWA: respect notches/dynamic-island via safe-area inset. */
  padding-top: max(14px, env(safe-area-inset-top));
}
.app-header h1 { color: white; font-size: 1.2rem; line-height: 1.2; }
.app-header .subtitle { margin: 0; font-size: 0.85rem; opacity: 0.9; }
@media (max-width: 540px) {
  .app-header { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
  .app-header h1 { font-size: 1.05rem; }
  .app-header .subtitle { font-size: 0.78rem; }
  .brand-mark-icon { width: 32px; height: 32px; }
  .header-right .role-pill { display: none; }   /* save space on phones */
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.4);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
}
/* PWA icon variant — subtle white frame so the white-on-red icon reads
 * cleanly against the red header background without looking pasted-on. */
.brand-mark-icon {
  display: block;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.10);
  padding: 4px;
  border: 1px solid rgba(255,255,255,0.25);
}

.header-right {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.88rem;
}
.role-pill {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.btn-link {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.55);
  color: white;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.btn-link:hover { background: rgba(255,255,255,0.12); }

/* ── Login screen ───────────────────────────────────────── */
.login-screen {
  min-height: calc(100vh - 70px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px;
  max-width: 380px;
  width: 100%;
}
.login-card label { display: block; margin: 16px 0 6px; font-weight: 500; }
.login-card input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
}
.login-card button { margin-top: 18px; width: 100%; }

/* ── Tab bar ────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  padding: 0 24px;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  padding: 14px 18px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--c-text-muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--c-text); }
.tab-btn.active {
  color: var(--c-fan-red);
  font-weight: 600;
  border-bottom-color: var(--c-fan-red);
}

/* ── Pages ──────────────────────────────────────────────── */
#app-main { padding: 24px; max-width: 1280px; margin: 0 auto; }
.page { background: var(--c-card); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm); }
.page-header { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-header h2 { margin: 0; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 540px) {
  #app-main { padding: 12px; }
  .page { padding: 14px; }
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px;
  font: inherit; font-size: 0.92rem; font-weight: 500;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: white; color: var(--c-text);
  cursor: pointer;
  text-decoration: none;
  min-height: 38px;            /* tap target */
  touch-action: manipulation;  /* dodge 300ms double-tap delay on older mobile */
}
.btn:hover { border-color: var(--c-text-muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--c-fan-red); border-color: var(--c-fan-red); color: white; }
.btn-primary:hover { background: var(--c-fan-red-dark); border-color: var(--c-fan-red-dark); }

.btn-success { background: var(--c-success); border-color: var(--c-success); color: white; }
.btn-success:hover { filter: brightness(0.92); }

.btn-danger { background: var(--c-danger); border-color: var(--c-danger); color: white; }
.btn-danger:hover { filter: brightness(0.92); }

.btn-outline { background: white; }
.btn-sm { padding: 5px 10px; font-size: 0.85rem; }

/* ── Forms ──────────────────────────────────────────────── */
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 500; font-size: 0.92rem; }
.field input, .field select, .field textarea {
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 16px;             /* 16px stops iOS Safari from auto-zooming on focus */
  background: white;
  min-height: 42px;            /* WCAG-friendly tap target on touch devices */
}
@media (min-width: 769px) {
  /* Tighter spacing on desktop where 16px+42px feels too generous. */
  .field input, .field select, .field textarea { font-size: 0.95rem; padding: 8px 10px; min-height: 0; }
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--c-fan-red);
  outline-offset: -1px;
  border-color: var(--c-fan-red);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
@media (max-width: 640px) {
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
}

/* ── Tables ─────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.data-table th, .data-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--c-border-soft); white-space: nowrap; }
.data-table th { background: var(--c-bg); font-weight: 600; color: var(--c-text); position: sticky; top: 0; }
.data-table tbody tr:hover { background: var(--c-fan-red-soft); cursor: default; }
.data-table tbody tr.clickable { cursor: pointer; }
.table-scroll { max-height: 60vh; overflow: auto; border: 1px solid var(--c-border); border-radius: var(--radius-sm); -webkit-overflow-scrolling: touch; }
@media (max-width: 540px) {
  .data-table { font-size: 0.85rem; }
  .data-table th, .data-table td { padding: 7px 8px; }
}

/* ── Status badges ──────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-Requested { background: var(--c-info-soft);    color: var(--c-info); }
.badge-Verified  { background: var(--c-success-soft); color: var(--c-success); }
.badge-Approved  { background: var(--c-success-soft); color: var(--c-success); }
.badge-Ordered   { background: var(--c-warning-soft); color: var(--c-warning); }
.badge-Declined  { background: var(--c-danger-soft);  color: var(--c-danger); }

/* ── Toast ──────────────────────────────────────────────── */
.toast-host {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--c-text); color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  animation: toast-in 0.18s ease-out;
  font-size: 0.92rem;
}
.toast.success { background: var(--c-success); }
.toast.error   { background: var(--c-danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Modal (used by Tracking detail view + Admin confirms) ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 8000;
  padding: 20px;
}
.modal-card {
  background: white;
  border-radius: var(--radius);
  max-width: 720px; width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md);
}
.modal-header { padding: 14px 20px; border-bottom: 1px solid var(--c-border-soft); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--c-border-soft); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Filter bar (used by Tracking, Inventory, Admin) ──── */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar input, .filter-bar select { padding: 7px 10px; border: 1px solid var(--c-border); border-radius: var(--radius-sm); font-size: 0.9rem; }
.filter-bar input[type="search"] { min-width: 220px; }

/* ── Items table inside Requests form ─────────────────── */
.items-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.items-table th, .items-table td { padding: 6px; vertical-align: middle; }
.items-table th { font-size: 0.8rem; color: var(--c-text-muted); text-align: left; font-weight: 600; }
.items-table input { width: 100%; padding: 6px 8px; border: 1px solid var(--c-border); border-radius: 5px; font: inherit; font-size: 0.9rem; }
.items-table .col-qty   { width: 70px; }
.items-table .col-unit  { width: 80px; }
.items-table .col-price { width: 110px; }
.items-table .col-total { width: 110px; }
.items-table .col-rm    { width: 36px; text-align: center; }
.row-removable .btn-rm { background: transparent; border: none; color: var(--c-danger); font-size: 1.2rem; cursor: pointer; padding: 4px; }

/* On phones, transform the items table from row-of-cells into a stacked card.
 * Each item becomes a self-contained block: full-width item input on top,
 * then qty/unit/price as a 3-column flex row, then line total + remove on
 * their own row. The data-label attributes (set in requests.js) provide
 * tiny inline column titles since we hide the thead. */
@media (max-width: 540px) {
  .items-table, .items-table tbody, .items-table tr, .items-table td {
    display: block; width: 100%;
  }
  .items-table thead { display: none; }
  .items-table tr {
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 12px;
    background: white;
  }
  .items-table td {
    padding: 6px 0;
    width: auto !important;        /* override desktop fixed widths */
    text-align: left !important;   /* override per-cell text-align */
  }
  .items-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--c-text-muted);
    margin-bottom: 4px;
  }
  .items-table .col-item {
    margin-bottom: 4px;
  }
  /* Group qty/unit/price/total in a 4-up grid using a flex parent rule
   * applied via CSS sibling rather than DOM change. We use a wrapper:
   * since changing DOM in CSS isn't possible, we rely on flow: each
   * stacked, with qty/unit/price in a flex row via grouping. Simpler:
   * just stack everything and bump the inputs to full-width 16px. */
  .items-table input {
    font-size: 16px;        /* prevents iOS Safari auto-zoom on focus */
    padding: 10px 12px;
    min-height: 42px;       /* tap target */
  }
  /* Pack qty / unit / price as a 3-column row (the line total + rm get their own line). */
  .items-table .col-qty, .items-table .col-unit, .items-table .col-price {
    display: inline-block;
    width: calc(33.333% - 6px) !important;
    vertical-align: top;
    margin-right: 6px;
  }
  .items-table .col-price { margin-right: 0; }
  /* Line total + remove button share the bottom row, total left, × right. */
  .items-table .col-total {
    display: inline-block !important;
    width: calc(100% - 50px) !important;
    font-weight: 600;
    color: var(--c-fan-red);
    font-size: 1.05rem;
  }
  .items-table .col-rm {
    display: inline-block !important;
    width: 44px !important;
    text-align: right !important;
    vertical-align: bottom;
  }
  .row-removable .btn-rm {
    font-size: 1.6rem;       /* easier tap target */
    padding: 6px 10px;
  }
}

.totals-bar { display: flex; justify-content: flex-end; gap: 16px; padding: 10px 6px; font-weight: 600; }
.totals-bar .num { color: var(--c-fan-red); font-variant-numeric: tabular-nums; }
