/* ==========================================================================
   BASE: Exact copy from newo-web-call/assets/styles.css
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  /* Theme-driven (overridden by theme.json at runtime) */
  --bg: #f0f0f0;
  --surface: #ffffff;
  --surface-secondary: #f5f5f5;
  --primary: #333333;
  --primary-hover: #555555;
  --accent: #666666;
  --ink: #1a1a1a;
  --ink-soft: rgba(26, 26, 26, 0.6);
  --ink-muted: rgba(26, 26, 26, 0.35);
  --line: rgba(0, 0, 0, 0.12);
  --header-bg: rgba(255, 255, 255, 0.7);
  --cart-bg: rgba(255, 255, 255, 0.9);
  --json-bg: #1a1a2e;
  --json-text: #e0e0e0;
  --json-code: #c8e6c9;
  --debug-bg: rgba(255, 255, 255, 0.95);
  --debug-header-bg: rgba(245, 245, 245, 0.96);
  --price-color: #333333;
  --badge-bg: #333333;
  --badge-text: #ffffff;
  --btn-bg: #1a1a1a;
  --btn-text: #ffffff;
  --btn-hover: #333333;
  --upload-bg: #333333;
  --upload-hover: #555555;
  --progress-bar: #333333;
  --copy-bg: #333333;
  --copy-hover: #555555;
  --filter-active: #333333;
  --filter-active-text: #ffffff;
  --status-connecting: #888888;
  --error: #c62828;
  --success: #4caf50;

  /* Non-configurable (call button colors) */
  --call-idle: linear-gradient(180deg, #29be74 0%, #149753 100%);
  --call-idle-shadow: 0 26px 60px rgba(31, 164, 99, 0.22);
  --call-active: linear-gradient(180deg, #29be74 0%, #149753 100%);
  --call-active-shadow: 0 0 0 16px rgba(31, 164, 99, 0.08), 0 26px 60px rgba(31, 164, 99, 0.22);
  --call-end: linear-gradient(180deg, #e25f58 0%, #cb4038 100%);
  --call-end-shadow: 0 24px 52px rgba(213, 76, 70, 0.22);
  --green: #1fa463;
  --green-ring: rgba(31, 164, 99, 0.2);
  --red: #d54c46;

  --shadow: 0 30px 80px rgba(0, 0, 0, 0.1);
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

html, body {
  margin: 0;
  min-height: 100%;
}

html {
  color-scheme: light;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout --- */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  gap: 12px;
  overflow: hidden;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  padding: 4px 8px;
  background: var(--header-bg);
  border-radius: 10px;
}

.logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

.logo svg {
  width: 132px;
  height: auto;
  display: block;
}

/* Menu Generator Button */
.menu-gen-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.menu-gen-btn:hover { background: var(--btn-hover); }
.powered-by {
  font-size: 11px;
  color: var(--ink-muted);
  text-decoration: none;
  transition: color 0.2s;
}
.powered-by:hover { color: var(--ink-soft); text-decoration: underline; }

.menu-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  transition: color 0.2s;
}
.menu-link:hover { color: var(--ink); text-decoration: underline; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-content {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #eee;
}
.modal-header h2 { margin: 0; font-size: 18px; color: var(--ink); }
.modal-close {
  background: none; border: none; font-size: 28px;
  cursor: pointer; color: #666; line-height: 1;
}
.modal-body {
  padding: 24px; overflow-y: auto; flex: 1;
}
.modal-body p { margin: 0 0 16px; color: #555; font-size: 14px; line-height: 1.5; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid #eee;
  display: flex; justify-content: flex-end;
}
.file-upload-label {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border: 2px dashed #ccc; border-radius: 12px;
  cursor: pointer; color: #666; font-size: 14px;
  transition: border-color 0.2s, background 0.2s;
}
.file-upload-label:hover { border-color: #999; background: #f9f9f9; }
.file-upload-label.has-file { border-color: #4caf50; background: #f1f8e9; color: #2e7d32; }
.file-upload-label input[type="file"] { display: none; }
.menu-gen-submit {
  padding: 10px 28px; background: var(--upload-bg); color: var(--btn-text); border: none;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.menu-gen-submit:disabled { opacity: 0.4; cursor: not-allowed; }
.menu-gen-submit:not(:disabled):hover { background: var(--upload-hover); }
.menu-gen-progress { margin-top: 16px; }
.progress-bar {
  width: 100%; height: 8px; background: var(--surface-secondary); border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--progress-bar); border-radius: 4px;
  transition: width 0.3s ease;
}
.progress-text { margin-top: 8px; font-size: 13px; color: #666; }
.progress-text.error { color: #c62828; }

/* POS JSON Viewer — middle column */
.pos-json-panel {
  width: 320px;
  min-width: 260px;
  background: var(--json-bg);
  color: var(--json-text);
  border-radius: 12px;
  display: none;
  flex-direction: column;
  font-family: monospace;
  overflow: hidden;
}
.pos-json-panel.visible { display: flex; }
.pos-json-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid #333;
}
.pos-json-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--json-text);
}
.pos-json-copy {
  padding: 4px 12px;
  background: var(--copy-bg);
  color: var(--btn-text);
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  margin-right: 8px;
}
.pos-json-copy:hover { background: var(--copy-hover); }
.pos-json-body {
  padding: 12px 16px;
  margin: 0;
  overflow-y: auto;
  max-height: 340px;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--json-code);
}

.main-area {
  flex: 1 1 auto;
  display: flex;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.main {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  background: rgba(255,255,255,0.4);
  border-radius: 12px;
}

.call-shell {
  width: min(100%, 820px);
  display: grid;
  place-items: center;
  gap: 22px;
  padding: 12px 16px 0;
}

.call-stage {
  position: relative;
  width: min(100vw - 48px, 520px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0.03) 64%, transparent 72%);
}

.wave-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* --- Call Button (exact newo-web-call) --- */
.call-btn {
  position: relative;
  z-index: 2;
  width: 176px;
  height: 176px;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease, background 0.22s ease;
  box-shadow: var(--call-idle-shadow);
  background: var(--call-idle);
  -webkit-tap-highlight-color: transparent;
}

.call-btn::before {
  content: '';
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.call-btn:hover { transform: translateY(-2px) scale(1.01); }
.call-btn:active { transform: scale(0.97); }

.call-btn svg {
  width: 56px;
  height: 56px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.call-btn.connecting {
  box-shadow: 0 0 0 16px rgba(255, 106, 0, 0.08), 0 26px 60px rgba(255, 106, 0, 0.24);
  animation: pulse 1.3s ease-in-out infinite;
}

.call-btn.active {
  background: var(--call-end);
  box-shadow: var(--call-end-shadow);
}

.call-btn.error,
.call-btn.ended {
  background: var(--call-end);
  box-shadow: var(--call-end-shadow);
}

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

button:focus-visible,
input:focus-visible {
  outline: 2px solid rgba(255, 106, 0, 0.45);
  outline-offset: 2px;
}

/* --- Status Stack (exact newo-web-call) --- */
.status-stack {
  display: grid;
  gap: 8px;
  place-items: center;
  text-align: center;
  margin-top: -2px;
}

.status-label {
  font-size: clamp(22px, 3vw, 28px);
  line-height: 1;
  letter-spacing: -0.05em;
  font-weight: 800;
  color: var(--ink);
}

.status-label.connecting { color: var(--orange-deep); }
.status-label.active { color: var(--green); }
.status-label.error { color: var(--red); }

.timer {
  min-height: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: rgba(70, 53, 42, 0.6);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.timer.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   ADDITIONS: Cart Panel, Transcript, Debug Panel
   ========================================================================== */

/* --- Cart Panel (left side, hidden by default, ?cart=1 to show) --- */
.cart-panel {
  width: 280px;
  min-width: 240px;
  background: var(--cart-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
}

.cart-panel.visible { display: flex; }

.cart-header {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cart-customer {
  padding: 8px 1.25rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.cart-customer-row { margin: 2px 0; }
.cart-customer-label { font-weight: 600; color: var(--ink); }

.cart-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.cart-badge {
  background: var(--orange);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  min-width: 24px;
  text-align: center;
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1.25rem;
}

.cart-empty {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.875rem;
  padding: 3rem 1rem;
}

.cart-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}

.cart-item:last-child { border-bottom: none; }

.cart-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.cart-item-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--ink);
  flex: 1;
}

.cart-item-qty {
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-left: 0.5rem;
}

.cart-item-price {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--orange);
  margin-left: 0.75rem;
}

.cart-item-modifiers {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--ink-soft);
  padding-left: 0.5rem;
}

.cart-item-modifier {
  display: flex;
  justify-content: space-between;
  padding: 1px 0;
}

.cart-footer {
  border-top: 1px solid var(--line);
  padding: 1rem 1.25rem;
}

.cart-subtotal {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
}

.cart-subtotal-value {
  font-family: var(--font-mono);
  color: var(--orange);
}

/* --- Transcript Area --- */
.transcript-area {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  right: 1.5rem;
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  z-index: 5;
}

.transcript-line {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: 10px;
  max-width: 85%;
  animation: fadeIn 0.2s ease;
}

.transcript-line.user {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.transcript-line.agent {
  align-self: flex-start;
  background: var(--orange);
  color: white;
  opacity: 0.92;
}

.transcript-line.system {
  align-self: center;
  background: rgba(31, 164, 99, 0.15);
  color: var(--green);
  font-weight: 600;
  font-size: 0.75rem;
}

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

/* --- Debug Panel --- */
.debug-panel {
  display: none;
  flex: 0 0 28vh;
  min-height: 160px;
  background: var(--debug-bg);
  border: 1px solid var(--line);
  border-top: 2px solid var(--primary);
  border-radius: 12px;
  flex-direction: column;
  overflow: hidden;
}

.debug-panel.visible { display: flex; }

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: rgba(252, 246, 239, 0.96);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.debug-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.debug-controls { display: flex; gap: 0.5rem; }

.debug-filter {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}

.debug-filter.active {
  background: var(--orange);
  color: white;
  border-color: var(--orange);
}

.debug-clear {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.debug-log {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  line-height: 1.5;
}

.debug-entry {
  padding: 2px 6px;
  border-radius: 3px;
  margin-bottom: 1px;
  white-space: pre-wrap;
  word-break: break-all;
}

.debug-entry .ts {
  color: rgba(23, 16, 11, 0.35);
  margin-right: 0.5rem;
}

.debug-entry.ws-in { color: #0d7377; background: rgba(13, 115, 119, 0.06); }
.debug-entry.ws-out { color: #6d28d9; background: rgba(109, 40, 217, 0.04); }
.debug-entry.tool-call { color: #c2410c; background: rgba(194, 65, 12, 0.06); }
.debug-entry.tool-result { color: #15803d; background: rgba(21, 128, 61, 0.06); }
.debug-entry.audio { color: rgba(23, 16, 11, 0.35); }
.debug-entry.status { color: #b45309; background: rgba(180, 83, 9, 0.06); }
.debug-entry.transcript { color: #be185d; background: rgba(190, 24, 93, 0.04); }
.debug-entry.error { color: #b91c1c; background: rgba(185, 28, 28, 0.08); }

/* --- Responsive --- */
@media (max-width: 768px) {
  .app {
    padding: 8px;
    gap: 6px;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .main-area {
    flex-direction: column;
    overflow: visible;
    min-height: auto;
  }

  /* Call button area — order 1 (below header) */
  .main {
    order: 1;
    flex: 0 0 auto;
    min-height: auto;
    padding: 10px 0;
    border-radius: 12px;
  }
  .call-shell {
    gap: 8px;
    padding: 0;
  }
  .call-stage {
    width: 120px;
    aspect-ratio: 1;
  }
  .call-btn {
    width: 88px;
    height: 88px;
  }
  .call-btn svg {
    width: 32px;
    height: 32px;
  }
  .call-btn::before {
    inset: 7px;
  }
  .status-label {
    font-size: 16px;
  }

  /* Cart panel — order 2, no internal scroll, grows with content */
  .cart-panel {
    width: 100%;
    min-width: 0;
    order: 2;
    overflow: visible;
    max-height: none;
    min-height: 20lh;
  }
  .cart-items {
    overflow: visible;
    max-height: none;
  }

  /* POS JSON — order 3, max ~10 lines with internal scroll */
  .pos-json-panel {
    width: 100%;
    min-width: 0;
    order: 3;
  }
  .pos-json-body {
    max-height: 15lh;
    overflow-y: auto;
  }

  /* Debug panel — max ~20 lines with internal scroll */
  .debug-panel {
    flex: 0 0 auto;
    min-height: auto;
  }
  .debug-log {
    max-height: 30lh;
    overflow-y: auto;
  }
}
