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

:root {
  --bg: #0d0f17;
  --surface: #151824;
  --surface-2: #1c2030;
  --border: rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.14);
  --primary: #6c63ff;
  --primary-dark: #5a52e0;
  --primary-glow: rgba(108,99,255,0.35);
  --secondary: #2a2d3e;
  --accent: #00d4aa;
  --text: #e8eaf0;
  --text-muted: #6b7080;
  --text-dim: #9aa0b2;
  --red: #ff5767;
  --yellow: #ffc857;
  --green: #00d4aa;
  --radius: 16px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 60px rgba(0,0,0,0.6);
  --transition: 0.2s ease;
}

html { font-size: 14px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== Background Orbs ===== */
.bg-orbs {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden;
}
.orb {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.15;
  animation: orbFloat 12s ease-in-out infinite;
}
.orb-1 { width: 400px; height: 400px; background: var(--primary); top: -120px; left: -80px; animation-delay: 0s; }
.orb-2 { width: 300px; height: 300px; background: var(--accent); bottom: -80px; right: -60px; animation-delay: -5s; }
.orb-3 { width: 250px; height: 250px; background: #ff6b9d; top: 40%; left: 40%; animation-delay: -9s; }

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -30px) scale(1.05); }
}

/* ===== Header ===== */
.header {
  position: relative; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,15,23,0.8);
  backdrop-filter: blur(20px);
}

.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.15rem; font-weight: 700;
  color: var(--text);
}
.logo svg { width: 28px; height: 28px; color: var(--primary); }

.status-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 0.8rem; font-weight: 500;
  transition: var(--transition);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted);
  transition: var(--transition);
}
.status-pill.connected .status-dot { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
.status-pill.connected { border-color: rgba(0,212,170,0.25); }
.status-pill.error .status-dot { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== Main Layout ===== */
.main {
  position: relative; z-index: 1;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 280px 1fr;
  gap: 20px;
  padding: 24px 32px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ===== Panel ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.panel-title {
  display: flex; align-items: center; gap: 10px;
}
.panel-title h2 {
  font-size: 1rem; font-weight: 600; color: var(--text);
}

.step-badge {
  width: 26px; height: 26px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
  color: #fff; flex-shrink: 0;
}

/* ===== Upload Zone ===== */
.upload-zone {
  position: relative;
  border: 2px dashed var(--border-hover);
  border-radius: var(--radius);
  min-height: 200px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  overflow: hidden;
}
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(108,99,255,0.06);
}

.upload-inner {
  text-align: center;
  padding: 28px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.upload-icon svg { width: 52px; height: 52px; color: var(--primary); opacity: 0.7; }
.upload-title { font-size: 0.95rem; font-weight: 500; color: var(--text-dim); }
.upload-sub { font-size: 0.8rem; color: var(--text-muted); }

.upload-actions { display: flex; gap: 8px; }

/* ===== Camera ===== */
.camera-overlay {
  position: absolute; inset: 0;
  background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
}
.camera-overlay.hidden { display: none; }
#videoStream { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--radius-sm); }

.camera-controls { display: flex; align-items: center; gap: 16px; }

.btn-capture {
  width: 60px; height: 60px; border-radius: 50%;
  background: #fff; border: 4px solid rgba(255,255,255,0.5) !important;
  position: relative; cursor: pointer;
  padding: 0 !important;
  display: flex; align-items: center; justify-content: center;
}
.capture-ring {
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff;
  transition: var(--transition);
}
.btn-capture:hover .capture-ring { background: #e0e0e0; transform: scale(0.95); }

/* ===== Preview ===== */
.preview-block {
  display: flex; flex-direction: column; gap: 8px;
  position: relative;
}
.preview-block.hidden { display: none; }
.preview-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
#originalImg {
  width: 100%; border-radius: var(--radius-sm);
  object-fit: contain;
  border: 1px solid var(--border);
  max-height: 260px;
}

.clear-btn {
  position: absolute; top: 24px; right: 8px;
  background: rgba(0,0,0,0.5); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: var(--radius-xs);
  padding: 4px 8px; font-size: 0.72rem; cursor: pointer;
  transition: var(--transition);
}
.clear-btn:hover { background: rgba(255,87,103,0.2); color: var(--red); border-color: var(--red); }

/* ===== Settings ===== */
.settings-group {
  display: flex; flex-direction: column; gap: 6px;
}
.toggle-group { flex-direction: row; align-items: center; justify-content: space-between; }

.setting-label {
  font-size: 0.78rem; color: var(--text-dim); font-weight: 500;
  display: flex; justify-content: space-between; align-items: center;
}
.setting-value {
  font-weight: 700; color: var(--primary); font-size: 0.78rem;
}

.select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-xs); padding: 8px 12px;
  font-size: 0.82rem; font-family: inherit; cursor: pointer;
  transition: var(--transition); outline: none;
}
.select:hover, .select:focus { border-color: var(--primary); }
.select option { background: var(--surface-2); }

.slider {
  width: 100%; appearance: none;
  height: 4px; border-radius: 99px;
  background: var(--surface-2);
  outline: none; cursor: pointer;
  accent-color: var(--primary);
  transition: var(--transition);
}

/* Toggle */
.toggle { position: relative; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  display: block; width: 42px; height: 24px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 99px; position: relative; transition: var(--transition);
}
.toggle input:checked + .toggle-track { background: var(--primary); border-color: var(--primary); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-muted); transition: var(--transition);
}
.toggle input:checked + .toggle-track .toggle-thumb {
  left: calc(100% - 19px); background: #fff;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 0.82rem; font-weight: 600; font-family: inherit;
  cursor: pointer; border: 1px solid transparent;
  transition: all 0.18s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 16px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--primary-glow);
}

