/* ============================================
   Robosobaka Voice Lab — Warm Editorial
   ============================================ */

:root {
  color-scheme: only light;

  /* Warm ivory base */
  --ivory: #faf7f2;
  --cream: #f3ede3;
  --linen: #ece5d8;
  --parchment: #e2d9ca;

  /* Ink & text */
  --ink: #2c2418;
  --ink-soft: #5c4f3d;
  --ink-faint: #9a8e7c;
  --ink-ghost: #c4baa8;

  /* Terracotta accent */
  --terra: #c4623a;
  --terra-light: #d98a6a;
  --terra-wash: rgba(196, 98, 58, 0.08);
  --terra-glow: rgba(196, 98, 58, 0.18);

  /* Sage for assistant */
  --sage: #6b8f71;
  --sage-wash: rgba(107, 143, 113, 0.09);
  --sage-border: rgba(107, 143, 113, 0.22);

  /* Utility */
  --shadow-sm: 0 1px 3px rgba(44, 36, 24, 0.06);
  --shadow-md: 0 4px 16px rgba(44, 36, 24, 0.08);
  --shadow-lg: 0 12px 40px rgba(44, 36, 24, 0.1);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
}

/* ---------- Reset ---------- */

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

/* ---------- Body ---------- */

body {
  min-height: 100dvh;
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-weight: 400;
  color: var(--ink);
  background-color: var(--ivory);
  background-image:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(196, 98, 58, 0.05), transparent),
    radial-gradient(ellipse 60% 60% at 85% 100%, rgba(107, 143, 113, 0.05), transparent);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Subtle paper grain */
.grain {
  position: fixed;
  inset: 0;
  opacity: 0.3;
  pointer-events: none;
  z-index: 100;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* ---------- Shell ---------- */

.shell {
  grid-column: 2;
  display: flex;
  justify-content: center;
  padding: 28px 24px 40px;
  min-height: 100dvh;
  min-width: 0;
}

/* ---------- Console ---------- */

.console {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-height: 0;
}

/* Staggered entrance */
.console > * {
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.console > *:nth-child(1) { animation-delay: 0s; }
.console > *:nth-child(2) { animation-delay: 0.06s; }
.console > *:nth-child(3) { animation-delay: 0.12s; }
.console > *:nth-child(4) { animation-delay: 0.18s; }

/* ---------- Header ---------- */

.console-top {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.console-top .console-title { grid-column: 2; }
.who {
  grid-column: 3;
  justify-self: end;
  font: inherit;
  font-size: 0.74rem;
  color: var(--ink-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
}
.who:hover { color: var(--terra); }

.console-title {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: clamp(1.4rem, 3.5vw, 1.8rem);
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--ink);
}

/* ---------- Status + Play button row ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--ink-soft);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-ghost);
  transition: background 0.4s ease, box-shadow 0.4s ease;
  flex-shrink: 0;
}

.status-dot[data-state="idle"] {
  background: var(--ink-ghost);
  box-shadow: none;
}

.status-dot[data-state="connecting"] {
  background: var(--terra-light);
  box-shadow: 0 0 0 4px var(--terra-wash);
  animation: blink 1.4s ease-in-out infinite;
}

.status-dot[data-state="listening"] {
  background: var(--terra);
  box-shadow: 0 0 0 5px var(--terra-glow);
  animation: breathe 2.2s ease-in-out infinite;
}

/* ---------- Wake word indicator ---------- */

.wake-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--ink-faint);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--cream);
  border: 1px solid var(--linen);
  transition: all 0.3s ease;
}

.wake-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-ghost);
  flex-shrink: 0;
  transition: all 0.3s ease;
}

body.wake-active .wake-indicator {
  background: var(--sage-wash);
  border-color: var(--sage-border);
  color: var(--sage);
}

body.wake-active .wake-dot {
  background: var(--sage);
  box-shadow: 0 0 0 4px rgba(107, 143, 113, 0.15);
  animation: breathe-sage 2.2s ease-in-out infinite;
}

