:root {
  color-scheme: light;
  font-family: Arial, sans-serif;
  --primary-color: #0f766e;
  --primary-color-hover: #0d5f59;
  --border-color: #d6e2f0;
  --bg-light: #eef4fb;
  --surface-bg: #ffffff;
  --text-dark: #334155;
  --text-body: #1f2937;
  --section-border: #8ca3bf;
  --section-bg-start: #f6f9ff;
  --section-bg-end: #eaf1fb;
  --input-border: #bfd0e3;
  --log-bg: #0f172a;
  --conversation-bg: #12336f;
  --error-bg: #4a1317;
  --status-idle: #2563eb;
  --status-error: #dc2626;
  --status-working: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg-light);
  color: var(--text-body);
  font-size: 16px;
}

.app {
  max-width: 90vw;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  gap: 12px;
}

@media (max-width: 768px) {
  .app {
    padding: 8px;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 6px;
    gap: 6px;
  }

  body {
    font-size: 14px;
  }
}

.app-brand {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.app-brand.section-intro {
  display: block;
}

.app-brand.section-intro h2 {
  margin-bottom: 8px;
}

.section-explainer {
  margin: 0;
}

.section-explainer summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 6px;
}

.section-explainer .section-title-summary {
  margin-bottom: 8px;
  font-size: clamp(1rem, 4vw, 1.5rem);
  font-weight: 700;

#htmlPopupArea {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 6px;
}

.html-popup-btn {
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}

.html-popup-btn:hover {
  background: #1558b0;
}
}

.section-explainer p {
  margin: 6px 0;
  font-size: clamp(0.9rem, 1.9vw, 1rem);
  line-height: 1.35;
}

.app-logo {
  width: auto;
  height: 1.8em;
  flex: 0 0 auto;
  vertical-align: baseline;
}

.app-brand h1 {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(1.2rem, 5vw, 2rem);
  flex-wrap: wrap;
  justify-content: center;
}

@media (max-width: 480px) {
  .app-logo {
    height: 1.5em;
  }

  .app-brand h1 {
    gap: 6px;
  }
}

h1, h2 {
  margin: 0 0 8px;
  font-size: clamp(1rem, 4vw, 1.5rem);
}

.top-level-section {
  border: 2px solid var(--section-border);
  border-radius: 12px;
  padding: 14px;
  display: grid;
  gap: 12px;
  background: linear-gradient(180deg, var(--section-bg-start) 0%, var(--section-bg-end) 100%);
  box-shadow: 0 10px 24px rgba(51, 65, 85, 0.14);
}

@media (max-width: 768px) {
  .top-level-section {
    padding: 10px;
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .top-level-section {
    padding: 8px;
    gap: 8px;
    border-radius: 8px;
  }
}

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

.panel-header h2 {
  margin: 0;
  flex: 1 1 auto;
}

.panel {
  background: var(--surface-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
}

@media (max-width: 480px) {
  .panel {
    padding: 10px;
    border-radius: 6px;
  }
}

.diagnostics-content {
  display: grid;
  gap: 12px;
}

.diagnostics-content[hidden] {
  display: none;
}

.controls {
  display: grid;
  gap: 8px;
  grid-auto-columns: minmax(0, 1fr);
}

.controls > label:not(.inline) {
  font-size: clamp(0.95rem, 2vw, 1.2rem);
  font-weight: 600;
}

.utterance-label {
  font-size: clamp(0.95rem, 2vw, 1.2rem);
  font-weight: 600;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  .row {
    gap: 6px;
  }
}

.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(0.9rem, 2vw, 1rem);
}

input[type="text"],
input:not([type]),
select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--surface-bg);
  font-family: inherit;
  font-size: inherit;
}

@media (max-width: 480px) {
  input[type="text"],
  input:not([type]),
  select {
    max-width: 100%;
    padding: 10px;
    font-size: 16px;
  }
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary-color);
  color: white;
  padding: 8px 12px;
  cursor: pointer;
  font-size: clamp(0.9rem, 2vw, 1rem);
  white-space: nowrap;
}

button:hover:not(:disabled) {
  background: var(--primary-color-hover);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

@media (max-width: 480px) {
  button {
    padding: 10px 14px;
    flex: 1 1 auto;
    min-width: 120px;
  }
}

.floor-btn-grant {
  background: #86efac;
  color: #14532d;
}

#conversation,
#eventLog,
#errorLog {
  min-height: 120px;
  max-height: 260px;
  overflow: auto;
  margin: 0;
  background: var(--log-bg);
  color: #e2e8f0;
  border-radius: 6px;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: clamp(0.75rem, 1.5vw, 0.875rem);
  line-height: 1.4;
}

#conversation {
  background: var(--conversation-bg);
  font-size: clamp(1rem, 2.1vw, 1.15rem);
}

.conversation-container {
  position: relative;
  resize: both;
  overflow: hidden;
  border-radius: 6px;
  min-height: 120px;
  max-height: 80vh;
  background: var(--conversation-bg);
  width: 100%;
}

.conversation-container #htmlPopupArea {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 6px;
}

.conversation-container #conversation {
  min-height: 120px;
  max-height: calc(100% - 16px);
  overflow: auto;
  background: transparent;
  border-radius: 0;
}

.resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  cursor: se-resize;
  background: linear-gradient(135deg, transparent 50%, var(--primary-color) 50%);
  border-radius: 0 0 6px 0;
}

.resize-handle:hover {
  background: linear-gradient(135deg, transparent 50%, var(--primary-color-hover) 50%);
}

#errorLog {
  background: var(--error-bg);
}

@media (max-width: 480px) {
  #conversation,
  #eventLog,
  #errorLog {
    max-height: 200px;
    padding: 8px;
    font-size: 0.75rem;
  }
}

.agent-row {
  display: grid;
  grid-template-columns: auto auto auto 18px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 6px;
}

@media (max-width: 768px) {
  .agent-row {
    grid-template-columns: auto 18px minmax(0, 1fr);
    gap: 6px;
  }
}

@media (max-width: 480px) {
  .agent-row {
    grid-template-columns: 18px minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
    margin-bottom: 4px;
  }
}

.agent-name {
  grid-column: 5;
  font-weight: 600;
  font-size: clamp(0.9rem, 2vw, 1rem);
}

@media (max-width: 768px) {
  .agent-name {
    grid-column: 3;
  }
}

@media (max-width: 480px) {
  .agent-name {
    grid-column: 2;
    word-break: break-word;
  }
}

.agent-url {
  grid-column: 6;
  grid-row: 1;
  font-size: 0.9rem;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  word-break: normal;
}

@media (max-width: 768px) {
  .agent-url {
    display: none;
  }
}

@media (max-width: 560px) {
  .agent-url {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: break-word;
    word-break: break-word;
  }
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .status-dot {
    width: 10px;
    height: 10px;
  }
}

.status-idle {
  background: var(--status-idle);
}

.status-error {
  background: var(--status-error);
}

.status-working {
  background: var(--status-working);
  animation: pulse 0.8s infinite alternate ease-in-out;
}

@keyframes pulse {
  from { opacity: 0.35; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  body {
    background: white;
  }

  .app {
    max-width: 100%;
    padding: 0;
  }

  button {
    display: none;
  }
}
