/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --bg-dark: #0f1117;
  --bg-card: #1a1d27;
  --bg-card2: #1f2233;
  --bg-input: #252840;
  --border: #2e3250;
  --border-light: #3a3f60;

  --accent-primary: #6c63ff;
  --accent-primary-glow: rgba(108, 99, 255, 0.25);
  --accent-green: #22d3a0;
  --accent-green-glow: rgba(34, 211, 160, 0.2);
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;

  --text-primary: #e8eaf6;
  --text-secondary: #8b92b8;
  --text-muted: #555c80;
  --text-dark: #1a1d27;

  --receipt-text: #1c1410;
  --receipt-muted: #6b5a4e;
  --receipt-border: #2a2018;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-card: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 24px var(--accent-primary-glow);

  --font-main: 'Noto Sans SC', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-receipt: 'VT323', 'Dot Matrix', 'Courier New', monospace;

  /* Thermal paper palette */
  --receipt-bg: #f5f0e8;
  --receipt-bg-warm: #ede6d6;
  --receipt-ink: #1c1410;
  --receipt-ink-fade: #3d3028;
  --receipt-ink-light: #6b5a4e;
  --receipt-crease: rgba(0,0,0,0.07);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-main);
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.app-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(108,99,255,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(34,211,160,0.08) 0%, transparent 60%),
    var(--bg-dark);
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: rgba(26,29,39,0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 14px; }

.header-icon {
  font-size: 28px;
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent-primary), #9c54f7);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-glow);
}

.header-text h1 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(90deg, #fff 40%, var(--accent-primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.header-right { display: flex; align-items: center; gap: 12px; }

.stats-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 16px;
  background: rgba(108,99,255,0.1);
  border: 1px solid rgba(108,99,255,0.3);
  border-radius: 50px;
  font-size: 13px; font-weight: 600;
  color: var(--accent-primary);
  cursor: pointer;
  font-family: var(--font-main);
  transition: all 0.2s;
}
.stats-btn:hover {
  background: rgba(108,99,255,0.22);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(108,99,255,0.25);
}
.stats-btn-icon { font-size: 15px; }

.status-badge {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px;
  background: rgba(34,211,160,0.1);
  border: 1px solid rgba(34,211,160,0.3);
  border-radius: 50px;
  font-size: 13px;
  color: var(--accent-green);
  font-weight: 500;
}

.status-dot {
  width: 8px; height: 8px;
  background: var(--accent-green);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ============================================================
   PANELS
   ============================================================ */
.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.form-panel {
  flex: 1.2;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.receipt-panel {
  flex: 0.85;
  min-width: 360px;
  background: rgba(15,17,23,0.6);
}

.panel-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.panel-icon { font-size: 18px; }

.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.panel-tag {
  padding: 3px 10px;
  background: var(--accent-primary-glow);
  border: 1px solid rgba(108,99,255,0.4);
  border-radius: 50px;
  font-size: 11px;
  color: var(--accent-primary);
  font-family: var(--font-mono);
  font-weight: 600;
}

.receipt-tag {
  background: var(--accent-green-glow);
  border-color: rgba(34,211,160,0.4);
  color: var(--accent-green);
}

/* ============================================================
   FORM SCROLL AREA
   ============================================================ */
.form-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.form-scroll::-webkit-scrollbar { width: 5px; }
.form-scroll::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }

/* ============================================================
   FORM SECTIONS
   ============================================================ */
.form-section {
  margin-bottom: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: border-color 0.2s;
}

.form-section:hover { border-color: var(--border-light); }

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-group { margin-bottom: 12px; }
.form-group:last-child { margin-bottom: 0; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.form-group--sm input { max-width: 100%; }

input[type="text"],
input[type="number"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-glow);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

textarea { resize: vertical; min-height: 60px; }

.input-with-unit {
  display: flex; align-items: center; gap: 0;
  position: relative;
}
.input-with-unit input { padding-right: 36px; }
.input-with-unit .unit {
  position: absolute;
  right: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ============================================================
   MENU TABLE
   ============================================================ */
.menu-table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.menu-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.menu-table thead th {
  background: var(--bg-card2);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.menu-table tbody tr { transition: background 0.15s; }
.menu-table tbody tr:hover { background: rgba(108,99,255,0.05); }
.menu-table tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }

.menu-table td { padding: 7px 8px; vertical-align: middle; }

.menu-table input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 13px;
}

.menu-table input:focus {
  background: var(--bg-input);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-primary-glow);
}

.col-name { width: 40%; }
.col-qty  { width: 15%; }
.col-unit { width: 15%; }
.col-price{ width: 20%; }
.col-action{ width: 10%; }

.btn-del-row {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  border-radius: 5px;
  padding: 3px 8px;
  transition: all 0.15s;
  line-height: 1;
}

.btn-del-row:hover {
  color: var(--accent-red);
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.3);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-add-row {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(34,211,160,0.1);
  border: 1px solid rgba(34,211,160,0.3);
  color: var(--accent-green);
  font-size: 12px;
  font-weight: 600;
  border-radius: 50px;
  padding: 4px 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-main);
}