@keyframes breathe-sage {
  0%, 100% { box-shadow: 0 0 0 4px rgba(107, 143, 113, 0.15); }
  50% { box-shadow: 0 0 0 7px rgba(107, 143, 113, 0.08); }
}

/* ---------- Controls row ---------- */

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

/* ---------- Mute button ---------- */

.mute-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--linen);
  cursor: pointer;
  background: var(--cream);
  color: var(--ink-soft);
  padding: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.mute-icon {
  width: 18px;
  height: 18px;
  display: block;
  flex-shrink: 0;
}

/* По умолчанию: микрофон включён */
.mute-icon--on  { display: block; }
.mute-icon--off { display: none; }

.mute-btn:hover {
  border-color: var(--ink-ghost);
  background: var(--linen);
  box-shadow: var(--shadow-sm);
}

.mute-btn:active {
  box-shadow: none;
}

/* Состояние мьюта — перечёркнутый микрофон, терракотовый акцент */
body.muted .mute-btn {
  background: var(--terra-wash);
  border-color: rgba(196, 98, 58, 0.3);
  color: var(--terra);
  box-shadow: 0 0 0 3px rgba(196, 98, 58, 0.08);
}

body.muted .mute-btn:hover {
  background: rgba(196, 98, 58, 0.14);
  border-color: var(--terra-light);
}

body.muted .mute-icon--on  { display: none; }
body.muted .mute-icon--off { display: block; }

/* ---------- Play / Stop button ---------- */

.play-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--terra);
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease, background 0.3s ease;
  position: relative;

  /* Hide text set by JS */
  font-size: 0;
  color: transparent;
  overflow: hidden;
  line-height: 0;
}

/* Play triangle (idle state) */
.play-btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 54%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 9px 0 9px 16px;
  border-color: transparent transparent transparent #fff;
  transition: all 0.25s ease;
}

.play-btn:hover {
  box-shadow: var(--shadow-lg);
}

.play-btn:active {
  box-shadow: var(--shadow-sm);
}

.play-btn[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

/* Stop square (listening state) */
body.listening .play-btn {
  background: var(--ink-soft);
}

body.listening .play-btn::before {
  border-width: 0;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: #fff;
  left: 50%;
}

body.listening .play-btn:hover {
  background: var(--ink);
}

/* ---------- Chat ---------- */

.chat {
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--cream);
  border: 1px solid var(--linen);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--parchment) transparent;
}

.chat::-webkit-scrollbar {
  width: 5px;
}

.chat::-webkit-scrollbar-track {
  background: transparent;
}

.chat::-webkit-scrollbar-thumb {
  background: var(--parchment);
  border-radius: 4px;
}

.chat-empty {
  color: var(--ink-faint);
  font-size: 0.88rem;
  line-height: 1.5;
  text-align: center;
  font-style: italic;
}

.chat-stream {
  display: grid;
  gap: 12px;
}

/* Messages */
.chat-message {
  display: grid;
  gap: 4px;
  animation: msg-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-message[data-role="user"] {
  justify-items: end;
}

.chat-message[data-role="assistant"] {
  justify-items: start;
}

.chat-bubble {
  max-width: 85%;
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.55;
}

/* User bubble — terracotta tint */
.chat-message[data-role="user"] .chat-bubble {
  background: var(--terra-wash);
  border: 1px solid rgba(196, 98, 58, 0.15);
  border-radius: var(--radius-sm) var(--radius-sm) 4px var(--radius-sm);
  color: var(--ink);
}

/* Assistant bubble — sage tint */
.chat-message[data-role="assistant"] .chat-bubble {
  background: var(--sage-wash);
  border: 1px solid var(--sage-border);
  border-radius: var(--radius-sm) var(--radius-sm) var(--radius-sm) 4px;
  color: var(--ink);
}

.chat-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

/* Streaming */
.chat-message.is-streaming .chat-bubble {
  border-style: dashed;
}

/* ============================================
   Keyframes
   ============================================ */

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

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 5px var(--terra-glow); }
  50% { box-shadow: 0 0 0 8px var(--terra-wash); }
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Layout: панель слева + консоль
   ============================================ */

