/* ═══════════════════════════════════════════════════════════════════════
   Hotel Athena Grand — Receptionist Voice Agent UI
   Plain CSS, no build step required.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --gold:       #c9a84c;
  --gold-light: #e4c97e;
  --dark:       #1a1a2e;
  --panel:      #16213e;
  --card:       #0f3460;
  --text:       #e0e0e0;
  --text-dim:   #8899aa;
  --green:      #4caf72;
  --red:        #e05252;
  --blue:       #4a9eff;
  --radius:     12px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
  --trace-w:    360px;  /* trace panel open width */
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--dark);
  color: var(--text);
  height: 100vh;
  overflow: hidden;   /* prevent page scroll — inner areas scroll instead */
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

header {
  background: linear-gradient(135deg, var(--panel), #0d1b2a);
  border-bottom: 2px solid var(--gold);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

header .logo { font-size: 2rem; }

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.04em;
}

header p { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }

/* Right-side header cluster */
.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.api-base-info {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.api-base-info code {
  color: var(--gold);
  font-family: 'Cascadia Code', monospace;
  font-size: 0.68rem;
}

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 8px var(--green); }

/* Trace toggle button (in header) */
.trace-toggle-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.trace-toggle-btn:hover          { color: var(--gold); border-color: var(--gold); }
.trace-toggle-btn.active         { color: var(--gold); border-color: var(--gold); }

.trace-toggle-label { display: inline; }

/* Chevron rotates when panel is open */
.chevron {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 0.7rem;
}
.trace-toggle-btn.active .chevron { transform: rotate(180deg); }

/* Error bubble inside transcript */
.error-bubble {
  border-left-color: var(--red) !important;
  background: rgba(224, 82, 82, 0.08) !important;
}
.error-bubble a { color: var(--gold); }
.error-bubble code { font-size: 0.8em; background: rgba(255,255,255,0.08); padding: 1px 4px; border-radius: 3px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.layout {
  display: flex;
  flex: 1;
  min-height: 0;    /* critical: allows flex children to shrink below content size */
  overflow: hidden;
}

/* ── Chat panel ──────────────────────────────────────────────────────────── */

.chat-panel {
  flex: 1;
  min-width: 0;     /* prevent flex blowout when content is wide */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid rgba(255,255,255,0.07);
}

.transcript {
  flex: 1;
  min-height: 0;    /* critical: nested flex scroll requires this */
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.25s ease;
}
.msg.user  { align-self: flex-end; align-items: flex-end; }
.msg.agent { align-self: flex-start; align-items: flex-start; }

.msg .bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.msg.user  .bubble { background: var(--card); color: var(--text); border-bottom-right-radius: 4px; }
.msg.agent .bubble {
  background: linear-gradient(135deg, #1e3a5f, #1a2f4e);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border-left: 3px solid var(--gold);
}

.msg .meta { font-size: 0.72rem; color: var(--text-dim); margin-top: 4px; padding: 0 4px; }

/* Audio player inside bubble */
.msg audio { margin-top: 8px; width: 100%; max-width: 260px; }

/* ── Input area (anchored at bottom) ─────────────────────────────────────── */

.input-area {
  flex-shrink: 0;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.text-row {
  display: flex;
  gap: 8px;
}

#textInput {
  flex: 1;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
#textInput:focus { border-color: var(--gold); }

button {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 10px 18px;
  transition: opacity 0.15s, transform 0.1s;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

#sendBtn {
  background: var(--gold);
  color: var(--dark);
}
#sendBtn:hover:not(:disabled) { background: var(--gold-light); }

/* Push-to-talk */
.voice-row { display: flex; gap: 8px; align-items: center; }

#pttBtn {
  flex: 1;
  background: var(--card);
  color: var(--text);
  border: 2px solid transparent;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
}
#pttBtn:hover:not(:disabled) { border-color: var(--gold); }
#pttBtn.recording {
  background: rgba(224, 82, 82, 0.2);
  border-color: var(--red);
  animation: pulse 1s infinite;
}

#voiceToggle {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 0.78rem;
  padding: 10px 12px;
}
#voiceToggle.active { color: var(--gold); border-color: var(--gold); }

#langSelect {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 10px 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, color 0.2s;
  appearance: none;
  -webkit-appearance: none;
  text-align: center;
  min-width: 52px;
}
#langSelect:hover, #langSelect:focus { color: var(--gold); border-color: var(--gold); }
#langSelect option { background: var(--panel); color: var(--text); }

