:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  
  /* New Accent: Teal */
  --primary: #0d9488;
  --primary-700: #0f766e;
  --primary-50: #f0fdfa;
  
  --danger: #ef4444;
  --focus: rgba(13, 148, 136, 0.4);
  
  /* Flatter shadows */
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  
  --radius: 12px;
  --radius-sm: 8px;
  --max: 1400px; /* Increased for sidebar layout */
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden; /* Prevent body scroll, handle in containers */
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.shell {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Crucial for nested scrolling */
}

.layout {
  display: flex;
  gap: 24px;
  height: 100%;
  min-height: 0;
}

.card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Chat Section */
.chat {
  flex: 1;
  min-width: 0; /* Prevent flex items from overflowing */
}

.chat__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 10;
}

.messages {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  overflow-y: auto;
  background: #f8fafc;
  scroll-behavior: smooth;
}

.messages:focus {
  outline: none;
}
.messages::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 99px;
}
.messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat__footer {
  padding: 16px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Sidebar Section */
.sidebar {
  width: 320px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.timeline-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.timeline-title {
  padding: 16px 20px;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}

.timeline__list {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline__item {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 12px;
  align-items: start;
}
.timeline__dot {
  width: 10px;
  height: 10px;
  border-radius: 99px;
  margin-top: 6px;
  background: var(--muted);
  opacity: 0.4;
}
.timeline__item[data-status="start"] .timeline__dot {
  background: #3b82f6;
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
.timeline__item[data-status="done"] .timeline__dot {
  background: #10b981;
  opacity: 1;
}
.timeline__item[data-status="error"] .timeline__dot {
  background: var(--danger);
  opacity: 1;
}
.timeline__text {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
.timeline__sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}


/* Common Elements */
.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.skip-link:focus-visible {
  left: 12px;
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand__mark {
  width: 28px;
  height: 28px;
  color: var(--primary);
}
.brand__title {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 16px;
}
.brand__subtitle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  min-height: 32px;
  font-size: 13px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--muted);
}
.status-pill[data-state="connected"] .status-dot {
  background: #10b981;
}
.status-pill[data-state="error"] .status-dot {
  background: var(--danger);
}

.h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.banner {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 14px;
}

/* Messages */
.msg {
  display: flex;
  align-items: flex-start;
  max-width: 100%;
}
.msg--user {
  justify-content: flex-end;
}

.msg__bubble {
  width: fit-content;
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
  font-size: 15px;
  line-height: 1.5;
}

.msg--assistant .msg__bubble {
  background: #ffffff;
  border-color: var(--border);
  border-top-left-radius: 4px;
}

.msg--user .msg__bubble {
  background: var(--primary);
  color: #ffffff;
  border-top-right-radius: 4px;
  box-shadow: none;
}
.msg--user .msg__role {
  display: none; 
}

.msg__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.msg__role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.msg__actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
}

.msg__text {
  white-space: pre-wrap;
}

/* UI Components */
.msg--ui {
  display: block;
  margin: 4px 0 14px;
  width: 100%;
}

/* Carousel */
.carousel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 4px 14px;
  scroll-snap-type: x mandatory;
}
.carousel::-webkit-scrollbar {
  height: 6px;
}
.carousel::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}
.carousel__item {
  flex: 0 0 180px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #ffffff;
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
  cursor: pointer;
  
  /* Flat Button Reset */
  appearance: none;
  font-family: inherit;
}
.carousel__item:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.carousel__title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text);
}
.carousel__meta {
  font-size: 13px;
  color: var(--muted);
}

/* Chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.chip {
  /* Flat Button Reset */
  appearance: none;
  font-family: inherit;
  
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-50);
}

/* Receipt */
.receipt {
  max-width: 320px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  position: relative;
  box-shadow: var(--shadow-sm);
  margin-top: 6px;
}
.receipt__head {
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1px;
  margin-bottom: 12px;
  text-align: center;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 8px;
}
.receipt__body {
  font-size: 14px;
  color: var(--text);
}
.receipt__code {
  font-family: ui-monospace, monospace;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  background: var(--surface-2);
  padding: 8px;
  border-radius: 6px;
  color: var(--text);
}
.receipt__time {
  text-align: center;
  margin-bottom: 12px;
  font-weight: 500;
}
.receipt__items {
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
}


.helper {
  min-height: 20px;
  color: var(--muted);
  margin-bottom: 8px;
  display: block;
  font-size: 13px;
  padding: 0;
  font-weight: 500;
}
.helper:not(:empty) {
  display: inline-block;
}

.composer {
  display: flex;
  gap: 12px;
  align-items: center;
}
.composer .icon-btn {
  min-height: 48px;
  min-width: 48px;
}
input[type="text"] {
  flex: 1;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  transition: all 0.2s;
}
input[type="text"]::placeholder {
  color: #94a3b8;
}
input[type="text"]:focus-visible {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--focus);
}

/* Flat Buttons */
button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}
button:hover {
  background: var(--surface-2);
  border-color: #cbd5e1;
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}
.btn-icon {
  width: 20px;
  height: 20px;
}

/* Primary Send Button - Flat */
#sendBtn {
  min-height: 48px;
  padding: 0 24px;
  border: none;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(13, 148, 136, 0.2);
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
}
#sendBtn:hover {
  background: var(--primary-700);
  box-shadow: 0 4px 6px rgba(13, 148, 136, 0.3);
  transform: translateY(-1px);
}
#sendBtn:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* Mic Button */
#micBtn {
    border-radius: 10px;
    border: 1px solid var(--border);
}
#micBtn[data-state="recording"] {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Icon Buttons */
.icon-btn {
  min-height: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: 99px; /* Circle */
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: transparent;
}
.icon-btn:focus-visible {
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--focus);
}

.icon {
  width: 20px;
  height: 20px;
  display: block;
  fill: currentColor;
}

/* TTS Play Button inside message */
.icon-btn--play {
  width: 28px;
  height: 28px;
  min-height: 0;
  min-width: 0;
  color: var(--primary);
  background: var(--primary-50);
  border: 1px solid var(--border);
}
.icon-btn--play:hover {
  background: var(--primary);
  color: white;
}
.icon-btn--play .icon {
  width: 14px;
  height: 14px;
}

.icon-btn--reset {
  color: var(--muted);
}
.icon-btn--reset:hover {
  color: var(--danger);
  background: #fef2f2;
}

.fineprint {
  margin: 10px 0 0;
  color: #94a3b8;
  font-size: 12px;
}

@media (max-width: 768px) {
    .layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 300px;
    }
    .chat {
        height: auto;
        min-height: 50vh;
    }
    .messages {
        max-height: 60vh;
    }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