.layout {
  display: grid;
  grid-template-columns: 0 1fr;
  min-height: 100dvh;
  transition: grid-template-columns 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}
body.panel-open .layout {
  grid-template-columns: 320px 1fr;
}
body.panel-disabled .layout { grid-template-columns: 0 minmax(0, 1fr); }

/* ---------- Панель ---------- */

.panel {
  position: sticky;
  top: 0;
  height: 100dvh;
  width: 320px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--cream), var(--ivory) 60%);
  border-right: 1px solid var(--linen);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.6);
  transform: translateX(-100%);
  opacity: 0;
  transition:
    transform 0.42s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.3s ease;
  overflow: hidden;
}
body.panel-open .panel {
  transform: translateX(0);
  opacity: 1;
}
body.panel-disabled .panel,
body.panel-disabled .panel-tab,
body.panel-disabled .panel-backdrop { display: none; }

.panel-tab-label { display: none; }
.panel-backdrop { display: none; }

:where(button, summary, a):focus-visible {
  outline: 2px solid var(--terra);
  outline-offset: 3px;
}

.panel-head {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 26px 20px 12px 24px;
}
.panel-title {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--ink);
}
.panel-sub {
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--ink-faint);
}
.panel-sub[data-ok="true"] { color: var(--sage); }
.panel-sub[data-ok="false"] { color: var(--terra-light); }

.icon-btn,
.panel-tab {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--linen);
  background: var(--ivory);
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.icon-btn svg,
.panel-tab svg { width: 16px; height: 16px; }
.icon-btn:hover,
.panel-tab:hover { color: var(--ink); border-color: var(--ink-ghost); background: var(--cream); }

/* «Ушко» открытия, живёт у левого края, когда панель скрыта */
.panel-tab {
  position: fixed;
  left: 14px;
  top: 26px;
  z-index: 5;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
body.panel-open .panel-tab {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-10px);
}

/* ---------- Состояние робота ---------- */

.panel-state {
  flex-shrink: 0;
  padding: 4px 24px 14px;
  border-bottom: 1px solid var(--linen);
  display: grid;
  gap: 5px;
}
.state-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}
.state-row--motor { font-size: 0.76rem; color: var(--ink-soft); }
.state-name { font-weight: 500; color: var(--ink); }
.state-tools {
  margin-left: auto;
  font-size: 0.68rem;
  color: var(--ink-faint);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--linen);
}
.state-meta {
  font-size: 0.76rem;
  color: var(--ink-soft);
  padding-left: 16px;
  min-height: 1em;
}
.state-motor { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--ink-ghost);
  transition: background 0.3s, box-shadow 0.3s;
}
.state-dot[data-state="idle"] { background: var(--ink-ghost); }
.state-dot[data-state="stepping"],
.state-dot[data-state="leading"],
.state-dot[data-state="touring"],
.state-dot[data-state="lecturing"] {
  background: var(--terra);
  box-shadow: 0 0 0 4px var(--terra-wash);
  animation: breathe 2.2s ease-in-out infinite;
}
.state-dot[data-link="sim"] { background: var(--ink-ghost); border: 1px dashed var(--ink-faint); }
.state-dot[data-link="up"] { background: var(--sage); }
.state-dot[data-link="down"] { background: var(--terra); }

.fault-armed {
  font-size: 0.72rem;
  color: var(--terra);
  padding-left: 16px;
}

/* ---------- Секции ---------- */

.panel-scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 20px 12px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--parchment) transparent;
}