.btn-add-row:hover {
  background: rgba(34,211,160,0.2);
  border-color: var(--accent-green);
  transform: translateY(-1px);
}

.menu-actions {
  display: flex; gap: 10px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.15s;
}

.btn:hover::after { background: rgba(255,255,255,0.08); }
.btn:active { transform: scale(0.97); }

.btn-save {
  background: rgba(108,99,255,0.15);
  border: 1px solid rgba(108,99,255,0.35);
  color: var(--accent-primary);
  flex: 1;
}

.btn-save:hover { background: rgba(108,99,255,0.25); }

.btn-restore {
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.3);
  color: var(--accent-amber);
  flex: 1;
}

.btn-restore:hover { background: rgba(245,158,11,0.2); }

.btn-order {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #6c63ff, #9c54f7);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(108,99,255,0.4);
  margin-bottom: 10px;
  letter-spacing: 0.03em;
}

.btn-order:hover { box-shadow: 0 6px 28px rgba(108,99,255,0.6); transform: translateY(-2px); }

.btn-print {
  width: 100%;
  padding: 12px;
  background: var(--bg-card2);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-size: 14px;
  border-radius: var(--radius-md);
}

.btn-print:hover { background: var(--bg-input); color: var(--text-primary); }

.btn-icon { font-size: 16px; }

/* ============================================================
   RECEIPT SCROLL AREA
   ============================================================ */
.receipt-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
  /* Dark desk surface */
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255,255,255,0.015) 0px,
      rgba(255,255,255,0.015) 1px,
      transparent 1px,
      transparent 40px
    ),
    linear-gradient(160deg, #0d1018 0%, #111520 60%, #0a0d14 100%);
}

.receipt-scroll::-webkit-scrollbar { width: 5px; }
.receipt-scroll::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }

/* SVG filters for dot-matrix and grain effects */
.receipt-panel svg.filters { position: absolute; width: 0; height: 0; }

/* ============================================================
   RECEIPT PAPER — Thermal Dot-Matrix Style
   ============================================================ */
.receipt-paper {
  background: var(--receipt-bg);
  color: var(--receipt-ink);
  font-family: var(--font-receipt);
  font-size: 17px;        /* VT323 needs larger size */
  line-height: 1.55;
  letter-spacing: 0.02em;
  width: 310px;
  min-width: 310px;
  padding: 28px 20px 32px;
  position: relative;
  /* Paper curl + depth shadows */
  box-shadow:
    0 1px 1px rgba(0,0,0,0.15),
    0 4px 8px rgba(0,0,0,0.25),
    0 16px 40px rgba(0,0,0,0.5),
    0 32px 60px rgba(0,0,0,0.3),
    4px 0  12px rgba(0,0,0,0.1),
    -4px 0 12px rgba(0,0,0,0.1),
    inset 0 0 60px rgba(180,150,100,0.08);
  /* Slightly warm paper tint */
  background-image:
    /* Subtle horizontal thermal scan lines */
    repeating-linear-gradient(
      180deg,
      transparent 0px,
      transparent 3px,
      rgba(0,0,0,0.018) 3px,
      rgba(0,0,0,0.018) 4px
    ),
    /* Paper grain via CSS noise */
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeBlend in='SourceGraphic' mode='overlay' result='blend'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E"),
    /* Slight vignette at edges */
    radial-gradient(ellipse at 50% 50%, var(--receipt-bg) 60%, var(--receipt-bg-warm) 100%);
  background-size: 100% 4px, 200px 200px, 100% 100%;
  /* Dot-matrix ink rendering simulation */
  image-rendering: pixelated;
  -webkit-font-smoothing: none;
  font-smooth: never;
  /* Very subtle tilt for realism */
  transform: rotate(-0.3deg);
  transform-origin: top center;
  transition: filter 0.4s ease;
}