.btn-secondary {
  background: var(--surface-2); color: var(--text-dim);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--secondary); color: var(--text);
  border-color: var(--border-hover);
}

.btn-outline {
  background: transparent; color: var(--text-dim);
  border-color: var(--border);
}
.btn-outline:hover { border-color: var(--border-hover); color: var(--text); background: var(--surface-2); }

/* ===== Thermal Preview ===== */
.thermal-preview-wrap {
  display: flex; justify-content: center;
  overflow-y: auto; max-height: 400px;
  border-radius: var(--radius-sm);
}
.thermal-paper {
  background: #fff; border-radius: 4px;
  position: relative; display: flex; flex-direction: column; align-items: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6), 0 0 0 1px rgba(0,0,0,0.2);
  overflow: hidden; min-width: 160px; min-height: 120px; max-width: 100%;
}
#thermalCanvas { display: block; image-rendering: pixelated; }

.thermal-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: #bbb; font-size: 0.78rem; text-align: center; line-height: 1.5;
}

/* ===== Print Actions ===== */
.print-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.print-actions .btn { flex: 1; justify-content: center; }

/* ===== Log ===== */
.log-box {
  background: #0a0c14; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px;
  max-height: 140px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  font-family: 'Courier New', monospace; font-size: 0.72rem;
}
.log-entry { line-height: 1.5; }
.log-info { color: #5e9eff; }
.log-success { color: var(--green); }
.log-error { color: var(--red); }
.log-warn { color: var(--yellow); }
.log-dim { color: var(--text-muted); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .main { grid-template-columns: 1fr 1fr; }
  .panel-center { grid-column: 1 / -1; order: -1; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .panel-center .panel-title { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .main { grid-template-columns: 1fr; padding: 16px; }
  .panel-center { grid-template-columns: 1fr; }
  .header { padding: 12px 16px; }
}

/* ===== Animations ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.panel { animation: fadeInUp 0.4s ease both; }
.panel:nth-child(1) { animation-delay: 0.05s; }
.panel:nth-child(2) { animation-delay: 0.1s; }
.panel:nth-child(3) { animation-delay: 0.15s; }

/* Print loading state */
.btn-primary.printing {
  animation: printingPulse 0.8s ease infinite;
}
@keyframes printingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
