/* ============================================================
   AI CIRCLES — FACILITATOR CONSOLE
   Brand: #184E57 teal / #D4A855 gold / #F6F4F1 cream
   Typography: Playfair Display + Inter
   ============================================================ */

/* --- Design tokens --- */
:root {
  --teal-900: #11323b;
  --teal-800: #154149;
  --teal-700: #184e57;
  --teal-300: #8fccd6;
  --teal-100: #d6edf1;

  --gold-700: #8a6d28;
  --gold-600: #c49a45;
  --gold-500: #d4a855;
  --gold-400: #e2be78;
  --gold-200: #e8d8a1;
  --gold-50: #faf6ea;

  --cream: #f6f4f1;
  --white: #ffffff;

  --ink: #1a1a1a;
  --muted: #6d6e71;
  --subtle: #767c85;
  --border: #e5e7eb;
  --border-teal: rgba(24, 78, 87, 0.1);

  --green: #2e7d32;
  --red: #c62828;

  --shadow-sm: 0 1px 3px rgba(24, 78, 87, 0.07), 0 1px 2px rgba(24, 78, 87, 0.04);
  --shadow-md: 0 4px 14px rgba(24, 78, 87, 0.09), 0 2px 4px rgba(24, 78, 87, 0.05);

  --radius-sm: 7px;
  --radius-md: 11px;
  --radius-lg: 16px;

  --ease: 160ms ease;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--cream);
  min-height: 100vh;
}

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */

.login-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 60%, rgba(143, 204, 214, 0.15) 0%, transparent 60%),
    linear-gradient(145deg, var(--teal-900) 0%, var(--teal-700) 45%, #1a6070 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* Decorative concentric circle rings in background */
.login-overlay::before,
.login-overlay::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(212, 168, 85, 0.1);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.login-overlay::before {
  width: min(80vw, 600px);
  height: min(80vw, 600px);
}
.login-overlay::after {
  width: min(130vw, 1000px);
  height: min(130vw, 1000px);
  border-color: rgba(212, 168, 85, 0.05);
}

.login-card {
  background: rgba(255, 255, 255, 0.97);
  border-radius: var(--radius-lg);
  padding: 52px 44px;
  max-width: 400px;
  width: calc(100% - 32px);
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.28),
    0 4px 12px rgba(0, 0, 0, 0.1);
  text-align: center;
  position: relative;
  z-index: 1;
}

.login-brand {
  margin-bottom: 36px;
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.login-brand h1 {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--teal-700);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.login-subtitle {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-700);
  margin-top: 8px;
}

.login-form p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 20px;
}

.login-form input {
  width: 100%;
  padding: 13px 16px;
  font-size: 0.9rem;
  font-family: "Inter", sans-serif;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: white;
  color: var(--ink);
  transition:
    border-color var(--ease),
    box-shadow var(--ease);
  margin-bottom: 12px;
}

.login-form input:focus {
  outline: none;
  border-color: var(--teal-700);
  box-shadow: 0 0 0 3px rgba(24, 78, 87, 0.1);
}

.login-form button {
  width: 100%;
  padding: 14px 24px;
  font-size: 0.95rem;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  background: var(--teal-700);
  color: white;
  letter-spacing: 0.02em;
  transition:
    background var(--ease),
    box-shadow var(--ease),
    transform 80ms ease;
}

.login-form button:hover {
  background: var(--teal-800);
  box-shadow: 0 4px 14px rgba(24, 78, 87, 0.3);
}

.login-form button:active {
  transform: translateY(1px);
}

.login-error {
  color: var(--red);
  font-size: 0.82rem;
  margin-top: 10px;
  min-height: 1.2em;
}

/* ============================================================
   APP HEADER
   ============================================================ */

.app-header {
  background: var(--teal-700);
  border-bottom: 1px solid rgba(212, 168, 85, 0.18);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 15px 28px;
  display: flex;
  align-items: center;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-title {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.44rem;
  font-weight: 700;
  color: white;
  line-height: 1;
  letter-spacing: -0.01em;
}

.header-subtitle {
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--gold-400);
}