.sect { border-bottom: 1px solid var(--linen); padding: 10px 0 12px; }
.sect:last-child { border-bottom: none; }
.sect > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.sect > summary::-webkit-details-marker { display: none; }
.sect > summary::before {
  content: "";
  width: 5px;
  height: 5px;
  border-right: 1px solid var(--ink-ghost);
  border-bottom: 1px solid var(--ink-ghost);
  transform: rotate(-45deg);
  transition: transform 0.2s;
}
.sect[open] > summary::before { transform: rotate(45deg); }
.sect > summary:hover { color: var(--ink-soft); }
.sect > *:not(summary) { margin-top: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.row { display: flex; gap: 6px; align-items: center; }
.row + .row { margin-top: 6px; }

.chip {
  font: inherit;
  font-size: 0.8rem;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--parchment);
  background: var(--ivory);
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.12s;
}
.chip:hover { background: var(--cream); border-color: var(--ink-ghost); color: var(--ink); }
.chip:active { transform: scale(0.97); }
.chip--act { background: var(--terra-wash); border-color: rgba(196, 98, 58, 0.25); color: var(--terra); }
.chip--act:hover { background: var(--terra-glow); border-color: var(--terra-light); color: var(--terra); }
.chip--warn { color: var(--terra); }
.chip--wide { width: 100%; text-align: center; }

.input {
  font: inherit;
  font-size: 0.8rem;
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--parchment);
  background: #fff;
  color: var(--ink);
}
.input:focus { outline: none; border-color: var(--terra-light); box-shadow: 0 0 0 3px var(--terra-wash); }
.hint { font-size: 0.7rem; color: var(--ink-faint); line-height: 1.45; }

/* ---------- Лента ---------- */

.feed {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.7rem;
  line-height: 1.6;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.ev { display: flex; gap: 6px; align-items: baseline; padding: 1px 0; }
.ev-ts { color: var(--ink-ghost); flex-shrink: 0; }
.ev-mark { color: var(--ink-faint); width: 10px; text-align: center; flex-shrink: 0; }
.ev-cmd { color: var(--terra); }
.ev-ok { color: var(--sage); }
.ev-err { color: #b5483a; }
.ev > span:nth-child(3) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Стоп / Тихо ---------- */

.panel-foot {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 8px;
  padding: 12px 20px 18px 24px;
  border-top: 1px solid var(--linen);
  background: var(--ivory);
}
.halt {
  font: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  padding: 10px 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--ink-soft);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}
.halt:hover { background: var(--ink); box-shadow: var(--shadow-md); }
.halt--soft { background: var(--cream); color: var(--ink-soft); border-color: var(--parchment); }
.halt--soft:hover { background: var(--linen); color: var(--ink); box-shadow: none; }

/* ============================================
   Вход
   ============================================ */

.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ivory);
  background-image:
    radial-gradient(ellipse 70% 50% at 15% 10%, rgba(196, 98, 58, 0.07), transparent),
    radial-gradient(ellipse 60% 60% at 90% 90%, rgba(107, 143, 113, 0.07), transparent);
}
.gate[hidden] { display: none; }
body.gated .layout { filter: blur(6px); pointer-events: none; }

.gate-card {
  width: min(360px, calc(100vw - 32px));
  padding: 34px 32px 28px;
  border-radius: var(--radius);
  background: var(--cream);
  border: 1px solid var(--linen);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  display: grid;
  gap: 14px;
  animation: rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.gate-eyebrow {
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--terra);
}
.gate-title {
  font-family: "Instrument Serif", Georgia, serif;
  font-weight: 400;
  font-size: 1.7rem;
  line-height: 1.1;
  margin: -6px 0 6px;
}
.field { display: grid; gap: 5px; }
.field span { font-size: 0.74rem; color: var(--ink-faint); }
.field input {
  font: inherit;
  font-size: 0.95rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--parchment);
  background: #fff;
  color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--terra-light); box-shadow: 0 0 0 3px var(--terra-wash); }
