/* DeathsPOS - DOS / IBM terminal look with DeathsNode red/black glitch flavour.
   Theme switch: <body data-theme="death|ibm">. Glitch FX: body.fx */
:root {
  --font: 'Share Tech Mono', 'Perfect DOS VGA 437', 'Lucida Console', 'Consolas', 'Courier New', monospace;
  --head: 'Bebas Neue', 'Impact', 'Arial Narrow', sans-serif;
}
body[data-theme="death"], body:not([data-theme]) {
  --bg: #050505; --panel: #0c0c0c; --fg: #e6e6e6; --dim: #8a8a8a; --accent: #ff1a2e;
  --line: #ff1a2e; --title-bg: #ff1a2e; --title-fg: #000; --hi: #fff; --ok: #55ff55; --warn: #ffff55; --err: #ff5555;
  --sel-bg: #ff1a2e; --sel-fg: #000; --btn: #aaaaaa; --btn-fg: #000;
}
body[data-theme="ibm"] {
  --bg: #0000aa; --panel: #000088; --fg: #c8c8c8; --dim: #8888cc; --accent: #ffff55;
  --line: #c8c8c8; --title-bg: #c8c8c8; --title-fg: #0000aa; --hi: #fff; --ok: #55ff55; --warn: #ffff55; --err: #ff5555;
  --sel-bg: #c8c8c8; --sel-fg: #0000aa; --btn: #aaaaaa; --btn-fg: #000;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 16px;
  line-height: 1.25; overflow: hidden; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
input, select, textarea, button { font-family: var(--font); font-size: inherit; }
input, select, textarea { user-select: text; -webkit-user-select: text; }
.hide { display: none !important; }

/* CRT scanlines + vignette */
body::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 9999;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.22) 3px),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 60%, rgba(0,0,0,.45) 100%);
}
body.fx { animation: flick 6s infinite steps(1); }
@keyframes flick { 0%,96%,100% { opacity: 1 } 97% { opacity: .94 } 98% { opacity: 1 } 99% { opacity: .9 } }