/* ============================================================
   TAB BAR
   ============================================================ */

.tab-bar {
  display: flex;
  gap: 0;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 28px;
  border-bottom: 1px solid rgba(212, 168, 85, 0.18);
  background: var(--teal-700);
}

.tab {
  padding: 11px 20px;
  font-family: "Inter", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.75);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  cursor: pointer;
  transition:
    color var(--ease),
    border-color var(--ease);
  white-space: nowrap;
}

.tab:hover {
  color: rgba(255, 255, 255, 0.85);
  background: none;
  box-shadow: none;
  transform: none;
}

.tab:active {
  transform: none;
}

.tab.active {
  color: var(--gold-400);
  border-bottom-color: var(--gold-400);
}

/* ============================================================
   TAB PANELS
   ============================================================ */

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */

.app-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 28px 72px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-teal);
}

.card-title {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--teal-700);
  margin-bottom: 20px;
  letter-spacing: -0.01em;
}

/* Gold-trimmed hero card for the primary action */
.hero-card {
  border: 1.5px solid rgba(212, 168, 85, 0.35);
  box-shadow:
    0 4px 20px rgba(212, 168, 85, 0.1),
    var(--shadow-sm);
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */

.field-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="url"],
input[type="password"],
input[type="number"],
input[type="text"],
textarea,
select {
  font-family: "Inter", sans-serif;
  font-size: 0.875rem;
  color: var(--ink);
  background: white;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  transition:
    border-color var(--ease),
    box-shadow var(--ease);
  width: 100%;
}

input[type="url"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--teal-700);
  box-shadow: 0 0 0 3px rgba(24, 78, 87, 0.08);
}

input[type="url"]::placeholder,
textarea::placeholder {
  color: var(--subtle);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7'%3E%3Cpath d='M1 1l4.5 4.5L10 1' stroke='%236D6E71' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

select:disabled {
  background-color: #f5f5f5;
  color: var(--subtle);
  cursor: not-allowed;
}

/* ============================================================
   CUSTOM SELECT DROPDOWN
   ============================================================ */

.custom-select {
  position: relative;
  width: 100%;
}

.custom-select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  font-family: "Inter", sans-serif;
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--ink);
  background: white;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition:
    border-color var(--ease),
    box-shadow var(--ease);
  letter-spacing: normal;
  box-shadow: none;
  transform: none !important;
}

.custom-select-trigger:hover:not(:disabled) {
  border-color: var(--teal-300);
  box-shadow: none;
}

.custom-select.open .custom-select-trigger {
  border-color: var(--border);
  box-shadow: none;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.custom-select-trigger svg {
  flex-shrink: 0;
  color: var(--muted);
  transition: transform var(--ease);
}

.custom-select.open .custom-select-trigger svg {
  transform: rotate(180deg);
}

.custom-select-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1.5px solid var(--border);
  border-top: none;
  border-bottom-left-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  list-style: none;
  margin: 0;
  padding: 4px 0;
  z-index: 50;
  max-height: 220px;
  overflow-y: auto;
}

.custom-select.open .custom-select-dropdown {
  display: block;
}

.custom-select-option {
  padding: 9px 14px;
  font-family: "Inter", sans-serif;
  font-size: 0.875rem;
  color: var(--ink);
  cursor: pointer;
  transition:
    background var(--ease),
    color var(--ease);
}

.custom-select-option:hover {
  background: var(--teal-100);
  color: var(--teal-700);
}

.custom-select-option.selected {
  background: var(--gold-50);
  color: var(--teal-700);
  font-weight: 500;
}

/* Disabled state */
.custom-select.disabled .custom-select-trigger {
  background: #f5f5f5;
  color: var(--subtle);
  cursor: not-allowed;
  border-color: var(--border);
  box-shadow: none;
}

textarea {
  resize: vertical;
  line-height: 1.65;
  min-height: 140px;
}

/* ============================================================
   CONFIGURATION SECTION
   ============================================================ */

.config-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.config-selects {
  display: flex;
  gap: 16px;
}

