/* style.css : Stage 2 - same dark esports theme as BEAD//EDITOR */

/* ===== 1. Theme colours (same as the editor) ===== */
:root {
  --bg: #121317;
  --panel: #1b1d23;
  --box: #23262e;
  --line: #2f333d;
  --text: #e6e6e6;
  --muted: #8b919c;
  --accent: #ff7a1a;
  --accent-dim: #ff7a1a33;
  --red: #ff4d4d;   --red-dim: #ff4d4d26;
  --yellow: #ffc83d; --yellow-dim: #ffc83d1f;
  --blue: #4da3ff;  --blue-dim: #4da3ff22;
  --left-w: 300px;
  --right-w: 390px;
  --top-h: 52px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  overflow: hidden;
}
input, textarea, button { font: inherit; }

/* ===== 2. Top bar ===== */
.topbar {
  height: var(--top-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 800; font-size: 20px; letter-spacing: 2px; white-space: nowrap; }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); }
.top-stats { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.top-stats b { color: var(--text); }
.top-stats .warn { color: var(--yellow); }

/* ===== 3. Three columns ===== */
.app {
  display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  height: calc(100vh - var(--top-h));
}
.panel { background: var(--panel); padding: 12px; overflow-y: auto; }
.panel.left  { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }

.box {
  background: var(--box);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.box h2 {
  margin: 0 0 10px;
  font-size: 13px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--accent);
  display: flex; justify-content: space-between; align-items: center;
}
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.hint-inline { color: var(--muted); font-size: 12px; }
.badge {
  font-size: 10px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 6px; text-transform: none; letter-spacing: 0;
}
.badge.ok { color: #6fdc8c; border-color: #6fdc8c55; }

/* ===== 4. Buttons and inputs ===== */
.btn {
  background: #2b2f38; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-dim); }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary {
  width: 100%; margin-top: 10px; padding: 10px;
  background: var(--accent); color: #111; border-color: var(--accent);
  font-weight: 800; letter-spacing: .5px;
}
.btn.primary:hover:not(:disabled) { background: #ff9447; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.mini { padding: 3px 7px; font-size: 12px; }
.file-btn { text-align: center; }
#clearBtn:hover:not(:disabled) { border-color: var(--red); background: var(--red-dim); color: #ff8080; }

input[type=text], input[type=number], input[type=search], textarea {
  width: 100%; padding: 6px 8px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; font-family: Consolas, monospace; font-size: 13px; }
.check { display: block; margin: 8px 0; color: var(--muted); font-size: 13px; }
.check input { accent-color: var(--accent); }
.field-col { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field { display: flex; justify-content: space-between; align-items: center; gap: 8px;
         margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.field input { width: 80px; }
.btn-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }

/* segmented switch (same as the editor's sort switch) */
.seg { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 8px;
       border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg-btn { background: #2b2f38; color: var(--muted); border: 0; padding: 6px; cursor: pointer; font-size: 12px; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--accent); color: #111; font-weight: 700; }

/* ===== 5. Picture box ===== */
.drop {
  display: flex; align-items: center; justify-content: center;
  min-height: 130px; padding: 8px;
  border: 2px dashed var(--line); border-radius: 8px;
  background: var(--bg); cursor: pointer; text-align: center;
  color: var(--muted); line-height: 1.6;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-dim); }
.drop b { color: var(--accent); }
#preview { max-width: 100%; max-height: 260px; display: block; border-radius: 4px; }
.drop.has-pic { min-height: 0; border-style: solid; }
.drop.has-pic .drop-text { display: none; }

.sum { margin: 10px 0 0; font-size: 13px; color: var(--muted); line-height: 1.5; }
.sum b { color: var(--text); }
.sum .bad { color: var(--red); font-weight: 700; }
.sum .warn { color: var(--yellow); }

/* ===== 6. Middle: results ===== */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.zoombar {
  display: flex; align-items: center; gap: 12px;
  height: 44px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.bar-title { font-size: 13px; letter-spacing: 1px; text-transform: uppercase; color: var(--accent); white-space: nowrap; }
#exportResBtn { margin-left: auto; }
#addRowBtn, #exportResBtn { white-space: nowrap; }
.legend-key { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.legend-key i { width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; display: inline-block; }
.k-short { background: var(--red); } .k-new { background: var(--blue); } .k-check { background: var(--yellow); }

.stage-scroll { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.results { max-width: 980px; margin: 0 auto; }

/* one row = one colour. Same columns for the header and every row. */
.res-head, .res-row {
  display: grid;
  grid-template-columns: 120px 140px 84px 130px minmax(120px, 1fr) 32px;
  gap: 10px; align-items: center;
}
.res-head { padding: 0 10px 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.res-head:has(+ #resRows:empty) { display: none; }
.res-row {
  background: var(--box); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 6px;
}
.res-row.check { border-left-color: var(--yellow); }
.res-row.new   { border-left-color: var(--blue); }
.res-row.short { border-left-color: var(--red); background: linear-gradient(90deg, var(--red-dim), var(--box) 70%); border-color: #ff4d4d66; }
.res-row.reading { opacity: .55; }

.crop { width: 120px; height: 64px; background: #fff; border-radius: 6px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.crop img { max-width: 100%; max-height: 100%; display: block; }
.code-cell { display: flex; align-items: center; gap: 6px; }
.code-cell input { font-weight: 800; font-size: 16px; text-transform: uppercase; padding: 5px 6px; min-width: 0; }
.count-cell input { font-weight: 700; font-size: 16px; text-align: right; padding: 5px 6px; }
.res-row.warn input { border-color: var(--yellow); }   /* something to check (also on red "not enough" rows) */

/* two half dots: left = colour in the picture, right = the MARD colour of the code */
.pair { position: relative; width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%; overflow: hidden; border: 1px solid #0006; }
.pair i { position: absolute; top: 0; bottom: 0; width: 50%; }
.pair i:first-child { left: 0; } .pair i:last-child { right: 0; }

.stock-cell { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.stock-cell b { color: var(--text); font-size: 15px; }
.res-row.short .stock-cell b { color: var(--red); }
.stock-cell .warn { color: var(--yellow); }
.note { font-size: 12px; color: var(--muted); line-height: 1.4; }
.note .tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; margin: 0 4px 2px 0; }
.tag.short { background: var(--red); color: #111; }
.tag.new   { background: var(--blue-dim); color: var(--blue); }
.tag.check { background: var(--yellow-dim); color: var(--yellow); }
.tag.fixed { background: var(--yellow-dim); color: var(--yellow); }
.tag.dup   { background: #ffffff14; color: var(--text); }
.sugg { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.sugg .btn { display: inline-flex; align-items: center; gap: 4px; }
.sugg .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid #0006; }
.del { width: 32px; height: 32px; padding: 0; color: var(--muted); font-size: 16px; }
.del:hover:not(:disabled) { color: #ff8080; border-color: var(--red) !important; background: var(--red-dim) !important; }

.empty { text-align: center; padding: 70px 20px; border: 2px dashed var(--line); border-radius: 12px; }
.empty-big { font-size: 22px; font-weight: 700; margin-bottom: 10px; }
.empty-big b { color: var(--accent); }
#resRows:not(:empty) + .empty { display: none; }

/* ===== 7. Right: stock ===== */
.search { margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip-btn { background: #2b2f38; color: var(--muted); border: 1px solid var(--line); border-radius: 12px;
            padding: 2px 9px; font-size: 12px; cursor: pointer; }
.chip-btn:hover { color: var(--text); border-color: var(--accent); }
.chip-btn.active { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }

.stock-head, .stock-row {
  display: grid; grid-template-columns: 20px 46px 1fr 58px 64px 26px; gap: 6px; align-items: center;
}
.stock-head { color: var(--muted); font-size: 11px; padding: 0 6px 4px; }
.stock-list { max-height: calc(100vh - 380px); min-height: 120px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.stock-row { padding: 3px 6px; border-radius: 6px; border: 1px solid transparent; }
.stock-row:hover { border-color: var(--line); background: #ffffff06; }
.stock-row .dot { width: 18px; height: 18px; border-radius: 50%; border: 1px solid #0006; }
.stock-row .code { font-weight: 700; }
.stock-row input { padding: 3px 6px; text-align: right; font-variant-numeric: tabular-nums; }
.stock-row .low-in { color: var(--muted); }
.stock-row.low { background: var(--yellow-dim); }
.stock-row.low .qty-in { color: var(--yellow); border-color: #ffc83d66; }
.stock-row.out { background: var(--red-dim); }
.stock-row.out .qty-in { color: #ff8080; border-color: #ff4d4d66; }
.stock-row .x { width: 26px; height: 26px; padding: 0; color: var(--muted); background: none; border-color: transparent; }
.stock-row .x:hover { color: #ff8080; }
.stock-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 20px 6px; }
.add-row { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 6px; margin-top: 10px; }
.add-row input { text-transform: uppercase; }

/* ===== 8. History ===== */
.history { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 560px); min-height: 80px; overflow-y: auto; }
.rec { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; background: #ffffff05; }
.rec-top { display: flex; align-items: center; gap: 6px; }
.rec-top .t { color: var(--muted); font-size: 11px; }
.rec-top .btn { margin-left: auto; }
.rec .name { font-weight: 700; margin: 3px 0 1px; cursor: pointer; }
.rec .meta { color: var(--muted); cursor: pointer; }
.rec .meta .minus { color: #ff8080; } .rec .meta .plus { color: #6fdc8c; }
.rec.undone { opacity: .5; } .rec.undone .name { text-decoration: line-through; }
.type { font-size: 10px; font-weight: 800; padding: 1px 5px; border-radius: 3px; text-transform: uppercase; letter-spacing: .5px; }
.type.deduct { background: var(--accent-dim); color: var(--accent); }
.type.restock, .type.import { background: #6fdc8c22; color: #6fdc8c; }
.type.edit, .type.restore { background: #ffffff14; color: var(--muted); }
.rec-items { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
.rec-items span { padding: 1px 6px; border-radius: 9px; background: var(--bg); font-variant-numeric: tabular-nums; }

/* ===== 9. Toast (message at the bottom) ===== */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  display: flex; align-items: center; gap: 12px;
  background: #2b2f38; border: 1px solid var(--accent); border-radius: 10px;
  padding: 10px 14px; box-shadow: 0 8px 30px #000a; max-width: calc(100vw - 24px);
}

/* ===== 10. Nicer scrollbars ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #3a3f4b; border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ===== 11. Medium screens: put "Notes" under the row ===== */
@media (max-width: 1250px) {
  :root { --left-w: 260px; --right-w: 340px; }
  .legend-key { display: none; }
  .res-row { grid-template-columns: 110px 130px 80px 1fr 32px; }
  .res-head { grid-template-columns: 110px 130px 80px 1fr 32px; }
  .res-head span:nth-child(5) { display: none; }
  .crop { width: 110px; }
  .res-row .note { grid-column: 2 / 6; }
  .res-row .note:empty { display: none; }
}

/* ===== 12. Phones: one column + tabs at the bottom ===== */
.tabbar { display: none; }
@media (max-width: 820px) {
  :root { --top-h: 44px; --tab-h: 58px; }
  body { overflow: auto; }
  .tagline { display: none; }
  .logo { font-size: 17px; }
  .topbar { padding: 0 12px; position: sticky; top: 0; z-index: 10; }
  /* panels "disappear" (display: contents) so the boxes can be put in a new order */
  .app { display: flex; flex-direction: column; gap: 10px; height: auto; padding: 10px 10px calc(var(--tab-h) + 16px); }
  .panel { display: contents; }
  .box { margin: 0; }
  #picBox { order: 1; } .stage { order: 2; } #deductBox { order: 3; }
  .panel.left .box[data-tab="history"] { order: 4; } .panel.right .box { order: 5; }
  .zoombar { border: 1px solid var(--line); border-radius: 8px 8px 0 0; }
  .stage-scroll { padding: 10px 0; overflow: visible; }
  .stock-list, .history { max-height: none; }
  .btn { min-height: 40px; }
  .btn.mini { min-height: 30px; }

  /* show only the parts that belong to the open tab */
  body[data-tab="deduct"]  [data-tab]:not([data-tab="deduct"]),
  body[data-tab="stock"]   [data-tab]:not([data-tab="stock"]),
  body[data-tab="history"] [data-tab]:not([data-tab="history"]) { display: none !important; }

  /* the deduct box becomes a small bar that stays above the tabs while you scroll the results */
  #deductBox {
    position: sticky; bottom: calc(var(--tab-h) + 8px); z-index: 5;
    display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center;
    padding: 8px 10px; border-color: var(--accent); box-shadow: 0 -6px 24px #000c;
  }
  #deductBox h2, #deductBox #clearBtn { display: none; }
  #deductBox .field-col { font-size: 0; gap: 0; }            /* hide the label text, keep the box */
  #deductBox .field-col input { font-size: 14px; }
  #deductBox .sum { grid-column: 1 / 3; order: -1; margin: 0; font-size: 12px; }
  #deductBox .sum br { display: none; }
  #deductBox .sum span { margin-left: 8px; }
  #deductBox .btn.primary { margin: 0; width: auto; padding: 9px 14px; }

  /* result rows become small cards */
  .res-head { display: none !important; }
  .res-row { grid-template-columns: 96px 1fr 76px 32px; gap: 8px; }
  .crop { width: 96px; height: 56px; }
  .res-row .stock-cell { grid-column: 2 / 5; order: 5; }
  .res-row .note { grid-column: 1 / 5; order: 6; }
  .empty { padding: 30px 14px; }
  .empty-big { font-size: 17px; }

  .tabbar {
    display: grid; grid-template-columns: repeat(3, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--tab-h);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel); border-top: 1px solid var(--line); z-index: 30;
  }
  .tab { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column;
         align-items: center; justify-content: center; gap: 3px; font-size: 11px; cursor: pointer; }
  .tab svg { width: 22px; height: 22px; }
  .tab.active { color: var(--accent); }
  .toast { bottom: calc(var(--tab-h) + 12px); }
}
