:root {
  color-scheme: light dark;
  --bg: #eef7f8;
  --card: #ffffff;
  --text: #17313a;
  --muted: #667985;
  --border: #d7e7eb;
  --primary: #256f84;
  --primary-dark: #1b5363;
  --accent: #d9f0ef;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(31, 82, 99, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at top left, #dff5f3 0, transparent 34rem), var(--bg);
  color: var(--text);
}

.secretary-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 2rem auto 4rem;
  padding-top: 1rem;
}

.card {
  background: color-mix(in srgb, var(--card) 94%, transparent);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 1.4rem;
  margin-bottom: 1.2rem;
}

.hero, .controls, .panel-heading, .button-row, .status-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.hero { padding: 2rem; }
.hero h1 { margin: 0.15rem 0 0.4rem; font-size: clamp(2rem, 6vw, 4rem); letter-spacing: -0.04em; }
.lede { max-width: 760px; color: var(--muted); font-size: 1.05rem; line-height: 1.65; }
.eyebrow { margin: 0 0 0.35rem; color: var(--primary); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.12em; font-weight: 800; }
.muted { color: var(--muted); }

.status-card {
  min-width: 240px;
  justify-content: flex-start;
  background: var(--accent);
  border-radius: 18px;
  padding: 1rem;
}
.status-card span:last-child, #connectionHint { display: block; color: var(--muted); font-size: 0.9rem; }
.status-dot { width: 0.9rem; height: 0.9rem; border-radius: 50%; background: #8fa4ad; box-shadow: 0 0 0 5px rgba(143,164,173,.18); }
.status-dot.ready, .status-dot.ended, .status-dot.readySummary { background: #8fa4ad; box-shadow: 0 0 0 5px rgba(143,164,173,.18); }
.status-dot.connecting { background: #f59e0b; box-shadow: 0 0 0 5px rgba(245,158,11,.18); }
.status-dot.connected, .status-dot.listening { background: #16a34a; box-shadow: 0 0 0 5px rgba(22,163,74,.18); }
.status-dot.speaking, .status-dot.generating { background: #2563eb; box-shadow: 0 0 0 5px rgba(37,99,235,.18); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 5px rgba(180,35,24,.18); }

button, .link-button {
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .16s ease, background .16s ease, opacity .16s ease;
}
button:hover, .link-button:hover { transform: translateY(-1px); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.secondary { background: #e5f2f5; color: var(--primary-dark); }
.ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }

.grid { display: grid; gap: 1.2rem; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.wrap { flex-wrap: wrap; }

.transcript {
  min-height: 420px;
  max-height: 58vh;
  overflow: auto;
  background: #f8fcfd;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
}
.turn { margin: 0 0 0.85rem; padding: 0.8rem 0.9rem; border-radius: 14px; background: #fff; border: 1px solid #e6eef1; }
.turn strong { display: block; color: var(--primary); margin-bottom: 0.25rem; }

.json-output, .prompt-preview, .code-editor {
  width: 100%;
  background: #092b35;
  color: #e9fbff;
  border: 1px solid #164857;
  border-radius: 16px;
  padding: 1rem;
  overflow: auto;
  white-space: pre-wrap;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 0.88rem;
  line-height: 1.55;
}
.json-output { min-height: 420px; }
.prompt-preview { min-height: 680px; }
.prompt-preview.compact { min-height: 180px; }

label { display: grid; gap: .45rem; font-weight: 750; color: var(--text); }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: #fbfeff;
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
.email-preview label { margin-top: 1rem; }
.email-preview textarea { min-height: 280px; }

.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.settings-form .full { grid-column: 1 / -1; }

.debug-panel {
  width: 100%;
  margin-top: 1rem;
  border: 1px dashed var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 62%, transparent);
  padding: 1rem;
}
.debug-grid {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.45rem 0.85rem;
  margin: 0;
  font-size: 0.9rem;
}
.debug-grid dt {
  color: var(--muted);
  font-weight: 800;
}
.debug-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.message, .error-box {
  margin-top: 1rem;
  border-radius: 14px;
  padding: 0.85rem 1rem;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
}
.message.success { background: #ecfdf5; color: #166534; border-color: #bbf7d0; }
.error-box { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.error-box p { margin: 0 0 .35rem; }
.error-box p:last-child { margin-bottom: 0; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #07191f;
    --card: #102a33;
    --text: #eefbff;
    --muted: #a9c2ca;
    --border: #244853;
    --primary: #75d1e8;
    --primary-dark: #b8edf8;
    --accent: #143843;
    --shadow: 0 18px 50px rgba(0,0,0,.32);
  }
  .secondary { background: #163843; color: #e4fbff; }
  input, textarea, select, .transcript, .turn { background: #0b2028; color: var(--text); border-color: var(--border); }
}

@media (max-width: 820px) {
  .hero, .controls, .panel-heading { align-items: stretch; flex-direction: column; }
  .button-row { flex-wrap: wrap; justify-content: flex-start; }
  .grid.two, .settings-form { grid-template-columns: 1fr; }
  .status-card { min-width: 0; width: 100%; }
}

.panel-heading.slim { margin-bottom: 0.75rem; }
.panel-heading.slim h3 { margin: 0 0 0.25rem; }
.button-row.compact { gap: 0.45rem; justify-content: flex-end; }
.button-row.compact button { padding: 0.55rem 0.75rem; font-size: 0.86rem; }
.location-editor {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}
.location-list { display: grid; gap: 1rem; }
.empty-state {
  margin: 0;
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 1rem;
  color: var(--muted);
  background: #f8fcfd;
}
.location-card {
  display: grid;
  gap: 1rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
  background: var(--card);
  box-shadow: 0 10px 28px rgba(31, 82, 99, 0.08);
}
.location-card.inactive { opacity: 0.76; }
.location-card__heading {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
}
.location-card__heading h3 { margin: 0 0 0.45rem; }
.location-card__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.location-card__grid .full { grid-column: 1 / -1; }
.location-card__grid.nested { align-self: start; }
.location-fieldset {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
}
.location-fieldset legend { padding: 0 0.35rem; font-weight: 800; }
.checkbox-label {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
}
.checkbox-label input { width: auto; }
.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 850;
}
.status-pill.active { background: #dcfce7; color: #166534; }
.status-pill.inactive { background: #fee2e2; color: #991b1b; }

@media (prefers-color-scheme: dark) {
  .empty-state { background: #0b2028; }
  .location-card { background: #102a33; }
  .status-pill.active { background: #14532d; color: #dcfce7; }
  .status-pill.inactive { background: #7f1d1d; color: #fee2e2; }
}

@media (max-width: 820px) {
  .location-card__heading, .button-row.compact { align-items: stretch; flex-direction: column; }
  .location-card__grid { grid-template-columns: 1fr; }
}
