:root {
  color-scheme: light;
  --bg: #f3efe6;
  --panel: rgba(255, 252, 246, 0.92);
  --text: #1f2933;
  --muted: #617180;
  --border: rgba(31, 41, 51, 0.12);
  --border-strong: rgba(31, 41, 51, 0.2);
  --primary: #0b7a75;
  --primary-dark: #075b57;
  --danger: #c44536;
  --danger-dark: #943025;
  --shadow: 0 24px 60px rgba(36, 54, 66, 0.14);
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(214, 228, 219, 0.9), transparent 32%),
    radial-gradient(circle at top right, rgba(255, 210, 163, 0.45), transparent 28%),
    linear-gradient(180deg, #f7f3eb 0%, #ece6dc 100%);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  padding: 10px;
}

.screen { width: 100%; }
.screen[hidden] { display: none; }
.screen-active { display: grid; min-height: calc(100vh - 20px); place-items: center; }

.setup-card, .card {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.setup-card {
  width: min(100%, 460px);
  padding: 18px;
  display: grid;
  gap: 14px;
}

.setup-icons {
  display: flex;
  gap: 10px;
}

.setup-icon {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(11, 122, 117, .1);
  font-size: 1.2rem;
}

h1, h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

h2 {
  font-size: 1.1rem;
}

.subtitle { color: var(--muted); }

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-weight: 700;
  font-size: .92rem;
}

select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: rgba(255, 255, 255, .92);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}

textarea {
  min-height: 52px;
  max-height: 180px;
}

select:focus, textarea:focus {
  border-color: rgba(11, 122, 117, .55);
  box-shadow: 0 0 0 4px rgba(11, 122, 117, .14);
}

.switch-row {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: .94rem;
}

.primary, .danger, .ghost-btn {
  border: 0;
  border-radius: 16px;
  font-weight: 700;
  transition: transform .16s ease, opacity .16s ease;
}

.primary, .danger { color: #fff; }
.primary:hover, .danger:hover, .ghost-btn:hover { transform: translateY(-1px); }
.primary:disabled, .danger:disabled { opacity: .55; cursor: default; transform: none; }

.primary { background: linear-gradient(180deg, var(--primary), var(--primary-dark)); }
.danger { background: linear-gradient(180deg, var(--danger), var(--danger-dark)); }

.ghost-btn {
  padding: 8px 12px;
  background: rgba(11, 122, 117, .08);
  color: var(--primary-dark);
  border: 1px solid rgba(11, 122, 117, .16);
}

.setup-start {
  width: 100%;
  padding: 14px 18px;
  font-size: 1rem;
}

.screen-chat, .chat-layout {
  min-height: calc(100vh - 20px);
  height: calc(100vh - 20px);
}

.chat-layout {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
}

.chat-header {
  padding: 10px 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.status-badge {
  min-width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-idle { background: rgba(97, 113, 128, .12); color: #556472; border-color: rgba(97, 113, 128, .18); }
.status-live { background: rgba(23, 160, 132, .16); color: #0f6f5c; border-color: rgba(23, 160, 132, .26); }
.status-busy { background: rgba(219, 139, 0, .16); color: #9c6300; border-color: rgba(219, 139, 0, .24); }

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1.15rem;
}

.chat-panel {
  min-height: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-list {
  min-height: 0;
  height: 100%;
  overflow: auto;
  display: grid;
  gap: 10px;
  padding: 2px;
  scroll-behavior: smooth;
}

.history-list.empty { display: block; }

.empty-state {
  display: grid;
  place-items: center;
  min-height: 100%;
  color: var(--muted);
  text-align: center;
  padding: 24px 16px;
}

.empty-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 10;
  padding: 10px 12px;
  background: rgba(255, 252, 246, 0.98);
}

.composer-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .9rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 0 5px rgba(11, 122, 117, 0.1);
}

.language-pill {
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(11, 122, 117, .1);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: .85rem;
}

.composer-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.composer-input-wrap {
  display: block;
  min-width: 0;
}

.send-btn {
  flex: 0 0 auto;
}

.notifications {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(100vw - 24px, 620px);
  display: grid;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.notice {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(28, 36, 44, .9);
  color: #fff;
  box-shadow: 0 10px 22px rgba(16, 25, 34, .2);
  opacity: 1;
  transform: translateY(0);
  transition: opacity .22s ease, transform .22s ease;
}

.notice-hiding {
  opacity: 0;
  transform: translateY(-8px);
}

.notice.success { background: rgba(15, 111, 92, .95); }
.notice.warn { background: rgba(156, 99, 0, .95); }
.notice.error { background: rgba(148, 48, 37, .96); }
.notice-subtitle {
  background: rgba(11, 122, 117, 0.96);
  font-size: 1rem;
  line-height: 1.35;
}

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

.message-card {
  width: min(82%, 880px);
  border: 1px solid rgba(31, 41, 51, .08);
  border-radius: 22px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: rgba(255, 255, 255, .88);
}

.message-card.speaker-ru {
  justify-self: start;
  border-bottom-left-radius: 8px;
  background: linear-gradient(180deg, rgba(229, 246, 242, .96), rgba(219, 240, 235, .96));
}

.message-card.speaker-target {
  justify-self: end;
  border-bottom-right-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 240, 236, .96), rgba(251, 229, 223, .96));
}

.partial-card {
  opacity: 0.86;
  border-style: dashed;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: .82rem;
  flex-wrap: wrap;
}

.message-speaker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
}

.speaker-chip {
  display: inline-flex;
  min-width: 38px;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(11, 122, 117, .14);
  color: var(--primary-dark);
}

.speaker-target .speaker-chip {
  background: rgba(196, 69, 54, .14);
  color: var(--danger-dark);
}

.phrase-grid {
  display: grid;
  gap: 8px;
}

.phrase-block {
  border: 1px solid rgba(31, 41, 51, .06);
  border-radius: 16px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .72);
}

.phrase-label {
  font-size: .74rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}

.phrase-text {
  white-space: pre-wrap;
  line-height: 1.42;
  font-size: 1.02rem;
}

.message-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.audio-tag {
  font-size: .78rem;
  color: var(--muted);
}

.timings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: .76rem;
  border-top: 1px solid rgba(31, 41, 51, .08);
  padding-top: 8px;
}

@media (max-width: 720px) {
  .app-shell { padding: 8px; }
  .screen-chat, .chat-layout {
    min-height: calc(100vh - 16px);
    height: calc(100vh - 16px);
  }
  .screen-active { min-height: calc(100vh - 16px); }
  .setup-card { width: 100%; padding: 14px; }
  .message-card { width: min(92%, 880px); }
  .composer-top { align-items: flex-start; }
}