.gate-btn {
  margin-top: 6px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 11px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--terra);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s, transform 0.12s;
}
.gate-btn:hover { box-shadow: var(--shadow-lg); }
.gate-btn:active { transform: scale(0.99); }
.gate-btn[disabled] { opacity: 0.6; cursor: wait; }
.gate-error { font-size: 0.8rem; color: var(--terra); min-height: 1.2em; }

/* ============================================
   Responsive: панель как выдвижной ящик
   ============================================ */

@media (max-width: 900px) {
  body.panel-open .layout { grid-template-columns: 0 1fr; }
  .panel {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 20;
    width: min(320px, 88vw);
    box-shadow: var(--shadow-lg);
  }
}

/* Атрибут hidden должен побеждать display:flex индикатора */
.wake-indicator[hidden] { display: none; }

/* ============================================
   Режим «только панель» (панель на роботе)
   ============================================
   На устройстве голос идёт через микрофон и динамик робота, поэтому голосовая
   консоль браузера скрыта, а панель занимает всю ширину и не сворачивается. */

body.panel-only .shell,
body.panel-only .panel-tab,
body.panel-only #panelClose { display: none; }

body.panel-only .layout { grid-template-columns: 1fr; }

body.panel-only .panel {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  border-right: 0;
  transform: none;
  opacity: 1;
}

body.panel-only .panel-foot { grid-template-columns: 1.4fr 1fr; }

.panel-link {
  grid-column: 1 / -1;
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--ink-soft, #7c6f63);
  text-decoration: none;
  text-align: center;
  padding: 8px 0;
  border: 1px solid var(--linen);
  border-radius: var(--radius-sm);
}
.panel-link:hover { color: var(--ink); background: var(--cream); }
.panel-link[hidden] { display: none; }

@media (max-width: 900px) {
  body.panel-only .panel { position: relative; width: 100%; box-shadow: none; }
}

/* ---------- Этаж, экскурсии, проводка (фича #9) ---------- */

.chip[disabled],
.chip[disabled]:hover { opacity: 0.45; cursor: not-allowed; background: var(--ivory); color: var(--ink-soft); transform: none; }
.floor-status { font-size: 0.75rem; color: var(--ink-soft); line-height: 1.5; }
.floor-warn { font-size: 0.72rem; color: var(--terra); line-height: 1.45; }
.tour-list { display: flex; flex-direction: column; gap: 6px; }
.tour-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tour-info { display: flex; flex-direction: column; min-width: 0; }
.tour-title { font-size: 0.78rem; color: var(--ink); line-height: 1.35; }
.tour-reason { font-size: 0.68rem; color: var(--ink-faint); }

/* ============================================
   Телефон: разговор на весь экран, панель поверх него
   ============================================ */