/* Torn top edge */
.receipt-paper::before {
  content: '';
  position: absolute;
  top: -10px; left: 0; right: 0;
  height: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='310' height='12'%3E%3Cpath d='M0,12 Q8,0 16,8 Q24,12 32,4 Q40,0 48,10 Q56,12 64,6 Q72,2 80,10 Q88,12 96,5 Q104,0 112,9 Q120,12 128,4 Q136,0 144,8 Q152,12 160,3 Q168,0 176,10 Q184,12 192,6 Q200,2 208,11 Q216,12 224,5 Q232,0 240,9 Q248,12 256,4 Q264,0 272,8 Q280,12 288,5 Q296,0 310,6 L310,12 Z' fill='%23f5f0e8'/%3E%3C/svg%3E");
  background-size: 310px 12px;
  background-repeat: no-repeat;
  z-index: 2;
}

/* Torn bottom edge */
.receipt-paper::after {
  content: '';
  position: absolute;
  bottom: -10px; left: 0; right: 0;
  height: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='310' height='12'%3E%3Cpath d='M0,0 Q8,12 16,4 Q24,0 32,8 Q40,12 48,3 Q56,0 64,7 Q72,12 80,3 Q88,0 96,8 Q104,12 112,4 Q120,0 128,9 Q136,12 144,5 Q152,0 160,10 Q168,12 176,4 Q184,0 192,7 Q200,12 208,3 Q216,0 224,8 Q232,12 240,4 Q248,0 256,9 Q264,12 272,5 Q280,0 288,7 Q296,12 310,5 L310,0 Z' fill='%23f5f0e8'/%3E%3C/svg%3E");
  background-size: 310px 12px;
  background-repeat: no-repeat;
  z-index: 2;
}

/* Printing animation — sweeps a highlight top→bottom */
@keyframes thermalPrint {
  0%   { clip-path: inset(0 0 100% 0); opacity: 0.7; filter: brightness(1.15); }
  80%  { clip-path: inset(0 0 0% 0);   opacity: 1;   filter: brightness(1.05); }
  100% { clip-path: inset(0 0 0% 0);   opacity: 1;   filter: brightness(1); }
}

.receipt-paper.printing {
  animation: thermalPrint 0.55s cubic-bezier(0.2, 0, 0.4, 1) forwards;
}

/* ── Receipt internals ── */
.receipt-header { text-align: center; margin-bottom: 8px; }

.receipt-title {
  font-size: 26px;
  font-weight: normal;   /* VT323 is already bold-looking */
  letter-spacing: 0.18em;
  color: var(--receipt-ink);
  /* Simulate slightly uneven ink pressure */
  text-shadow:
    0.5px 0.5px 0 rgba(0,0,0,0.12),
    -0.3px 0 0 rgba(0,0,0,0.06);
}

.receipt-shop {
  font-size: 15px;
  color: var(--receipt-ink-light);
  margin-top: 2px;
  letter-spacing: 0.06em;
}

.receipt-divider {
  border: none;
  margin: 6px 0;
  overflow: hidden;
  height: 1px;
  position: relative;
}

