:root {
  --bg: #f7f5f2;
  --panel: #ffffff;
  --ink: #1a2a25;
  --ink-soft: #626262;
  --ink-faint: #9a9a9a;
  --line: #e6e2dd;
  --accent: #184e3f;
  --accent-soft: #e8efec;
  --ok: #184e3f;
  --warn: #bd9482;
  --danger: #c0392b;
  --guest: #f1ece6;
  --ai: #e8efec;
  --flash: #f1ddd2;
  --shadow: 0 1px 2px rgba(24, 78, 63, 0.05), 0 4px 20px rgba(24, 78, 63, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  padding: 24px 28px 40px;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.005em; }

/* ─── Top bar ─────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 20px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; flex: 1; }
.brand-icon { font-size: 28px; }
.brand-title { font-size: 17px; font-weight: 600; color: var(--accent); }
.brand-sub   { font-size: 12px; color: var(--ink-soft); }
.room { color: var(--ink-soft); font-size: 14px; }
.room strong { color: var(--ink); margin-left: 4px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: #efece8; font-size: 13px; color: var(--ink-soft);
  min-width: 110px; justify-content: center;
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-faint);
}
.status-pill[data-status="idle"]       { background: #efece8; }
.status-pill[data-status="listening"]  { background: #e8efec; color: #184e3f; }
.status-pill[data-status="listening"] .dot { background: #184e3f; animation: pulse 1.4s ease-in-out infinite; }
.status-pill[data-status="thinking"]   { background: #f5e6df; color: #7a4a3a; }
.status-pill[data-status="thinking"] .dot { background: #bd9482; animation: pulse 1.0s ease-in-out infinite; }
.status-pill[data-status="speaking"]   { background: #d9e6e1; color: #184e3f; }
.status-pill[data-status="speaking"] .dot { background: #184e3f; animation: pulse 0.7s ease-in-out infinite; }
.status-pill[data-status="ending"]     { background: #fde6e6; color: #a32630; }
.status-pill[data-status="ending"] .dot { background: var(--danger); }

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

/* ─── KPIs ─────────────────────────────────────────── */
.kpis {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
  margin: 16px 0;
}
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
}
.kpi-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; }
.kpi-label { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* ─── Controls ─────────────────────────────────────── */
.controls {
  display: flex; justify-content: center; gap: 14px; margin: 8px 0 20px;
}
.btn {
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 12px 30px; border-radius: 999px; border: 1px solid transparent;
  cursor: pointer; transition: transform 0.1s ease, box-shadow 0.1s ease, opacity 0.15s ease;
  box-shadow: var(--shadow);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-start { background: var(--accent); color: #fff; }
.btn-start:hover:not(:disabled) { background: #0f3a2e; }
.btn-end   { background: #fff; color: var(--danger); border-color: #e6d6d2; }
.btn-end:hover:not(:disabled) { background: #faf0ec; }

/* ─── Panels grid ─────────────────────────────────── */
.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; min-height: 320px;
}
.panel-head {
  padding: 16px 20px 10px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.btn-ghost {
  border: 1px solid var(--line); background: transparent; color: var(--ink-soft);
  font-size: 12px; padding: 5px 10px; border-radius: 999px; cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.btn-ghost:disabled { opacity: 0.5; cursor: not-allowed; }
.panel h2 { font-size: 15px; }
.panel-sub { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

.empty {
  padding: 40px 20px; text-align: center; color: var(--ink-faint); font-size: 14px;
}

/* ─── Conversation ─────────────────────────────────── */
.conversation {
  padding: 16px 20px; overflow-y: auto; flex: 1;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 400px;
}
.bubble {
  max-width: 80%; padding: 10px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.45;
  animation: fadeIn 0.25s ease;
}
.bubble.guest {
  background: var(--guest); align-self: flex-start; border-bottom-left-radius: 4px;
}
.bubble.ai {
  background: var(--ai); align-self: flex-end; border-bottom-right-radius: 4px;
}
.bubble .who {
  font-size: 11px; font-weight: 600; color: var(--ink-soft); margin-bottom: 3px;
  display: flex; align-items: center; gap: 6px;
}
.bubble .timing {
  font-size: 10px; color: var(--ink-faint); margin-top: 5px;
}

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

/* ─── Dispatches ─────────────────────────────────── */
.dispatches {
  padding: 16px 20px; overflow-y: auto; flex: 1;
  display: flex; flex-direction: column; gap: 10px;
  max-height: 400px;
}
.card {
  background: #fbf8f4; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; animation: fadeIn 0.3s ease;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--ink-soft); margin-bottom: 6px;
}
.card-head .id { font-family: ui-monospace, Menlo, monospace; color: var(--ink); }
.card-head .eta {
  background: var(--accent-soft); color: var(--accent); padding: 2px 8px;
  border-radius: 999px; font-weight: 600;
}
.card-items { font-size: 14px; }
.card-items .item {
  display: flex; align-items: center; gap: 6px; padding: 2px 0;
}

/* ─── Inventory ─────────────────────────────────── */
.inventory {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.inventory thead th {
  text-align: left; padding: 10px 20px; font-size: 11px; text-transform: uppercase;
  color: var(--ink-soft); letter-spacing: 0.05em; font-weight: 600;
  border-bottom: 1px solid var(--line); background: #fbf8f4;
}
.inventory tbody td {
  padding: 10px 20px; border-bottom: 1px solid #f1ece6;
}
.inventory tbody tr:last-child td { border-bottom: none; }
.inventory .qty { font-variant-numeric: tabular-nums; font-weight: 600; }
.inventory .delta {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: #f1ddd2; color: #7a3a2c; font-size: 11px; font-weight: 600;
}
.inventory tr.flash td { background: var(--flash); transition: background 0.8s ease; }

/* ─── Alerts ─────────────────────────────────── */
.alerts {
  flex: 1; padding: 24px 20px; display: flex; align-items: center; justify-content: center;
}
.alerts-ok       { background: #e8efec; color: #184e3f; }
.alerts-ok .alerts-ok-msg { font-size: 14px; }
.alerts-emergency {
  background: linear-gradient(180deg, #fbe6e8 0%, #f8cccf 100%);
  color: var(--danger); animation: alertFlash 1s ease infinite alternate;
  flex-direction: column; gap: 10px; text-align: center;
}
.alerts-emergency .emerg-title { font-size: 18px; font-weight: 700; letter-spacing: 0.02em; }
.alerts-emergency .emerg-category { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; }
.alerts-emergency .emerg-quote { font-size: 14px; font-style: italic; max-width: 90%; color: #8a1a22; }

@keyframes alertFlash {
  from { background: linear-gradient(180deg, #fbe6e8 0%, #f8cccf 100%); }
  to   { background: linear-gradient(180deg, #fdf2f3 0%, #fae0e2 100%); }
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr; }
}