.config-selects .field-group {
  flex: 1;
}

/* ============================================================
   SYSTEM PROMPT SECTION
   ============================================================ */

.prompt-section .card-title {
  margin-bottom: 0;
}

.prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.save-status {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.3s;
}

.save-status.visible {
  opacity: 1;
}

.session-fields {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.session-fields .field-group {
  flex: 0 1 auto;
}

.session-fields input[type="number"] {
  width: 80px;
}

.session-fields input[type="text"] {
  width: 180px;
}

#systemPrompt {
  margin-bottom: 12px;
}

/* ============================================================
   BOT SECTION
   ============================================================ */

.bot-section .card-title {
  margin-bottom: 16px;
}

.bot-input-row {
  display: flex;
  gap: 10px;
}

.bot-input-row input {
  flex: 1;
}

.bot-status {
  font-size: 0.82rem;
  font-weight: 500;
  margin-top: 10px;
  min-height: 1.2em;
}

.bot-status.success {
  color: var(--green);
}
.bot-status.error {
  color: var(--red);
}

/* Tunnel status indicator */
.tunnel-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 0.85rem;
}

.tunnel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tunnel-dot.connected {
  background: #34d399;
  box-shadow: 0 0 4px #34d39966;
}

.tunnel-dot.disconnected {
  background: #f87171;
  box-shadow: 0 0 4px #f8717166;
}

.tunnel-label {
  color: var(--text-muted, #888);
  word-break: break-all;
}

/* ============================================================
   BUTTONS
   ============================================================ */

button {
  font-family: "Inter", sans-serif;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition:
    background var(--ease),
    box-shadow var(--ease),
    transform 80ms ease;
  white-space: nowrap;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Secondary: light background, teal text */
.btn-secondary {
  padding: 10px 18px;
  font-size: 0.83rem;
  background: var(--cream);
  color: var(--teal-700);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: white;
  border-color: var(--teal-300);
  box-shadow: 0 2px 6px rgba(24, 78, 87, 0.1);
}

/* Gold: primary call-to-action */
.btn-gold {
  padding: 10px 26px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--gold-500);
  color: var(--teal-900);
  box-shadow: 0 2px 8px rgba(212, 168, 85, 0.35);
  letter-spacing: 0.01em;
}

.btn-gold:hover:not(:disabled) {
  background: var(--gold-600);
  box-shadow: 0 4px 16px rgba(212, 168, 85, 0.45);
}

/* Teal: start conversation */
.btn-teal {
  padding: 11px 28px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--teal-700);
  color: white;
}

.btn-teal:hover:not(:disabled) {
  background: var(--teal-800);
  box-shadow: 0 4px 12px rgba(24, 78, 87, 0.28);
}

/* Stop: outlined red */
.btn-stop {
  padding: 11px 24px;
  font-size: 0.9rem;
  background: white;
  color: var(--red);
  border: 1.5px solid rgba(198, 40, 40, 0.28);
}

.btn-stop:hover:not(:disabled) {
  background: rgba(198, 40, 40, 0.05);
  border-color: var(--red);
}

/* ============================================================
   SESSION SECTION
   ============================================================ */

.session-top-row {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 16px;
}

.session-top-row .config-selects {
  flex: 1;
}

.session-top-row .controls {
  margin-bottom: 0;
}

.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

#status {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  color: var(--muted);
  background: var(--cream);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

#status.connected {
  background: #e8f5e9;
  color: var(--green);
  border-color: rgba(46, 125, 50, 0.2);
}

/* Animated pulse dot when connected */
#status.connected::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}

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

#status.error {
  background: #ffebee;
  color: var(--red);
  border-color: rgba(198, 40, 40, 0.2);
}

/* ============================================================
   USAGE TRACKER
   ============================================================ */

/* --- Lucy state indicator --- */
.lucy-state-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  margin-bottom: 12px;
}

.lucy-state-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.lucy-state-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lucy-state-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition:
    background 0.3s ease,
    box-shadow 0.3s ease;
}

.lucy-state-text {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--subtle);
  transition: color 0.3s ease;
}