@media (max-width: 900px) {
  :root { --ink-faint: #796b58; }

  .layout {
    display: block;
    height: 100dvh;
    min-height: 0;
  }

  .shell {
    height: 100%;
    min-height: 0;
    padding: calc(14px + env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }

  .console { gap: 12px; min-width: 0; }
  .console-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    min-height: 44px;
    padding-left: 100px;
  }
  .console-title { font-size: clamp(1.2rem, 4.6vw, 1.6rem); }
  .who { min-height: 44px; padding: 8px; font-size: 0.85rem; flex-shrink: 0; }
  .who[hidden] { display: none; }
  .who-divider,
  #whoName { display: none; }
  body.panel-disabled .console-top { padding-left: 0; }

  .status { font-size: 0.9rem; line-height: 1.4; max-width: 100%; }
  .wake-indicator { font-size: 0.85rem; }
  .controls { gap: 12px; flex-shrink: 0; }
  .play-btn {
    width: 180px;
    height: 52px;
    padding: 0 16px 0 42px;
    border-radius: var(--radius-pill);
    font: inherit;
    font-weight: 500;
    color: #fff;
    line-height: 1.3;
  }
  .play-btn::before {
    left: 26px;
    border-width: 7px 0 7px 12px;
  }
  body.listening .play-btn::before { left: 26px; width: 14px; height: 14px; }
  .mute-btn { width: 52px; height: 52px; }
  .mute-icon { width: 21px; height: 21px; }

  .chat { padding: 14px; gap: 12px; overscroll-behavior-y: contain; }
  .chat-bubble { max-width: 94%; padding: 12px 14px; }
  .chat-text { font-size: 1rem; line-height: 1.55; }
  .chat-empty { font-size: 0.95rem; }

  .panel-tab {
    top: calc(14px + env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
    width: auto;
    height: 44px;
    padding: 0 10px;
    gap: 6px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    font: inherit;
    font-size: 0.85rem;
  }
  .panel-tab svg { width: 18px; height: 18px; }
  .panel-tab-label { display: inline; }
  .panel {
    width: min(380px, calc(100vw - 28px));
    height: 100dvh;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
  }
  .panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 15;
    display: block;
    background: rgba(44, 36, 24, 0.38);
    touch-action: none;
  }
  .panel-backdrop[hidden] { display: none; }
  body.panel-modal { overflow: hidden; }
  .panel-head { padding: 16px 16px 8px; align-items: center; }
  .panel-title { font-size: 1.6rem; }
  .panel-sub { font-size: 0.85rem; }
  .icon-btn { width: 44px; height: 44px; flex-shrink: 0; }
  .icon-btn svg { width: 20px; height: 20px; }
  .panel-state { padding: 4px 16px 12px; }
  .state-row { flex-wrap: wrap; row-gap: 6px; }
  .state-tools { font-size: 0.75rem; }
  .state-row--motor,
  .state-meta,
  .fault-armed { font-size: 0.85rem; line-height: 1.4; }
  .state-meta { overflow-wrap: anywhere; }
  .state-motor { max-width: calc(100% - 16px); }
  .panel-scroll { padding: 4px 16px 12px; overscroll-behavior-y: contain; }
  .sect { padding: 6px 0 12px; }
  .sect > summary { min-height: 44px; font-size: 0.8rem; letter-spacing: 0.04em; }
  .sect > summary::before { flex-shrink: 0; }
  .chips { gap: 8px; }
  .chip { min-height: 44px; max-width: 100%; padding: 9px 12px; font-size: 0.9rem; white-space: normal; overflow-wrap: anywhere; }
  .row { gap: 8px; }
  .row > .chip { flex-shrink: 0; }
  .input { min-height: 44px; font-size: 1rem; padding: 10px; }
  .hint,
  .floor-status,
  .floor-warn,
  .tour-reason { font-size: 0.85rem; line-height: 1.5; }
  .hint,
  .tour-reason { color: var(--ink-soft); }
  .tour-row { align-items: flex-start; gap: 10px; }
  .tour-title { font-size: 0.95rem; line-height: 1.4; }
  .tour-row > .chip { flex-shrink: 0; }
  .feed { font-size: 0.8rem; }
  .panel-foot {
    padding: 12px 16px max(16px, env(safe-area-inset-bottom));
  }
  .halt { min-height: 48px; font-size: 1rem; }
  .panel-link { min-height: 44px; font-size: 0.9rem; }

  .gate {
    padding: max(16px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    overflow-y: auto;
  }
  .gate-card { width: min(360px, 100%); margin-block: auto; padding: 28px 24px; flex-shrink: 0; }
  .field span { font-size: 0.85rem; }
  .field input { min-width: 0; min-height: 48px; font-size: 1rem; }
  .gate-btn { min-height: 48px; font-size: 1rem; }

  body.panel-only .panel { max-width: 100%; }
}

@media (max-width: 900px) and (max-height: 500px) {
  .console { gap: 8px; }
  .shell { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .panel-tab { top: max(8px, env(safe-area-inset-top)); }
  .panel-head { padding-top: 8px; padding-bottom: 4px; }
  .panel-state { padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