/* ── Agent Trace panel ───────────────────────────────────────────────────── */

/*
 * Desktop: slides in from the right (width: 0 → --trace-w).
 * Mobile: fixed overlay drawer that slides in from right edge.
 */

.trace-panel {
  /* Desktop default: collapsed (zero width, invisible) */
  width: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #0a1628;
  overflow: hidden;
  transition: width 0.25s ease;
  border-left: 0px solid rgba(255,255,255,0.07);
}

/* When open on desktop: expand to full width */
.trace-panel.open {
  width: var(--trace-w);
  border-left-width: 1px;
}

.trace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 11px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.trace-header span { color: var(--gold); }

/* X close button (visible on mobile, and inside panel on desktop) */
.trace-close-btn {
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 1rem;
  font-weight: 400;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
}
.trace-close-btn:hover { color: var(--text); background: rgba(255,255,255,0.1); }

#traceLog {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.75rem;
}

.trace-step {
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  padding: 7px 9px;
  border-left: 3px solid transparent;
  animation: fadeIn 0.2s ease;
  cursor: pointer;
}
.trace-step:hover { background: rgba(255,255,255,0.06); }

.trace-step.START       { border-color: #888; }
.trace-step.FINISH      { border-color: var(--green); }
/* Proposal loop */
.trace-step.PROPOSAL    { border-color: #26c6da; }
.trace-step.VERIFY_PASS { border-color: var(--green); }
.trace-step.VERIFY_FAIL { border-color: #ff9f43; }
.trace-step.VERIFY_RETRY{ border-color: #ffcc02; }
/* Tool execution */
.trace-step.TOOL_RESULT { border-color: #9c6fff; }
/* Outcomes */
.trace-step.HANDOFF     { border-color: var(--red); }
/* Errors */
.trace-step.ERROR, .trace-step.PARSE_ERROR { border-color: var(--red); }

.trace-step .event-name {
  font-weight: 700;
  font-size: 0.69rem;
  letter-spacing: 0.06em;
  margin-bottom: 3px;
}
.trace-step .event-time { color: var(--text-dim); font-size: 0.65rem; float: right; }
.trace-step .event-body { color: #aabbc8; word-break: break-all; }

.trace-detail {
  background: #060e1c;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 9px;
  margin-top: 4px;
  white-space: pre-wrap;
  font-size: 0.72rem;
  color: #9ec8ff;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.trace-step.expanded .trace-detail { display: block; }

#clearTrace {
  background: transparent;
  color: var(--text-dim);
  font-size: 0.72rem;
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  margin: 8px 10px;
  align-self: flex-start;
  flex-shrink: 0;
}
#clearTrace:hover { color: var(--text); }

/* ── Backdrop (mobile overlay) ───────────────────────────────────────────── */

.trace-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 199;
}

/* ── Misc ────────────────────────────────────────────────────────────────── */

.typing-indicator {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 6px 16px;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
  flex-shrink: 0;
}
.typing-indicator.visible { display: flex; }
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold);
  animation: bounce 1.4s infinite both;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

/* ── ID Scan button (in voice row) ──────────────────────────────────────── */

#idScanBtn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 0.78rem;
  padding: 10px 12px;
}
#idScanBtn:hover { color: var(--gold); border-color: var(--gold); }
#idScanBtn.scanned { color: var(--green); border-color: var(--green); }

/* ── ID Scan Modal ───────────────────────────────────────────────────────── */

.id-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.65);
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.id-modal.open { display: flex; }

.id-modal-content {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.id-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.id-modal-header h2 { font-size: 1rem; color: var(--gold); font-weight: 700; }

.id-modal-close {
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.id-modal-close:hover { color: var(--text); background: rgba(255,255,255,0.1); }

/* Tabs */
.id-tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.id-tab {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 0;
  font-size: 0.85rem;
  font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
}
.id-tab.active   { color: var(--gold); border-bottom-color: var(--gold); }
.id-tab:hover:not(.active) { color: var(--text); }

/* Panels */
.id-panel { padding: 14px 16px; }
.id-panel--hidden { display: none; }

/* Upload drop zone */
.id-upload-area {
  border: 2px dashed rgba(255,255,255,0.2);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.id-upload-area:hover,
.id-upload-area.drag-over { border-color: var(--gold); }
.id-upload-icon { font-size: 2.5rem; }
.id-upload-area p { font-size: 0.85rem; color: var(--text-dim); }
.id-upload-hint  { font-size: 0.75rem !important; opacity: 0.6; }

/* Camera */
.id-camera-wrap {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.id-camera-wrap video { width: 100%; height: 100%; object-fit: cover; }
.id-action-btn {
  margin-top: 10px;
  width: 100%;
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
}
.id-action-btn:hover { border: 1px solid var(--gold); }

/* Preview thumbnail */
.id-preview-wrap {
  padding: 0 16px 4px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.id-preview-wrap--hidden { display: none; }
.id-preview-wrap img {
  max-height: 90px;
  max-width: 140px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
}
.id-retake-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.2);
  font-size: 0.8rem;
  padding: 6px 12px;
}
.id-retake-btn:hover { color: var(--text); }

/* Status */
.id-status {
  padding: 6px 16px;
  font-size: 0.82rem;
  color: var(--text-dim);
  min-height: 28px;
}
.id-status.ok    { color: var(--green); }
.id-status.error { color: var(--red); }

/* Extracted fields table */
.id-results { padding: 0 16px 8px; }
.id-results--hidden { display: none; }
.id-fields-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.id-fields-table tr  { border-bottom: 1px solid rgba(255,255,255,0.05); }
.id-fields-table td  { padding: 5px 8px; }
.id-fields-table td:first-child { color: var(--text-dim); width: 42%; }
.id-fields-table td:last-child  { color: var(--text); font-weight: 600; }

/* Modal action buttons */
.id-modal-actions {
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.id-submit-btn {
  flex: 1;
  background: var(--card);
  color: var(--text);
}
.id-submit-btn:not(:disabled):hover { outline: 1px solid var(--gold); }
.id-confirm-btn {
  flex: 1;
  background: var(--green);
  color: #0a1628;
  font-weight: 700;
}
.id-confirm-btn--hidden { display: none; }
.id-confirm-btn:hover:not(:disabled) { opacity: 0.88; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

/* Hide label text on very narrow viewports to keep the button compact */
@media (max-width: 480px) {
  .trace-toggle-label { display: none; }
  header h1 { font-size: 1rem; }
}

/*
 * Mobile / small screens (< 900px):
 *   - Trace panel becomes a fixed overlay drawer (slides in from right).
 *   - .open adds transform to bring it into view.
 *   - Backdrop becomes visible so tapping outside dismisses it.
 *   - Chat panel takes full width; layout is a single column.
 */
@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .chat-panel {
    border-right: none;
    border-bottom: none;
  }

  /* Trace panel: fixed overlay, off-screen by default */
  .trace-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: min(340px, 90vw);   /* readable but never wider than the viewport */
    max-height: 100vh;
    z-index: 200;
    border-left: 1px solid rgba(255,255,255,0.12);
    /* Override desktop width transitions — use transform instead */
    transform: translateX(100%);
    transition: transform 0.3s ease;
    /* Reset desktop width — panel is always 'wide' on mobile, translate handles hide */
  }

  .trace-panel.open {
    transform: translateX(0);
    width: min(340px, 90vw);  /* keep same width, just unhide */
  }

  /* Show backdrop when trace is open on mobile */
  .trace-panel.open ~ .trace-backdrop,
  .trace-backdrop.visible {
    display: block;
  }
}
