:root {
  color-scheme: light dark;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --text: #1f2933;
  --muted: #667085;
  --border: #d8d2c8;
  --accent: #2f6f4e;
  --accent-hover: #245a3f;
  --error: #b42318;
  --read-only: #f0ece4;
  --page-pad: 1.25rem;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

#app {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#login-view {
  width: min(100% - 2rem, 420px);
  margin: 10vh auto;
  padding: 2rem;
}

#main-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 100vh;
  padding: var(--page-pad);
  width: 100%;
}

h1,
h2 {
  margin: 0 0 0.5rem;
}

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

.error {
  color: var(--error);
}

.topbar,
.sidebar-header,
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.topbar {
  flex-shrink: 0;
}

.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.nav-tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.nav-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.settings-panel {
  width: 100%;
  padding: 1.5rem;
}

#voice-select,
#model-select,
#image-model-select {
  width: 100%;
  max-width: 28rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.settings-section-spacer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.settings-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
}

.model-probe-section {
  margin-top: 0.5rem;
}

.model-probe-table-wrap {
  margin-top: 0.75rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.model-probe-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.model-probe-table th,
.model-probe-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.model-probe-table th {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--read-only);
}

.model-probe-table tbody tr:last-child td {
  border-bottom: none;
}

.model-probe-table .model-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.model-probe-status {
  display: inline-block;
  font-weight: 600;
}

.model-probe-status.ok {
  color: #1a4d32;
}

.model-probe-status.fail {
  color: var(--error);
}

.model-probe-detail {
  display: block;
  margin-top: 0.25rem;
  font-weight: 400;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

button.secondary {
  background: transparent;
  color: var(--text);
}

.status-badge {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--read-only);
}

.status-badge.enabled {
  color: #1a4d32;
  background: #e6f4ec;
  border-color: #9fd4b5;
}

.status-badge.disabled {
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 1rem;
  flex: 1;
  min-height: 0;
  width: 100%;
}

#settings-view {
  display: block;
  width: 100%;
  flex: 1;
}

.sidebar,
.editor {
  padding: 1rem;
  min-width: 0;
}

#channel-list,
#monitor-list,
#tool-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

#channel-list li,
#monitor-list li,
#tool-list li {
  margin-bottom: 0.5rem;
}

.tools-filter-field {
  margin-top: 0.75rem;
  margin-bottom: 0;
}

.tools-filter-field input {
  margin-top: 0;
}

.tool-category-label {
  margin: 0.85rem 0 0.35rem;
  padding: 0 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.tool-category-label:first-child {
  margin-top: 0.25rem;
}

.tool-example {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.tool-params-table .param-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 600;
}

.tool-params-table .param-required {
  font-weight: 600;
  color: #1a4d32;
}

.tool-params-table .param-optional {
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.channel-link {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.75rem;
  cursor: pointer;
  color: var(--text);
}

.channel-link:hover,
.channel-link.active {
  border-color: var(--border);
  background: var(--read-only);
}

.channel-link .name {
  display: block;
  font-weight: 600;
  color: #000;
}

.channel-link .meta {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

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

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 12rem;
}

button {
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: var(--read-only);
}

.field {
  margin-top: 1.25rem;
}

.field-help {
  margin: -0.25rem 0 0.5rem;
  font-size: 0.9rem;
}

.read-only pre,
.read-only ul {
  margin: 0;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--read-only);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  overflow-x: auto;
}

.read-only ul {
  list-style: disc;
  padding-left: 2rem;
}

.status {
  margin-top: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-weight: 600;
  white-space: pre-line;
}

.status.success {
  color: #1a4d32;
  background: #e6f4ec;
  border: 1px solid #9fd4b5;
}

.status.error {
  color: var(--error);
  background: #fef3f2;
  border: 1px solid #fecdca;
}

button.saved {
  background: #1a4d32;
}

@media (max-width: 900px) {
  :root {
    --page-pad: 0.85rem;
  }

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

  .topbar,
  .sidebar-header,
  .editor-header {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-actions {
    justify-content: stretch;
  }

  .settings-actions button,
  .editor-header > button,
  .topbar > button {
    width: 100%;
  }

  #voice-select,
  #model-select,
  #image-model-select {
    max-width: none;
  }

  textarea {
    min-height: 10rem;
  }
}

@media (max-width: 480px) {
  .nav-tabs {
    width: 100%;
  }

  .nav-tab {
    flex: 1 1 auto;
    text-align: center;
  }
}