/* Silent state */
#lucyStateCard[data-state="silent"] .lucy-state-dot {
  background: var(--muted);
  box-shadow: none;
}
#lucyStateCard[data-state="silent"] .lucy-state-text {
  color: var(--muted);
}

/* Active conversation state */
#lucyStateCard[data-state="active"] .lucy-state-dot {
  background: var(--teal-700);
  box-shadow: 0 0 0 3px var(--teal-100);
}
#lucyStateCard[data-state="active"] .lucy-state-text {
  color: var(--teal-700);
}

/* Speaking state */
#lucyStateCard[data-state="speaking"] .lucy-state-dot {
  background: var(--gold-500);
  box-shadow: 0 0 0 3px var(--gold-50);
  animation: state-pulse 1s ease-in-out infinite;
}
#lucyStateCard[data-state="speaking"] .lucy-state-text {
  color: var(--gold-700);
}

@keyframes state-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 3px var(--gold-50);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(212, 168, 85, 0.15);
  }
}

.usage {
  display: none;
}

.usage.visible {
  display: block;
}

.usage-label-row {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.usage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.usage-item {
  text-align: center;
}

.usage-value {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--teal-700);
}

.usage-label {
  font-size: 0.7rem;
  color: var(--subtle);
  margin-top: 3px;
}

/* ============================================================
   EVENT LOG
   ============================================================ */

.log-section .card-title {
  margin-bottom: 14px;
}

#log {
  padding: 16px 18px;
  background: var(--teal-900);
  border-radius: var(--radius-sm);
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.78rem;
  max-height: 280px;
  overflow-y: auto;
  color: var(--teal-300);
  line-height: 1.75;
}

#log div {
  border-bottom: 1px solid rgba(143, 204, 214, 0.07);
  padding: 1px 0 3px;
}

#log div:last-child {
  border-bottom: none;
}

#log::-webkit-scrollbar {
  width: 4px;
}
#log::-webkit-scrollbar-track {
  background: transparent;
}
#log::-webkit-scrollbar-thumb {
  background: rgba(143, 204, 214, 0.2);
  border-radius: 2px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 640px) {
  .app-main {
    padding: 24px 16px 56px;
    gap: 16px;
  }

  .card {
    padding: 22px 20px;
  }

  .tab-bar {
    padding: 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    padding: 10px 14px;
    font-size: 0.75rem;
  }

  .header-inner {
    padding: 14px 16px;
  }

  .config-selects {
    flex-direction: column;
  }

  .bot-input-row {
    flex-direction: column;
  }

  .bot-input-row .btn-gold {
    width: 100%;
    text-align: center;
  }

  .session-top-row {
    flex-direction: column;
    align-items: stretch;
  }

  .controls {
    flex-direction: column;
  }

  .controls button {
    width: 100%;
    text-align: center;
  }

  .login-card {
    padding: 40px 24px;
  }

  .login-brand h1 {
    font-size: 1.85rem;
  }
}

/* --- Bot avatar (shown inside Recall.ai's headless browser) --- */
#botAvatar {
  width: 100vw;
  height: 100vh;
  background: #0d3b3b;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: background 0.4s ease;
}

/* Active conversation: warmer background tint */
#botAvatar[data-state="active"] {
  background: #0d2e3b;
}

/* Speaking: darker background + pulsing ring on the image */
#botAvatar[data-state="speaking"] {
  background: #0a1f2e;
}

#botAvatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition:
    box-shadow 0.3s ease,
    opacity 0.3s ease;
}

/* Silent: slightly dimmed */
#botAvatar[data-state="silent"] img {
  opacity: 0.75;
}

/* Active: full brightness */
#botAvatar[data-state="active"] img {
  opacity: 1;
}

/* Speaking: full brightness + animated glow ring */
#botAvatar[data-state="speaking"] img {
  opacity: 1;
  animation: speaking-pulse 1s ease-in-out infinite;
}

@keyframes speaking-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(212, 168, 85, 0);
  }
  50% {
    box-shadow: 0 0 0 18px rgba(212, 168, 85, 0.25);
  }
}
