/* ---------------------------------------------------------------------------
   YML Refinery brand system (from ymlrefinery.com)
   Fonts: Raleway (headings/UI) + Lato (body)
   --------------------------------------------------------------------------- */
:root {
  --gold: #c9a84c;
  --gold-light: #e0c36a;
  --gold-dark: #a8872f;
  --bg-darkest: #0d0d0d;
  --bg-dark: #141414;
  --bg-mid: #1c1c1c;
  --bg-card: #222222;
  --bg-card-hover: #2a2a2a;
  --text-primary: #f0ece0;
  --text-secondary: #a89f8c;
  --text-muted: #6b6356;
  --border: #2e2a24;
  --border-gold: rgba(201, 168, 76, 0.3);
  --white: #ffffff;
  --font-head: 'Raleway', sans-serif;
  --font-body: 'Lato', sans-serif;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  --shadow-gold: 0 0 24px rgba(201, 168, 76, 0.15);

  /* semantic aliases used throughout the app */
  --bg: var(--bg-dark);
  --panel: var(--bg-mid);
  --panel-2: var(--bg-card);
  --line: var(--border);
  --text: var(--text-primary);
  --muted: var(--text-secondary);
  --silver: #cfd4dc;
  --green: #4bb96a;
  --red: #e5645a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.6 var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 24px;
  background: linear-gradient(180deg, var(--bg-mid), var(--bg-dark));
  border-bottom: 1px solid var(--border-gold);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 14px; }
.logo { text-decoration: none; }
.logo-text {
  font-family: var(--font-head); font-size: 1.5rem; font-weight: 900;
  color: var(--text-primary); letter-spacing: 0.05em; text-transform: uppercase;
}
.logo-text em { font-style: normal; color: var(--gold); }
.title {
  font-family: var(--font-head); font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; font-size: 0.8rem; color: var(--text-secondary);
}
.spot { display: flex; align-items: center; gap: 16px; }
.spot-item { display: flex; flex-direction: column; align-items: flex-end; }
.spot-label {
  font-family: var(--font-head); font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px; font-weight: 700;
}
.spot-val { font-family: var(--font-head); font-weight: 800; font-variant-numeric: tabular-nums; }
#spotGold { color: var(--gold); }
#spotSilver { color: var(--silver); }
.spot-meta { font-size: 11px; color: var(--text-muted); min-width: 84px; }

/* Summary cards */
.summary {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; padding: 20px 24px;
}
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.card.click { cursor: pointer; transition: border-color 0.2s ease; }
.card.click:hover { border-color: var(--gold); }
.card.cashcard { background: linear-gradient(180deg, rgba(201, 168, 76, 0.07), var(--bg-card)); border-color: var(--border-gold); }
.card-sub { font-size: 10px; color: var(--text-muted); margin-top: 4px; }
.card-label {
  font-family: var(--font-head); font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px; font-weight: 700;
}
.card-val {
  font-family: var(--font-head); font-size: 20px; font-weight: 800;
  margin-top: 6px; font-variant-numeric: tabular-nums; color: var(--text-primary);
}

/* Tabs */
.tabs { display: flex; gap: 6px; padding: 0 24px; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; color: var(--text-secondary);
  padding: 12px 18px; cursor: pointer; font-family: var(--font-head);
  font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }

main { padding: 20px 24px 60px; }
.tabpane { display: none; }
.tabpane.active { display: block; }