/* Glitch title */
.glitch { position: relative; font-family: var(--head); letter-spacing: 2px; color: var(--hi); display: inline-block; }
body.fx .glitch::before, body.fx .glitch::after {
  content: attr(data-text); position: absolute; left: 0; top: 0; width: 100%; overflow: hidden; pointer-events: none;
}
body.fx .glitch::before { color: var(--accent); left: 2px; text-shadow: -1px 0 #00ffff; animation: gl1 3.2s infinite steps(1); }
body.fx .glitch::after  { color: #00e5ff; left: -2px; text-shadow: 1px 0 var(--accent); animation: gl2 2.7s infinite steps(1); }
@keyframes gl1 {
  0%,88%,100% { clip-path: inset(0 0 100% 0); } 89% { clip-path: inset(10% 0 60% 0); } 91% { clip-path: inset(55% 0 20% 0); }
  93% { clip-path: inset(30% 0 45% 0); } 95% { clip-path: inset(80% 0 5% 0); }
}
@keyframes gl2 {
  0%,84%,100% { clip-path: inset(100% 0 0 0); } 85% { clip-path: inset(40% 0 40% 0); } 87% { clip-path: inset(5% 0 80% 0); }
  90% { clip-path: inset(65% 0 10% 0); } 92% { clip-path: inset(20% 0 55% 0); }
}
@media (prefers-reduced-motion: reduce) { body.fx, body.fx .glitch::before, body.fx .glitch::after { animation: none !important; } }

/* DOS window */
.win { border: 3px double var(--line); background: var(--panel); box-shadow: 8px 8px 0 rgba(0,0,0,.65); display: flex; flex-direction: column; min-height: 0; }
.win > .title { background: var(--title-bg); color: var(--title-fg); padding: 2px 10px; text-align: center; text-transform: uppercase; font-weight: bold; letter-spacing: 1px; flex: none; }
.win > .body { padding: 8px 10px; flex: 1; min-height: 0; overflow: auto; }

/* DOS button */
.dbtn {
  --b: var(--btn); --f: var(--btn-fg);
  background: var(--b); color: var(--f); border: 0; cursor: pointer; text-transform: uppercase; font-weight: bold;
  padding: 6px 12px; line-height: 1.1; text-align: center; overflow: hidden; word-break: break-word;
  box-shadow: inset 3px 3px 0 rgba(255,255,255,.55), inset -3px -3px 0 rgba(0,0,0,.6), 0 0 0 1px #000;
  touch-action: manipulation;
}
.dbtn:hover { filter: brightness(1.12); }
.dbtn:active, .dbtn.down { box-shadow: inset 3px 3px 0 rgba(0,0,0,.6), inset -3px -3px 0 rgba(255,255,255,.35), 0 0 0 1px #000; transform: translate(1px,1px); }
.dbtn:disabled { opacity: .4; cursor: default; }
.dbtn.sel { outline: 3px solid var(--hi); outline-offset: -6px; }
.dbtn small { display: block; font-size: .72em; opacity: .9; font-weight: normal; }
.dbtn.red { --b: #aa0000; --f: #fff; } .dbtn.green { --b: #00aa00; --f: #fff; } .dbtn.blue { --b: #0000aa; --f: #fff; }
.dbtn.yellow { --b: #ffff55; --f: #000; } .dbtn.sm { padding: 3px 8px; font-size: .9em; }

/* Inputs */
.dinput, select.dinput, textarea.dinput {
  background: #000; color: var(--ok); border: 2px inset #777; padding: 4px 6px; width: 100%; outline: none;
  caret-color: var(--ok); border-radius: 0;
}
.dinput:focus { border-color: var(--accent); }
label.f { display: block; margin: 6px 0 2px; color: var(--dim); text-transform: uppercase; font-size: .85em; }
.row { display: flex; gap: 8px; align-items: center; } .row > * { flex: 1; } .row > .auto { flex: none; }
.chk { display: flex; gap: 8px; align-items: center; margin: 6px 0; cursor: pointer; text-transform: uppercase; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Modal */
#modal-root { position: fixed; inset: 0; z-index: 5000; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,.6); }
#modal-root.on { display: flex; }
.modal { min-width: 340px; max-width: min(92vw, 640px); max-height: 90vh; }
.modal .btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; } .modal .btns .dbtn { flex: 1; min-width: 90px; padding: 10px; }
.big { font-size: 2.2em; font-weight: bold; text-align: center; color: var(--hi); margin: 6px 0; }
.err { color: var(--err); } .ok { color: var(--ok); } .warn { color: var(--warn); } .dim { color: var(--dim); }
#toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 6000; background: #000; border: 3px double var(--line); padding: 6px 16px; display: none; max-width: 90vw; text-transform: uppercase; }
#toast.on { display: block; } #toast.bad { border-color: #ff5555; color: #ff5555; } #toast.good { border-color: #55ff55; color: #55ff55; }

/* Login */
#login { position: fixed; inset: 0; z-index: 4000; background: var(--bg); display: flex; align-items: center; justify-content: center; }
#login .win { width: min(92vw, 360px); }
#login h1 { margin: 4px 0 2px; font-size: 3em; text-align: center; line-height: 1; }
#pin-disp { font-size: 2em; letter-spacing: .4em; text-align: center; background: #000; color: var(--ok); border: 2px inset #777; padding: 4px; height: 1.6em; margin: 8px 0; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; } .pad .dbtn { padding: 14px 0; font-size: 1.3em; }

/* ===== POS ===== */
#app { height: 100%; display: flex; flex-direction: column; padding: 8px; gap: 8px; }
#top { display: flex; align-items: center; gap: 14px; flex: none; border-bottom: 3px double var(--line); padding: 0 4px 6px; }
#top .brand { font-size: 2em; line-height: 1; }
#top .store { color: var(--dim); text-transform: uppercase; }
#top .sp { flex: 1; }
#top .chip { border: 2px solid var(--line); padding: 1px 8px; text-transform: uppercase; cursor: pointer; white-space: nowrap; }
.chip.on { color: var(--ok); border-color: var(--ok); } .chip.off { color: var(--err); border-color: var(--err); }
#main { flex: 1; display: grid; grid-template-columns: minmax(300px, 38%) 1fr; gap: 12px; min-height: 0; padding-right: 8px; padding-bottom: 8px; }
#left { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
#ticket { flex: 1; min-height: 80px; }
#lines { font-size: 1.05em; }
.ln { display: flex; justify-content: space-between; gap: 8px; padding: 1px 4px; cursor: pointer; }
.ln .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .ln .t { flex: none; }
.ln.sel { background: var(--sel-bg); color: var(--sel-fg); }
.ln.sub { color: var(--dim); font-size: .85em; padding-left: 24px; } .ln.sub.sel { color: var(--sel-fg); }
.ln.empty { color: var(--dim); text-align: center; cursor: default; margin-top: 20px; }
#totals { flex: none; border-top: 2px dashed var(--line); padding: 4px 10px 6px; }
#totals div { display: flex; justify-content: space-between; } #totals .grand { font-size: 1.9em; color: var(--hi); font-weight: bold; }
#entry-row { display: flex; gap: 8px; align-items: center; flex: none; }
#entry { flex: 1; background: #000; border: 2px inset #777; color: var(--ok); padding: 4px 8px; min-height: 2em; font-size: 1.3em; text-align: right; overflow: hidden; white-space: nowrap; }
#entry-hint { color: var(--dim); font-size: .8em; flex: none; max-width: 45%; text-align: right; }
#keypad { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: 5px; flex: none; height: 200px; }
#keypad .dbtn { padding: 0; font-size: 1.4em; }
#right { display: flex; flex-direction: column; min-height: 0; gap: 8px; }
#tabs { display: flex; gap: 6px; flex: none; flex-wrap: wrap; }
#tabs .dbtn { padding: 4px 14px; } #tabs .dbtn.act { --b: var(--accent); --f: #000; }
#grid { flex: 1; display: grid; gap: 6px; min-height: 0; }
#grid .dbtn { padding: 4px; font-size: clamp(11px, 1.55vw, 20px); display: flex; flex-direction: column; justify-content: center; align-items: center; }
#grid .cell-text { display: flex; align-items: center; justify-content: center; text-transform: uppercase; font-weight: bold; text-align: center; padding: 4px; }
#foot { flex: none; color: var(--dim); font-size: .8em; text-align: center; }
@media (max-width: 860px) { #main { grid-template-columns: 1fr; overflow: auto; } #keypad { height: 180px; } body { overflow: auto; } #app { height: auto; min-height: 100%; } #grid { min-height: 380px; } }

/* ===== ADMIN ===== */
#admin { height: 100%; display: flex; flex-direction: column; padding: 8px; gap: 8px; }
#atabs { display: flex; gap: 6px; flex-wrap: wrap; flex: none; } #atabs .dbtn.act { --b: var(--accent); --f: #000; }
#acontent { flex: 1; min-height: 0; overflow: auto; padding: 4px 8px 10px 4px; }
table.dt { width: 100%; border-collapse: collapse; } table.dt th { background: var(--title-bg); color: var(--title-fg); text-align: left; padding: 2px 8px; position: sticky; top: 0; z-index: 1; }
table.dt td { padding: 2px 8px; border-bottom: 1px dotted #444; } table.dt tr:hover td { background: rgba(255,255,255,.07); } table.dt td.r, table.dt th.r { text-align: right; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; } .cols3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }
@media (max-width: 900px) { .cols2, .cols3 { grid-template-columns: 1fr; } }
.tag { display: inline-block; padding: 0 6px; border: 1px solid currentColor; font-size: .85em; }

/* layout editor */
#ed { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 14px; align-items: start; }
@media (max-width: 1000px) { #ed { grid-template-columns: 1fr; } }
#egrid { display: grid; gap: 4px; background: #000; padding: 6px; border: 3px double var(--line); aspect-ratio: 1.55 / 1; width: 100%; max-height: 62vh; }
.ecell { border: 1px dashed #444; position: relative; cursor: pointer; display: flex; align-items: center; justify-content: center; text-align: center; color: #555; font-size: 12px; overflow: hidden; }
.ecell:hover { border-color: var(--accent); color: var(--accent); }
.ecell.drop { outline: 3px solid var(--ok); }
.ebtn { padding: 2px; font-size: 12px; font-weight: bold; text-transform: uppercase; cursor: grab; overflow: hidden; word-break: break-word;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.5), inset -2px -2px 0 rgba(0,0,0,.55); border: 0; }
.ebtn.sel { outline: 3px solid #fff; outline-offset: -5px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { outline-color: var(--accent); } }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; } .sw { height: 24px; border: 2px solid #000; cursor: pointer; } .sw.on { outline: 2px solid #fff; }
