:root {
  color-scheme: light dark;
  font-family: system-ui, sans-serif;
}

body {
  margin: 0;
  padding: 2rem 1rem;
  background: #f4f4f5;
  color: #1a1a1a;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

main[hidden] {
  display: none;
}

main.login-main {
  max-width: 360px;
  margin-top: 15vh;
}

h1 {
  font-size: 1.4rem;
  margin: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.tab-panel {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.tab-panel[hidden] {
  display: none;
}

.card-full {
  grid-column: 1 / -1;
}

@media (max-width: 820px) {
  .tab-panel {
    grid-template-columns: 1fr;
  }
}

.section-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-bottom: 1px solid #e2e2e2;
  padding-bottom: 0.75rem;
}

.section-tab {
  background: transparent;
  color: inherit;
  opacity: 0.65;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.section-tab:hover {
  opacity: 0.9;
  background: rgba(0, 0, 0, 0.05);
}

.section-tab.active {
  opacity: 1;
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

.card {
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 10px;
  padding: 1.25rem;
}

.card h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

label.row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

input, select, textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fff;
  color: #1a1a1a;
}

button {
  align-self: flex-start;
  font: inherit;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: none;
  background: #2563eb;
  color: white;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

.hint {
  font-size: 0.85rem;
  opacity: 0.75;
  margin-top: -0.5rem;
}

.feedback {
  font-size: 0.85rem;
}

#wa-qr {
  max-width: 260px;
  display: block;
  margin-top: 0.5rem;
  border-radius: 8px;
  background: #fff;
  padding: 0.5rem;
}

.row-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.agent-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.agent-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  color: inherit;
  border: 1px solid #ccc;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
}

.agent-tab:hover {
  background: rgba(0, 0, 0, 0.05);
}

.agent-tab.active {
  border-color: #2563eb;
  background: rgba(37, 99, 235, 0.1);
  font-weight: 600;
}

.agent-tab-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
}

.agent-tab-dot.connected {
  background: #22c55e;
}

.agent-tab-dot.qr_ready {
  background: #eab308;
}

.agent-tab-dot.connecting,
.agent-tab-dot.starting {
  background: #f97316;
}

.agent-tab-dot.disconnected {
  background: #ef4444;
}

#agent-form {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}

#agent-form input {
  flex: 1;
  min-width: 160px;
}

button.ghost.danger {
  color: #dc2626;
  border-color: #dc2626;
  margin-top: 0.75rem;
}

button.ghost.danger:hover {
  background: rgba(220, 38, 38, 0.1);
}

#voice-list,
#contact-list,
#group-list,
#available-group-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.contact-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e2e2;
  border-radius: 6px;
  font-size: 0.9rem;
}

.contact-item span {
  flex: 1;
  min-width: 100px;
}

.pause-badge {
  flex: 0 0 auto !important;
  min-width: 0 !important;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: #fde68a;
  color: #713f12;
  white-space: nowrap;
}

.group-item {
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e2e2;
  border-radius: 6px;
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.group-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 600;
}

.group-item-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.85rem;
}

.group-item-options label {
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.group-item-options input[type="time"] {
  padding: 0.3rem 0.4rem;
}

#available-group-list,
#available-contact-list {
  max-height: 260px;
  overflow-y: auto;
  margin-top: 0.5rem;
}

.available-group-item,
.available-contact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0.75rem;
  border: 1px dashed #ccc;
  border-radius: 6px;
  font-size: 0.85rem;
}

.voice-item {
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e2e2;
  border-radius: 6px;
  font-size: 0.9rem;
}

.voice-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.voice-item details {
  margin-top: 0.5rem;
}

.voice-params {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.voice-params label {
  flex: 1;
  min-width: 90px;
  font-size: 0.8rem;
}

button.ghost {
  background: transparent;
  color: inherit;
  border: 1px solid #ccc;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}

button.ghost:hover {
  background: rgba(0, 0, 0, 0.05);
}

details {
  font-size: 0.9rem;
}

details summary {
  cursor: pointer;
  margin-bottom: 0.5rem;
}

details label {
  margin-top: 0.5rem;
}

/* Dark-mode overrides must come last so they win the cascade for
   properties (like .card background) that the light rules above also set. */
@media (prefers-color-scheme: dark) {
  body {
    background: #121212;
    color: #eaeaea;
  }

  .card {
    background: #1e1e1e;
    border-color: #2f2f2f;
  }

  input, select, textarea {
    background: #1a1a1a;
    color: #eaeaea;
    border-color: #3a3a3a;
  }

  .voice-item,
  .contact-item,
  .group-item {
    border-color: #3a3a3a;
  }

  .available-group-item,
  .available-contact-item {
    border-color: #4a4a4a;
  }

  button.ghost {
    border-color: #3a3a3a;
  }

  button.ghost:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  .agent-tab {
    border-color: #3a3a3a;
  }

  .agent-tab:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  .section-tabs {
    border-color: #2f2f2f;
  }

  .section-tab:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  .section-tab.active {
    background: rgba(37, 99, 235, 0.2);
    color: #60a5fa;
  }
}