.pane-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.hint { color: var(--text-muted); font-size: 12px; }
.search {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: var(--radius-sm); min-width: 240px; font-family: var(--font-body);
}
.search:focus, .field input:focus, .field select:focus { outline: none; border-color: var(--gold); }
.chk { color: var(--text-secondary); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.chk input { accent-color: var(--gold); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  background: var(--bg-card); color: var(--text-muted); font-family: var(--font-head);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px;
  position: sticky; top: 0;
}
tbody tr:hover { background: var(--bg-card-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions-col { text-align: right; }
.pill {
  font-family: var(--font-head); font-size: 10px; padding: 3px 9px; border-radius: 20px;
  font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
}
.pill.gold { background: rgba(201, 168, 76, 0.16); color: var(--gold); border: 1px solid var(--border-gold); }
.pill.silver { background: rgba(207, 212, 220, 0.12); color: var(--silver); border: 1px solid rgba(207, 212, 220, 0.25); }
.pill.cash { background: rgba(75, 185, 106, 0.14); color: var(--green); border: 1px solid rgba(75, 185, 106, 0.3); }
.pill.check { background: rgba(47, 129, 247, 0.14); color: #6aa5f8; border: 1px solid rgba(47, 129, 247, 0.3); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--text-muted); }

/* Buttons */
.btn {
  background: var(--gold); color: var(--bg-darkest); border: 2px solid var(--gold);
  border-radius: var(--radius-sm); padding: 9px 18px; cursor: pointer;
  font-family: var(--font-head); font-weight: 700; font-size: 12px;
  letter-spacing: 0.04em; text-transform: uppercase; transition: all 0.2s ease;
}
.btn:hover { background: var(--gold-light); border-color: var(--gold-light); }
.btn.small { padding: 6px 12px; font-size: 11px; }
.btn.ghost {
  background: transparent; border: 2px solid rgba(240, 236, 224, 0.25); color: var(--text-primary);
}
.btn.ghost:hover { border-color: var(--gold); color: var(--gold); background: transparent; }
.btn.buy { background: var(--green); border-color: var(--green); color: var(--bg-darkest); }
.btn.buy:hover { filter: brightness(1.12); }
.btn.sell { background: var(--gold); border-color: var(--gold); color: var(--bg-darkest); }
.btn.danger { background: var(--red); border-color: var(--red); color: var(--white); }
.btn.danger:hover { filter: brightness(1.1); }
.btn:disabled { cursor: default; }
.row-actions { display: inline-flex; gap: 6px; }

/* Segmented control */
.seg { display: inline-flex; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.segbtn {
  background: none; border: none; color: var(--text-secondary); padding: 9px 16px; cursor: pointer;
  font-family: var(--font-head); font-weight: 700; text-transform: uppercase; font-size: 12px; letter-spacing: 0.04em;
}
.segbtn.active { background: var(--gold); color: var(--bg-darkest); }

/* Modal */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .7);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.backdrop.hidden { display: none; }
.modal {
  background: var(--bg-mid); border: 1px solid var(--border-gold); border-radius: var(--radius);
  padding: 24px; width: 440px; max-width: calc(100vw - 40px); max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow), var(--shadow-gold);
}
.modal h3 { font-family: var(--font-head); font-weight: 800; margin: 0 0 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.modal .sub { color: var(--text-secondary); font-size: 12px; margin-bottom: 18px; }
.field { margin-bottom: 14px; }
.field label {
  display: block; font-family: var(--font-head); font-size: 11px; color: var(--text-secondary);
  margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700;
}
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: var(--radius-sm); font-size: 14px; font-family: var(--font-body);
}
.field .est { font-size: 12px; color: var(--gold); margin-top: 4px; min-height: 16px; }
.est { font-size: 12px; color: var(--gold); min-height: 16px; margin-bottom: 12px; }
.valbox {
  background: rgba(201, 168, 76, 0.08); border: 1px solid var(--border-gold);
  border-radius: var(--radius-sm); padding: 11px 13px; margin-bottom: 14px; font-size: 13px;
}
.valbox strong { color: var(--gold); font-family: var(--font-head); font-size: 16px; }
.valrow { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; }
.valrow span { color: var(--text-secondary); font-size: 12px; }
.valrow strong { color: var(--text-primary); font-family: var(--font-head); font-size: 15px; }
.valrow.hi strong { color: var(--gold); }
.btn.large { padding: 11px 22px; font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------------------------------------------------------------------------
   Views (Register / Manage) + POS register
   --------------------------------------------------------------------------- */
.view { display: none; }
.view.active { display: block; }

.modeswitch { display: inline-flex; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.modeswitch .mode {
  background: none; border: none; color: var(--text-secondary); padding: 9px 22px; cursor: pointer;
  font-family: var(--font-head); font-weight: 800; text-transform: uppercase; font-size: 13px; letter-spacing: 0.05em;
}
.modeswitch .mode:hover { color: var(--text-primary); }
.modeswitch .mode.active { background: var(--gold); color: var(--bg-darkest); }

/* POS layout — .pos itself is the green-number class, so the container is .pos-wrap */
.pos-wrap {
  display: grid; grid-template-columns: 1fr 380px; gap: 18px;
  padding: 18px 24px 40px; align-items: start;
}

/* Mode buttons — the front-and-center Buy / Sell */
.pos-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.pos-mode {
  border: 2px solid var(--border); background: var(--bg-card); border-radius: var(--radius);
  padding: 14px; cursor: pointer; text-align: center; transition: all 0.15s ease;
}
.pos-mode-title { display: block; font-family: var(--font-head); font-weight: 900; font-size: 20px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }
.pos-mode-sub { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.pos-mode.buymode:hover { border-color: var(--green); }
.pos-mode.sellmode:hover { border-color: var(--gold); }
.pos-mode.buymode.active { background: rgba(75, 185, 106, 0.14); border-color: var(--green); }
.pos-mode.buymode.active .pos-mode-title { color: var(--green); }
.pos-mode.sellmode.active { background: rgba(201, 168, 76, 0.14); border-color: var(--gold); }
.pos-mode.sellmode.active .pos-mode-title { color: var(--gold); }

.pos-filter { display: flex; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.pos-filter .search { flex: 1; min-width: 180px; }

/* Product tiles */
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.pos-tile {
  border: 1px solid var(--border); background: var(--bg-card); border-radius: var(--radius);
  padding: 12px; cursor: pointer; text-align: left; transition: border-color 0.12s ease, transform 0.06s ease;
  display: flex; flex-direction: column; gap: 5px; min-height: 96px;
  color: var(--text-primary); font-family: var(--font-body);
}
.pos-tile:hover { border-color: var(--gold); }
.pos-tile:active { transform: scale(0.98); }
.pos-tile.disabled { opacity: 0.35; pointer-events: none; }
.pos-tile-name { font-size: 13px; font-weight: 700; color: var(--text-primary); line-height: 1.3; }
.pos-tile-price { font-family: var(--font-head); font-weight: 800; font-size: 16px; color: var(--gold); margin-top: auto; font-variant-numeric: tabular-nums; }
.pos-tile-sub { font-size: 11px; color: var(--text-muted); }
.pos-grid .ticket-empty { grid-column: 1 / -1; }

/* Ticket */
.pos-ticket {
  background: var(--bg-mid); border: 1px solid var(--border-gold); border-radius: var(--radius);
  box-shadow: var(--shadow); position: sticky; top: 76px;
  display: flex; flex-direction: column; max-height: calc(100vh - 96px);
}
.ticket-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.ticket-head h3 { margin: 0; font-family: var(--font-head); font-weight: 900; font-size: 15px; text-transform: uppercase; letter-spacing: 0.04em; }
.ticket-head h3.buying { color: var(--green); }
.ticket-head h3.selling { color: var(--gold); }
.ticket-lines { flex: 1; overflow-y: auto; padding: 4px 0; min-height: 120px; }
.ticket-empty { color: var(--text-muted); text-align: center; padding: 36px 16px; font-size: 13px; }
.tline { border-bottom: 1px solid var(--border); padding: 14px 16px; }
.tline-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tline-name { font-size: 16px; font-weight: 700; }
.tline-x { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 22px; padding: 0 6px; }
.tline-x:hover { color: var(--red); }
.tline-ctl { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.qty-step { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.qty-step button {
  background: var(--bg-card); border: none; color: var(--text-primary); width: 44px; height: 44px;
  cursor: pointer; font-size: 22px; font-weight: 700;
}
.qty-step button:hover { background: var(--bg-card-hover); color: var(--gold); }
.qty-step .qv { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; }
.tline-price {
  width: 128px; background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 10px 10px; border-radius: 8px; font-size: 17px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums;
}
.tline-x { margin-left: auto; }
.tline-total { font-family: var(--font-head); font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tline-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.ticket-foot { border-top: 1px solid var(--border); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.ticket-margin { font-size: 12px; color: var(--text-secondary); min-height: 15px; }
.ticket-total { display: flex; justify-content: space-between; align-items: baseline; }
.ticket-total span { font-family: var(--font-head); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-secondary); font-weight: 700; }
.ticket-total strong { font-family: var(--font-head); font-size: 28px; font-weight: 900; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ticket-payrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ticket-cash { font-size: 11px; color: var(--text-muted); text-align: right; }
.btn.xl { width: 100%; padding: 15px 20px; font-size: 15px; border-radius: var(--radius); }
.btn.xl.sell { background: var(--gold); border-color: var(--gold); color: var(--bg-darkest); }
.btn.xl:disabled { opacity: 0.45; }

/* Floating ticket bar (mobile): jump from the grid to the ticket */
.ticket-fab { display: none; }

/* Receipt */
.receipt {
  background: #f7f5f0; color: #151310; border-radius: 6px; padding: 20px 22px;
  font-size: 13px; line-height: 1.5;
}
.r-head { text-align: center; margin-bottom: 4px; }
.r-logo { font-family: var(--font-head); font-weight: 900; font-size: 20px; letter-spacing: 0.06em; text-transform: uppercase; }
.r-logo em { font-style: normal; color: var(--gold-dark); }
.r-sub { font-size: 11px; color: #6b6356; }
.r-type {
  text-align: center; font-family: var(--font-head); font-weight: 800; font-size: 12px;
  letter-spacing: 0.08em; margin: 10px 0 2px; text-transform: uppercase;
  border-top: 1px dashed #b5ac9c; border-bottom: 1px dashed #b5ac9c; padding: 6px 0;
}
.r-meta { text-align: center; font-size: 11px; color: #6b6356; margin-bottom: 10px; }
.r-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.r-table th, .r-table td { padding: 4px 4px; border-bottom: none; font-size: 12px; color: #151310; background: none; white-space: normal; }
.r-table th { font-family: var(--font-head); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #6b6356; border-bottom: 1px solid #b5ac9c; position: static; }
.r-table .num { text-align: right; }
.r-total {
  display: flex; justify-content: space-between; border-top: 1px dashed #b5ac9c;
  padding-top: 8px; font-family: var(--font-head); font-weight: 900; font-size: 16px;
}
.r-pay { text-align: right; font-size: 12px; margin-top: 2px; }
.r-thanks { text-align: center; margin-top: 12px; font-size: 12px; color: #6b6356; }

@media print {
  body * { visibility: hidden !important; }
  .receipt, .receipt * { visibility: visible !important; }
  .receipt {
    position: fixed; left: 0; top: 0; width: 100%;
    background: #fff !important; border-radius: 0; padding: 10px;
  }
  .no-print { display: none !important; }
}

/* Auth */
.userbox { display: flex; align-items: center; gap: 10px; }
.userbadge {
  font-family: var(--font-head); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--gold);
  border: 1px solid var(--border-gold); border-radius: 20px; padding: 4px 12px;
}
.login-modal { width: 340px; }
.login-brand { text-align: center; margin-bottom: 6px; }
#loginOverlay { background: rgba(0, 0, 0, 0.85); }

/* Store role: no dashboard, no reports, no admin, no audit */
body.role-store .summary { display: none; }
body.role-store .tab[data-tab="reports"],
body.role-store .tab[data-tab="admin"],
body.role-store .tab[data-tab="audit"] { display: none; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border-gold); padding: 11px 18px;
  border-radius: var(--radius-sm); z-index: 60; box-shadow: var(--shadow);
  font-family: var(--font-head); font-weight: 600; font-size: 13px;
}
.toast.hidden { display: none; }
.toast.err { border-color: var(--red); color: #ffb4ae; }
.toast.ok { border-color: var(--gold); }

/* ---------------------------------------------------------------------------
   Mobile
   --------------------------------------------------------------------------- */
@media (max-width: 900px) {
  /* Top bar: logo + user on row one, Register/Manage full width, spot below */
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px 12px; }
  .title { display: none; }
  .logo-text { font-size: 1.15rem; }
  .brand { order: 1; }
  .userbox { order: 2; margin-left: auto; }
  .modeswitch { order: 3; width: 100%; display: flex; }
  .mode { flex: 1; padding: 11px 0; }
  .spot { order: 4; width: 100%; justify-content: space-between; gap: 10px; }
  .spot-meta { display: none; }

  /* POS stacks; ticket flows under the grid */
  .pos-wrap { grid-template-columns: 1fr; padding: 14px 14px 90px; }
  .pos-ticket { position: static; max-height: none; }
  .pos-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .pos-mode-title { font-size: 17px; }
  .pos-filter .search { min-width: 0; width: 100%; }

  /* Floating "view ticket" pill once something's on the ticket */
  .ticket-fab.has-items {
    display: flex; position: fixed; left: 14px; right: 14px; bottom: 14px; z-index: 40;
    justify-content: space-between; align-items: center; gap: 10px;
    background: var(--gold); color: var(--bg-darkest); border: none; border-radius: 10px;
    padding: 15px 18px; font-family: var(--font-head); font-weight: 800; font-size: 15px;
    text-transform: uppercase; letter-spacing: 0.03em; cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  }

  /* Manage view */
  .summary { grid-template-columns: repeat(2, 1fr); padding: 14px; gap: 10px; }
  .card-val { font-size: 17px; }
  .tabs { overflow-x: auto; padding: 0 14px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; padding: 12px 12px; }
  main { padding: 14px 14px 60px; }
  .pane-head .search { min-width: 0; flex: 1; }

  /* iOS zooms into any input under 16px — keep fields at 16px+ */
  input, select, textarea { font-size: 16px !important; }

  /* Modals: stack side-by-side fields, use the full width */
  .modal { width: calc(100vw - 28px); padding: 18px; }
  .two-col { grid-template-columns: 1fr; gap: 0; }
}
