:root {
  color-scheme: dark;
  --bg: #1a1d22;
  --bg-soft: #1f2329;
  --surface: #242931;
  --surface-muted: #2a3039;
  --text-primary: #e6e8eb;
  --text-secondary: #a3a9b3;
  --brand: #7ea0c4;
  --brand-strong: #6c90b8;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --radius-lg: 12px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f9fa;
  --bg-soft: #ffffff;
  --surface: #ffffff;
  --surface-muted: #f1f3f4;
  --text-primary: #202124;
  --text-secondary: #5f6368;
  --brand: #1a73e8;
  --brand-strong: #1765cc;
  --danger: #d93025;
  --success: #188038;
  --warning: #b06000;
}

* {
  box-sizing: border-box;
  font-family: Heebo, Assistant, Inter, "Segoe UI", Arial, sans-serif;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text-primary);
}

[dir="rtl"] {
  text-align: right;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 20px 42px;
}

.layout-shell {
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.sidebar {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 16px;
}

h1,
h2,
h3 {
  margin: 0;
}

.title {
  font-size: clamp(1.4rem, 2vw, 1.85rem);
  font-weight: 700;
  line-height: 1.35;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--text-secondary);
  line-height: 1.65;
}

.controls,
.status-stack {
  display: grid;
  gap: 10px;
}

.bot-stack {
  align-content: start;
}

.sidebar-system {
  margin-top: auto;
  padding-top: 8px;
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.theme-switch input {
  appearance: none;
  width: 44px;
  height: 24px;
  background: var(--surface-muted);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
}

.theme-switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-primary);
  transition: transform 140ms ease;
}

.theme-switch input:checked {
  background: var(--brand);
}

.theme-switch input:checked::after {
  transform: translateX(20px);
}

.main-content {
  min-width: 0;
}

.card-top-row {
  justify-content: space-between;
  align-items: center;
}

.card-top-row > h3 {
  flex: 1;
}

.card-top-row > button {
  flex: 0 0 auto;
  min-width: 140px;
}

.span-4 {
  grid-column: span 4;
}
.span-6 {
  grid-column: span 6;
}
.span-8 {
  grid-column: span 8;
}
.span-12 {
  grid-column: span 12;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 0;
  background: var(--surface-muted);
  color: var(--text-primary);
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 140px;
  line-height: 1.5;
  white-space: pre-wrap;
}

input:focus,
select:focus,
textarea:focus {
  background: color-mix(in srgb, var(--surface-muted) 75%, var(--brand) 25%);
}

button {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}

button:hover {
  background: var(--brand-strong);
}

button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand) 70%, #ffffff 30%);
  outline-offset: 2px;
}

button.secondary {
  background: var(--surface-muted);
  color: var(--text-primary);
}

button.secondary:hover {
  background: color-mix(in srgb, var(--surface-muted) 78%, var(--brand) 22%);
}

button.danger-action {
  background: color-mix(in srgb, var(--danger) 30%, var(--surface-muted) 70%);
  color: #fff;
}

button.danger-action:hover {
  background: color-mix(in srgb, var(--danger) 28%, var(--surface-muted) 72%);
}

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

.row > * {
  flex: 1;
  min-width: 180px;
}

.compact-actions > * {
  min-width: 120px;
  flex: 1 1 0;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.is-disabled {
  opacity: 0.58;
  pointer-events: none;
}

.muted {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.6;
}

.bot-quick-status {
  margin: 2px 0 0;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-inline-end: 8px;
  vertical-align: middle;
}

.dot-good {
  background: #22c55e;
}

.dot-warn {
  background: #eab308;
}

.dot-bad {
  background: #ef4444;
}

.dot-neutral {
  background: #94a3b8;
}

.alert-banner {
  background: color-mix(in srgb, var(--danger) 10%, transparent 90%);
  color: color-mix(in srgb, var(--danger) 65%, var(--text-primary) 35%);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  line-height: 1.6;
}

.primary-bot-card {
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.bot-main-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.inline-status {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.status-good {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 22%, transparent 78%);
}

.status-warn {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 22%, transparent 78%);
}

.status-bad {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 22%, transparent 78%);
}

.status-neutral {
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--text-secondary) 14%, transparent 86%);
}

.bot-secondary-line {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.bot-hint {
  margin: 0;
}

.single-line-meta {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-muted);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.group-list {
  display: grid;
  gap: 12px;
  margin: 12px 0;
}

.group-card {
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  padding: 16px;
  display: grid;
  gap: 8px;
}

.empty-state {
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--surface-muted);
}

.auth-shell {
  max-width: 520px;
  margin: 10vh auto 0;
}

.auth-form {
  margin-top: 14px;
  background: var(--surface);
  border-radius: 12px;
  padding: 18px;
}

.bot-list {
  display: grid;
  gap: 8px;
}

.bot-list-item {
  width: 100%;
  text-align: right;
  background: var(--surface-muted);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.bot-list-item.is-active {
  background: color-mix(in srgb, var(--surface-muted) 72%, var(--brand) 28%);
}

.bot-list-meta {
  display: grid;
  gap: 2px;
}

.bot-remove-btn {
  min-width: 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--danger) 25%, var(--surface-muted) 75%);
  color: #fff;
  flex: 0 0 auto;
}

.bot-remove-btn:hover {
  background: color-mix(in srgb, var(--danger) 40%, var(--surface-muted) 60%);
}

.status-stack .row label {
  margin: 0;
}

.group-actions {
  justify-content: flex-start;
}

.group-actions > * {
  flex: 0 0 auto;
  min-width: 0;
}

.ghost-icon-btn {
  background: var(--surface);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 0.95rem;
}

.ghost-icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text-primary);
}

.ghost-icon-btn.danger {
  color: var(--danger);
}

.ghost-icon-btn.danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface) 88%);
}

details > summary {
  cursor: pointer;
}

.details-body {
  margin-top: 8px;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 180ms ease;
}

.details-body > * {
  overflow: hidden;
}

details[open] .details-body {
  grid-template-rows: 1fr;
}

.group-dialog {
  width: min(860px, 92vw);
  border: 0;
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  color: var(--text-primary);
}

.group-dialog::backdrop {
  background: rgba(2, 6, 23, 0.5);
}

.group-dialog-shell {
  position: relative;
  padding: 16px;
  padding-top: 20px;
}

.dialog-close-btn {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: 1.25rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dialog-close-btn:hover {
  background: color-mix(in srgb, var(--surface-muted) 75%, var(--brand) 25%);
  color: var(--text-primary);
}

#pairingQr {
  max-width: 300px;
  background: #fff;
  border-radius: var(--radius-md);
  padding: 8px;
}

@media (max-width: 1024px) {
  .layout-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }
}

@media (max-width: 900px) {
  .span-4,
  .span-6,
  .span-8 {
    grid-column: span 12;
  }
}
