@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@500;600;700&display=swap');

:root {
  --brand: #c92f32;       /* placeholder brand color — swap once real Legends Arena ProShop logo art arrives */
  --brand-dark: #a02426;
  --brand-light: #fdf1f1;
  --ink: #17130f;         /* near-black, matches the logo's lettering */
  --muted: #6b6560;
  --line: #e7e2de;
  --bg: #f6f4f2;
  --card: #ffffff;
  --ok: #1e8e5a;
  --err: #d93025;
  --radius: 14px;
  --heading-font: 'Oswald', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, .brand-word, .tile-label, .btn { font-family: var(--heading-font); }

/* ---------- app shell: persistent sidebar + main content ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line);
  border-top: 3px solid var(--brand); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 30;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.side-brand img.logo { width: 34px; height: 34px; border-radius: 50%; box-shadow: 0 0 0 2px var(--brand-light); }
.side-brand .brand-word { font-family: var(--heading-font); font-weight: 700; font-size: 14px; letter-spacing: .02em; text-transform: uppercase; line-height: 1.2; }
.side-nav { flex: 1; padding: 6px 10px; }
.side-section {
  font-family: var(--heading-font); font-size: 11px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted); padding: 16px 10px 6px;
}
.side-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: 10px;
  color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 500; margin-bottom: 2px;
}
.side-link:hover { background: var(--brand-light); }
.side-link.active { background: var(--brand); color: #fff; }
.side-emoji { font-size: 16px; width: 20px; text-align: center; }
.side-user {
  padding: 14px 18px; border-top: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; gap: 8px; font-size: 13px;
}
.side-user .iconbtn { padding: 6px 10px; font-size: 12px; }

.mobile-topbar {
  display: none; align-items: center; justify-content: space-between; padding: 12px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.mobile-topbar img.logo { width: 28px; height: 28px; border-radius: 50%; }

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

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-topbar { display: flex; }
}

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--line);
  border-top: 3px solid var(--brand);
  position: sticky; top: 0; z-index: 10;
}
.app-header .brand { display: flex; align-items: center; gap: 10px; }
.app-header .brand img.logo { width: 34px; height: 34px; border-radius: 50%; display: block; box-shadow: 0 0 0 2px var(--brand-light); }
.app-header .brand .brand-word { font-weight: 700; font-size: 16px; letter-spacing: .02em; text-transform: uppercase; }
.app-header nav { display: flex; gap: 8px; align-items: center; }
.iconbtn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 12px; border-radius: 10px; font-size: 14px; cursor: pointer; text-decoration: none;
}
.iconbtn:hover { border-color: var(--brand); color: var(--brand); }

/* 720px was fine for a lone entry form; Reports/Admin have since grown into
   wide tables and 15+ tabs that were clipping at that width. Entry forms
   themselves stay narrow (.container.narrow) since a 2-4 field form
   stretched across a wide screen just reads as empty space either side. */
.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 80px; }
.container.narrow { max-width: 720px; }

.page-title {
  font-family: var(--heading-font); font-weight: 600; font-size: 22px; letter-spacing: .01em;
  margin: 22px 0 2px; text-transform: uppercase;
}

.section-heading {
  font-family: var(--heading-font); font-size: 13px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin: 28px 0 4px;
}
.section-heading:first-of-type { margin-top: 18px; }

