/* POS — touch-friendly responsive UI */
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --line: #334155;
  --muted: #94a3b8;
  --text: #f1f5f9;
  --accent: #22d3ee;
  --accent-2: #06b6d4;
  --warn: #fbbf24;
  --danger: #ef4444;
  --ok: #10b981;
  --radius: 10px;
  --tap: 48px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; touch-action: manipulation; }
body { overscroll-behavior: none; }
input, button, select, textarea { font: inherit; color: inherit; }

#app { display: flex; flex-direction: column; min-height: 100vh; }
.app-loading { align-items: center; justify-content: center; }
.splash { text-align: center; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #0b1220; border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.sidebar .brand { font-weight: 800; font-size: 22px; color: var(--accent); padding: 12px 8px; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: var(--radius); color: var(--text); text-decoration: none; min-height: var(--tap); }
.sidebar a:hover { background: var(--panel); }
.sidebar a.active { background: var(--accent); color: #06303a; font-weight: 700; }
.sidebar .spacer { flex: 1; }
.sidebar .userbox { background: var(--panel); padding: 10px; border-radius: var(--radius); font-size: 13px; }
.sidebar .userbox b { display: block; margin-bottom: 4px; }
.sidebar .lang { display: flex; gap: 4px; margin-top: 8px; }
.sidebar .lang button { flex: 1; padding: 8px; border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 6px; cursor: pointer; }
.sidebar .lang button.active { background: var(--accent); color: #06303a; border-color: var(--accent); }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { background: #0b1220; border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; gap: 12px; min-height: 56px; }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .grow { flex: 1; }
.online-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 6px; }
.online-dot.offline { background: var(--danger); }

/* Compact status icons in topbar (online / printer / AI) */
.status-icons { display: flex; gap: 6px; align-items: center; }
.status-icons .sicon { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; cursor: default; }
.status-icons .sicon .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status-icons .sicon.ok .dot { background: var(--ok); }
.status-icons .sicon.err .dot { background: var(--danger); }
.status-icons .sicon.unknown .dot { background: var(--muted); }
.status-icons .sicon .glyph { font-size: 14px; line-height: 1; }
.status-icons .sicon .lbl { font-size: 12px; color: var(--muted); max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) { .status-icons .sicon .lbl { display: none; } }
.content { padding: 16px; flex: 1; min-width: 0; }

/* iPad/portrait */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; cursor: pointer; min-width: var(--tap); min-height: var(--tap); align-items: center; justify-content: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; min-height: var(--tap); min-width: var(--tap); background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; text-decoration: none; font-weight: 600; }
.btn:hover { background: var(--panel); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #06303a; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.warn { background: var(--warn); color: #2b1d00; border-color: var(--warn); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.lg { font-size: 18px; padding: 16px 22px; min-height: 60px; }
.btn.xl { font-size: 22px; padding: 22px; min-height: 80px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Inputs */
.input, .select, .textarea { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-height: var(--tap); width: 100%; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* Card / panel */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; }
.muted { color: var(--muted); }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.table tr:hover { background: var(--panel-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* POS layout */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 12px; height: calc(100vh - 56px); }
@media (max-width: 1100px) { .pos { grid-template-columns: 1fr; } }
.pos .left { display: flex; flex-direction: column; min-height: 0; }
.pos .right { display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
.pos .scanbar { display: flex; gap: 8px; padding: 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.pos .scanbar input { font-size: 18px; }
.pos .cart { flex: 1; overflow: auto; padding: 8px 12px; }
.pos .line { display: grid; grid-template-columns: 1fr auto; gap: 4px; padding: 12px; background: var(--panel-2); border-radius: var(--radius); margin-bottom: 6px; }
.pos .line .name { font-weight: 600; }
.pos .line .meta { color: var(--muted); font-size: 13px; }
.pos .line .total { font-weight: 700; font-size: 18px; align-self: center; }
.pos .line .controls { display: flex; gap: 6px; align-items: center; }
.pos .line button { background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; color: var(--text); cursor: pointer; min-height: 36px; }
.pos .line .qty { width: 70px; text-align: center; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px; min-height: 36px; font-weight: 600; }
.pos .line .qty:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
/* Plain number inputs without a class still get readable contrast */
input[type="number"]:not([class]) { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.pos .totals { padding: 12px 16px; border-top: 1px solid var(--line); }
.pos .totals .row { justify-content: space-between; padding: 4px 0; }
.pos .totals .grand { font-size: 28px; font-weight: 800; padding-top: 8px; border-top: 1px dashed var(--line); }
.pos .actions { padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pos .actions .full { grid-column: span 2; }
.pos .quickgrid { display: grid; gap: 8px; padding: 12px; overflow: auto; flex: 1; align-content: start; }
.pos .quickgrid.fixed { grid-template-columns: repeat(var(--cols, 5), 1fr); grid-auto-rows: minmax(110px, auto); }
.pos .quickgrid.fluid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.pos .quickgrid button { padding: 8px; background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: var(--radius); cursor: pointer; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; min-height: 80px; overflow: hidden; }
.pos .quickgrid button:hover { background: var(--accent); color: #06303a; }
.pos .quickgrid img { width: 100%; height: 60px; object-fit: cover; border-radius: 6px; }
.pos .quickgrid b { font-size: 14px; text-align: center; }
.pos .quickgrid span { font-size: 12px; color: var(--muted); }
.pos .quickgrid button:hover span { color: #06303a; }
.pos .quickgrid .empty { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 12px; cursor: default; }
.pos .quickgrid .empty:hover { background: transparent; color: var(--muted); }

/* Quick-tile editor (settings) */
.tile-editor { display: grid; gap: 6px; }
.tile-editor button { background: var(--panel-2); border: 1px dashed var(--line); border-radius: 8px; min-height: 80px; color: var(--text); cursor: pointer; padding: 6px; font-size: 12px; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; }
.tile-editor button.has-product { border-style: solid; background: var(--panel); }
.tile-editor button img { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; }

/* Switch (Tax / Nontax) */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .knob { width: 44px; height: 24px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; position: relative; transition: background .15s; }
.switch .knob::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + .knob { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(20px); background: #06303a; }

/* Image preview in product editor */
.image-pick { display: flex; align-items: center; gap: 12px; }
.image-pick .preview { width: 96px; height: 96px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.image-pick .preview img { width: 100%; height: 100%; object-fit: cover; }
.image-pick .preview .ph { color: var(--muted); font-size: 11px; text-align: center; padding: 4px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-width: 500px; width: 100%; max-height: 90vh; overflow: auto; padding: 20px; }
.modal.lg { max-width: 800px; }
.modal h2 { margin-top: 0; }

/* Receipt preview */
.receipt { background: #fff; color: #000; padding: 16px; max-width: 320px; margin: 0 auto; font-family: 'Courier New', monospace; font-size: 12px; line-height: 1.4; }
.receipt h3 { margin: 0; text-align: center; }
.receipt hr { border: none; border-top: 1px dashed #555; margin: 8px 0; }
.receipt .center { text-align: center; }
.receipt .right { text-align: right; }
.receipt table { width: 100%; }
.receipt table td { padding: 1px 0; }

/* Login */
.login-shell { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 400px; }
.login-card h1 { margin: 0 0 24px; color: var(--accent); text-align: center; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.ok { background: #064e3b; color: #6ee7b7; }
.badge.warn { background: #78350f; color: #fde68a; }
.badge.danger { background: #7f1d1d; color: #fecaca; }
.badge.info { background: #155e75; color: #67e8f9; }

/* Toasts */
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { padding: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-width: 360px; }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--ok); }

/* Print */
/* Print rules are injected dynamically by components/receipt.js so the paper width
 * follows the configured `printer.width_mm` setting (58mm or 80mm for TSP650 II). */

.hidden { display: none !important; }
.flex { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.right { text-align: right; }
.center { text-align: center; }
.tag { padding: 2px 6px; border-radius: 4px; background: var(--panel-2); font-size: 11px; }
.scrollx { overflow-x: auto; }