/* Dashed = dot-matrix dots row */
.receipt-divider.dashed {
  background: repeating-linear-gradient(
    90deg,
    var(--receipt-ink-light) 0px, var(--receipt-ink-light) 3px,
    transparent 3px, transparent 7px
  );
  opacity: 0.5;
}

/* Solid = full rule with slight ink fade variation */
.receipt-divider.solid {
  background: var(--receipt-ink-fade);
  opacity: 0.7;
}

.receipt-divider.double {
  height: 5px;
  background:
    linear-gradient(var(--receipt-ink-fade), var(--receipt-ink-fade)) 0 0 / 100% 1px no-repeat,
    linear-gradient(var(--receipt-ink-fade), var(--receipt-ink-fade)) 0 4px / 100% 1px no-repeat;
  opacity: 0.65;
}

.receipt-info-row {
  display: flex;
  font-size: 17px;
}
.info-label {
  min-width: 62px;
  font-size: 17px;
  color: var(--receipt-ink);
}
.info-value {
  flex: 1;
  font-size: 17px;
  color: var(--receipt-ink-fade);
}

.receipt-items-header {
  display: grid;
  grid-template-columns: 1fr 46px 46px 52px;
  gap: 2px;
  font-size: 15px;
  color: var(--receipt-ink-light);
  padding: 0 0 2px 0;
  letter-spacing: 0.04em;
}

.receipt-item-row {
  display: grid;
  grid-template-columns: 1fr 46px 46px 52px;
  gap: 2px;
  font-size: 16px;
  padding: 1px 0;
  align-items: start;
  color: var(--receipt-ink-fade);
}

.ri-name { white-space: pre-wrap; word-break: break-all; color: var(--receipt-ink); }
.ri-qty, .ri-uprice, .ri-dprice { text-align: right; }

.receipt-summary { font-size: 16px; }

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 1px 0;
  color: var(--receipt-ink-light);
}

.receipt-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0 4px;
}

.total-label {
  font-size: 22px;
  color: var(--receipt-ink);
  letter-spacing: 0.05em;
  text-shadow: 0.5px 0.5px 0 rgba(0,0,0,0.15);
}

.total-amount {
  font-size: 32px;
  color: var(--receipt-ink);
  letter-spacing: 0.04em;
  text-shadow:
    1px 1px 0 rgba(0,0,0,0.18),
    -0.5px 0 0 rgba(0,0,0,0.08);
}

.receipt-meta {
  font-size: 15px;
  color: var(--receipt-ink-light);
  line-height: 1.7;
}

.receipt-notice {
  font-size: 15px;
  color: var(--receipt-ink-fade);
  line-height: 1.55;
  white-space: pre-wrap;
}

.receipt-footer {
  font-size: 14px;
  color: var(--receipt-ink-light);
  text-align: center;
  line-height: 1.6;
  margin-top: 4px;
  opacity: 0.75;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 36px 40px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  box-shadow: var(--shadow-card), var(--shadow-glow);
  animation: slideUp 0.3s cubic-bezier(0.16,1,0.3,1);
}

@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-icon { font-size: 48px; margin-bottom: 14px; }
.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.modal-desc { color: var(--text-secondary); font-size: 14px; margin-bottom: 16px; }

.modal-info {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  text-align: left;
  line-height: 1.8;
}

.modal-close-btn { max-width: 200px; margin: 0 auto; }

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  body { background: white; }
  .app-header, .form-panel, .receipt-panel .panel-header { display: none !important; }
  .receipt-panel {
    flex: 1;
    border: none;
    background: white;
  }
  .receipt-scroll { padding: 0; justify-content: flex-start; }
  .receipt-paper {
    box-shadow: none;
    border-radius: 0;
    width: 80mm;
    min-width: 0;
  }
  .receipt-paper::before, .receipt-paper::after { display: none; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  html, body { overflow: auto; }
  .app-wrapper { height: auto; min-height: 100vh; }
  .main-content { flex-direction: column; overflow: visible; }
  .receipt-panel { min-width: 0; }
  .receipt-scroll { padding: 16px; }
  .form-panel { border-right: none; border-bottom: 1px solid var(--border); }
}