.picker-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 18px;
}
@media (min-width: 560px) { .picker-grid { grid-template-columns: repeat(3, 1fr); } }
.picker-tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 12px 18px; text-align: center; cursor: pointer; text-decoration: none; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  transition: transform .1s ease, box-shadow .1s ease, border-color .1s ease;
  position: relative; overflow: hidden;
}
.picker-tile::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--brand); transform: scaleX(0); transform-origin: left;
  transition: transform .15s ease;
}
.picker-tile:hover::before { transform: scaleX(1); }
.picker-tile:active { transform: scale(0.97); }
.picker-tile:hover { box-shadow: 0 6px 18px rgba(201,47,50,.12); border-color: #f0d5d5; }
.picker-tile .emoji-badge {
  width: 52px; height: 52px; border-radius: 50%; background: var(--brand-light);
  display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.picker-tile .tile-label { font-weight: 600; font-size: 13px; letter-spacing: .01em; text-transform: uppercase; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.report-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.report-actions .btn { width: auto; font-size: 12px; padding: 8px 12px; }
.card h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field label .req { color: var(--brand); }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(201,47,50,.12);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }

/* Item lines as a real spreadsheet-style table — one column per field,
   one row per item — instead of a stacked card per item. Column headers
   carry the labels, so the per-field <label> (still rendered by the shared
   field controllers, unchanged) is hidden here rather than duplicated. */
.items-table { border-collapse: collapse; width: 100%; min-width: 560px; }
.items-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 4px 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.items-table th .req { color: var(--brand); }
.items-table td { padding: 6px 8px; vertical-align: top; border-bottom: 1px solid var(--line); }
.items-table tr:last-child td { border-bottom: none; }
.items-table .field { margin: 0; min-width: 130px; }
.items-table .field label { display: none; }
.items-table input, .items-table select { padding: 9px 10px; font-size: 14px; }
.items-table .autocomplete input { min-width: 160px; }
.items-table .remove-line {
  border: none; background: none; color: var(--muted); font-size: 17px; cursor: pointer; padding: 8px 4px;
}
.items-table .remove-line:hover { color: var(--brand); }
.items-table .photo-list { max-width: 180px; }

.autocomplete { position: relative; }
/* left/top/width are set inline in JS (position: fixed, viewport-relative)
   so the dropdown isn't clipped by a scrolling ancestor — e.g. the
   horizontal-scroll wrapper around the item-entry table. */
.ac-list {
  position: fixed; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.08);
  max-height: 220px; overflow-y: auto; z-index: 210; display: none;
}
.ac-list.open { display: block; }
.ac-item { padding: 10px 12px; cursor: pointer; font-size: 14px; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.ac-item:hover, .ac-item.active { background: var(--brand-light); }
.ac-item.quickadd { color: var(--brand); font-weight: 600; border-top: 1px solid var(--line); }
.ac-detail { color: var(--muted); font-size: 12.5px; white-space: nowrap; }

.items-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.items-toolbar .btn { width: auto; flex: 1 1 auto; font-size: 12px; padding: 11px 14px; }

/* Details + Items now live in one card (one form, not two floating boxes)
   — a divider marks the section break instead of a gap between cards. */
#itemsCard { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(23,19,15,.45); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal { background: #fff; border-radius: var(--radius); padding: 20px; width: 100%; max-width: 560px; border-top: 4px solid var(--brand); }
.modal h3 { margin: 0 0 6px; font-family: var(--heading-font); text-transform: uppercase; letter-spacing: .03em; font-size: 15px; }
.modal textarea {
  width: 100%; margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical;
}
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { width: auto; flex: 1; }

.payment-row { margin-bottom: 10px; }
.payment-row-main { display: flex; gap: 10px; align-items: center; }
.payment-row-main select { flex: 1.2; } .payment-row-main input { flex: 1; }
.payment-row .rm { border: none; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.payment-recon { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; padding-left: 4px; }
.payment-recon input[type=text] { flex: 1; min-width: 140px; }
.recon-photo-btn {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--brand);
  border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; white-space: nowrap;
}
.recon-photo-btn:hover { background: var(--brand-light); }
.total-line { font-size: 13px; color: var(--muted); margin-top: 4px; }
.total-line.ok { color: var(--ok); }
.total-line.err { color: var(--err); }
.link-btn { border: none; background: none; padding: 0; color: var(--brand); text-decoration: underline; font-size: inherit; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 12px; padding: 13px 18px; font-size: 14px; font-weight: 600;
  letter-spacing: .03em; text-transform: uppercase; cursor: pointer; width: 100%;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px dashed var(--line); }
.btn-ghost { background: none; color: var(--brand); padding: 8px; width: auto; text-transform: none; letter-spacing: normal; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

.error-text { color: var(--err); font-size: 13px; margin-top: 6px; }
.muted { color: var(--muted); font-size: 13px; }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
table.simple th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; white-space: nowrap; }
.table-scroll { overflow-x: auto; }
.access-grid th, .access-grid td { white-space: nowrap; }
.scope-badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
}
.scope-badge.header { background: var(--brand-light); color: var(--brand-dark); }
.scope-badge.item { background: #eef1f4; color: var(--muted); }
.scope-badge.status-pending, .scope-badge.status-open { background: #fdf1de; color: #a05a00; }
.scope-badge.status-approved, .scope-badge.status-received { background: #e4f4ec; color: var(--ok); }
.scope-badge.status-rejected, .scope-badge.status-cancelled { background: #fbe6e5; color: var(--err); }
.scope-badge.status-partial { background: #e3edfa; color: #1a5ea8; }

.day-status {
  padding: 12px 16px; border-radius: 12px; font-size: 14px; margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.day-status.open { background: #e4f4ec; color: var(--ok); }
.day-status.closed { background: #fbe6e5; color: var(--err); }
.day-status .btn { width: auto; padding: 8px 16px; font-size: 12.5px; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--brand-light); }

.photo-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.photo-chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--brand-light); color: var(--brand-dark);
  padding: 5px 8px; border-radius: 8px; font-size: 12px;
}
.photo-chip button { border: none; background: none; color: var(--brand-dark); cursor: pointer; font-size: 14px; line-height: 1; padding: 0; }

/* padding-bottom gives the scrollbar its own strip below the pills instead
   of overlapping their text; the thin custom scrollbar keeps that strip
   small instead of the OS's full-size (often opaque) default. */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 12px; scrollbar-width: thin; }
.tabs::-webkit-scrollbar { height: 6px; }
.tabs::-webkit-scrollbar-track { background: transparent; }
.tabs::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.tabs::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.tabs button {
  border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 999px;
  font-size: 13px; white-space: nowrap; cursor: pointer; font-weight: 500;
}
.tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
/* The second-level row (a section's own report tabs) reads as nested under
   the section pills above it — smaller and brand-toned instead of a second
   identical black-on-active row. */
.tabs.sub-tabs { margin-top: -8px; }
.tabs.sub-tabs button { padding: 6px 12px; font-size: 12.5px; background: var(--bg); }
.tabs.sub-tabs button.active { background: var(--brand); border-color: var(--brand); }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle at 50% 0%, #fff 0%, var(--bg) 65%);
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 18px; padding: 34px 26px 30px;
  box-shadow: 0 16px 50px rgba(23,19,15,.10); border-top: 4px solid var(--brand); text-align: center;
}
.login-card img.logo { width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 16px; display: block; box-shadow: 0 0 0 4px var(--brand-light); }
.login-card h1 {
  font-family: var(--heading-font); font-weight: 700; font-size: 22px; letter-spacing: .04em;
  margin: 0 0 4px; text-transform: uppercase;
}
.login-card p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: 13px; letter-spacing: .02em; }
.login-card .field { text-align: left; }

/* ---------- overview dashboard: stat tiles + charts ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat-tile .stat-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.stat-tile .stat-value { font-family: var(--heading-font); font-size: 26px; font-weight: 600; }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-grid .card { margin-bottom: 0; }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.mini-list li:last-child { border-bottom: none; }
.mini-list .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; margin-right: 8px; flex-shrink: 0; }
.mini-list .row-label { display: flex; align-items: center; color: var(--ink); }
.mini-list .row-value { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .bar-label { width: 96px; flex-shrink: 0; font-size: 13px; color: var(--muted); }
.bar-row .bar-track { flex: 1; background: var(--brand-light); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-row .bar-fill { background: var(--brand); height: 100%; border-radius: 999px; }
.bar-row .bar-value { width: 64px; text-align: right; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- print ---------- */
@media print {
  .sidebar, .mobile-topbar, .tabs, .report-actions, .no-print, .btn { display: none !important; }
  .main { margin: 0 !important; }
  body { background: #fff; }
  .card { border: none; box-shadow: none; padding: 0; margin-bottom: 24px; page-break-inside: avoid; }
  .container { max-width: none; padding: 0; }
  table.simple th, table.simple td { padding: 6px 4px; }
  /* A report opened inside a detail modal (e.g. the Customer Ledger
     statement) should print as a plain page, not a floating overlay. */
  .modal-backdrop { position: static; background: none; padding: 0; display: block; }
  .modal { max-width: none; border-top: none; padding: 0; }
}

/* ---------- thermal receipt (80mm printers, e.g. BlackCopper) ---------- */
.receipt-modal .modal { max-width: 340px; }
#receiptArea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: #000;
  width: 100%; line-height: 1.5;
}
#receiptArea .r-center { text-align: center; }
#receiptArea .r-logo { width: 44px; height: 44px; border-radius: 50%; margin: 0 auto 6px; display: block; }
#receiptArea .r-title { font-weight: 700; font-size: 15px; }
#receiptArea .r-line { border-top: 1px dashed #000; margin: 8px 0; }
#receiptArea .r-row { display: flex; justify-content: space-between; gap: 8px; }
#receiptArea .r-total { font-weight: 700; font-size: 14px; }

@media screen {
  #receiptPrintOnly { display: none; }
}
@media print {
  body.printing-receipt > *:not(#receiptPrintOnly) { display: none !important; }
  #receiptPrintOnly { display: block !important; }
  @page { size: 80mm auto; margin: 3mm; }
}
