/* ==========================================================================
   Design tokens
   Generated with the ui-ux-pro-max design system (see design-system/gargona/MASTER.md)
   and adapted for light/dark parity.
   ========================================================================== */
:root {
  --font-sans: 'Fira Sans', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'Fira Code', ui-monospace, SFMono-Regular, Menlo, monospace;

  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-surface-muted: #F1F5FD;
  --color-border: #E4ECFC;
  --color-text: #0F172A;
  --color-text-muted: #64748B;
  --color-text-faint: #94A3B8;

  --color-primary: #2563EB;
  --color-primary-hover: #1D4ED8;
  --color-on-primary: #FFFFFF;

  --color-accent: #059669;
  --color-accent-hover: #047857;

  --color-danger: #DC2626;
  --color-danger-hover: #B91C1C;
  --color-danger-bg: #FEE2E2;
  --color-danger-text: #991B1B;

  --color-warning: #D97706;
  --color-warning-bg: #FEF3C7;
  --color-warning-text: #854D0E;

  --color-success-bg: #DCFCE7;
  --color-success-text: #166534;

  --color-info: #0891B2;
  --color-ring: #2563EB;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --radius-xl: 1.25rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgb(15 23 42 / 0.05);
  --shadow-md: 0 4px 10px rgb(15 23 42 / 0.06);
  --shadow-lg: 0 12px 28px rgb(15 23 42 / 0.12);
  --shadow-xl: 0 24px 48px rgb(15 23 42 / 0.18);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: 150ms;
  --transition-base: 200ms;

  --sidebar-width: 15rem;
}

:root.dark {
  --color-bg: #0B1220;
  --color-surface: #111A2C;
  --color-surface-muted: #1B263B;
  --color-border: #263449;
  --color-text: #F1F5F9;
  --color-text-muted: #94A3B8;
  --color-text-faint: #64748B;

  --color-primary: #3B82F6;
  --color-primary-hover: #60A5FA;
  --color-on-primary: #0B1220;

  --color-accent: #10B981;
  --color-accent-hover: #34D399;

  --color-danger: #F87171;
  --color-danger-hover: #FCA5A5;
  --color-danger-bg: rgb(127 29 29 / 0.35);
  --color-danger-text: #FCA5A5;

  --color-warning: #FBBF24;
  --color-warning-bg: rgb(120 53 15 / 0.35);
  --color-warning-text: #FDE68A;

  --color-success-bg: rgb(20 83 45 / 0.35);
  --color-success-text: #86EFAC;

  --color-info: #22D3EE;
  --color-ring: #60A5FA;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 10px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 12px 28px rgb(0 0 0 / 0.45);
  --shadow-xl: 0 24px 48px rgb(0 0 0 / 0.55);
}

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

body { font-family: var(--font-sans); }

/* Visible only when focused — lets keyboard users jump past the sidebar */
.skip-link {
  position: absolute;
  top: -3rem;
  left: 0.75rem;
  z-index: 200;
  background: var(--color-primary);
  color: var(--color-on-primary);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  transition: top var(--transition-base) var(--ease);
}
.skip-link:focus { top: 0.75rem; }

/* Consistent, visible keyboard focus everywhere (mouse clicks stay quiet) */
:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   App shell / sidebar navigation
   ========================================================================== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1.1rem;
  border-bottom: 1px solid var(--color-border);
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text);
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
}

.sidebar-section-title {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  padding: 0.9rem 0.6rem 0.35rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: background var(--transition-fast) var(--ease), color var(--transition-fast) var(--ease);
}
.nav-link:hover { background: var(--color-surface-muted); color: var(--color-text); }
.nav-active {
  background: var(--color-surface-muted);
  color: var(--color-primary) !important;
}
.nav-active .icon { color: var(--color-primary); }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Mobile off-canvas nav — uses the same .drawer open/close JS (Escape, backdrop,
   click handling all key off ".drawer"), this class just mirrors it to the left. */
.drawer.mobile-nav {
  left: 0;
  right: auto;
  width: min(18rem, 82vw);
  transform: translateX(-100%);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.topbar-mobile {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

@media (max-width: 899px) {
  .sidebar { display: none; }
  .topbar-mobile { display: flex; }
}

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

/* ==========================================================================
   Icons & icon buttons
   ========================================================================== */
.icon {
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 0.95rem; height: 0.95rem; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition-fast) var(--ease), color var(--transition-fast) var(--ease);
}
.icon-btn:hover { background: var(--color-surface-muted); color: var(--color-text); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border: 1px solid transparent;
  transition: background var(--transition-fast) var(--ease), border-color var(--transition-fast) var(--ease), opacity var(--transition-fast) var(--ease);
}
.btn:hover { background: var(--color-primary-hover); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}
.btn-danger { background: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger-hover); }
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-surface-muted); }

/* Loading spinner shown inside a button while an AJAX submit is in flight */
.btn-spinner {
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.4);
  border-top-color: currentColor;
  animation: btn-spin 0.6s linear infinite;
}
.btn-secondary .btn-spinner { border-color: rgb(15 23 42 / 0.15); border-top-color: currentColor; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .btn-spinner { animation: none; }
}

/* ==========================================================================
   Cards, badges, empty/skeleton states
   ========================================================================== */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-active { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-pending { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-error { background: var(--color-danger-bg); color: var(--color-danger-text); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: 2.5rem 1.5rem;
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-lg);
}
.empty-state .icon { width: 2rem; height: 2rem; color: var(--color-text-faint); }
.empty-state-title { font-weight: 600; color: var(--color-text); font-size: 0.95rem; }
.empty-state-desc { font-size: 0.85rem; max-width: 26rem; }

.skeleton {
  background: linear-gradient(90deg, var(--color-surface-muted) 25%, var(--color-border) 37%, var(--color-surface-muted) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius-md);
}
@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--color-surface-muted); }
}

/* ==========================================================================
   Forms
   ========================================================================== */
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.3rem;
}
.field-label .required-mark { color: var(--color-danger); margin-left: 0.15rem; }
.field-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.3rem;
}
.field-error {
  font-size: 0.75rem;
  color: var(--color-danger);
  margin-top: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Page-level error banner — one real component instead of the same inline
   background/padding/radius repeated (and once forgotten) on every page. */
.alert-error {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}

.input {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.9rem;
  transition: border-color var(--transition-fast) var(--ease), box-shadow var(--transition-fast) var(--ease);
}
.input::placeholder { color: var(--color-text-faint); }
.input:hover { border-color: var(--color-text-faint); }
.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}
.input:disabled, .input[readonly] {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  cursor: not-allowed;
}
.input[readonly] { border-style: dashed; }

/* ==========================================================================
   Toasts
   ========================================================================== */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 22rem;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  background: #334155;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(1rem);
  transition: opacity var(--transition-base) var(--ease), transform var(--transition-base) var(--ease);
}
.toast-show { opacity: 1; transform: translateX(0); }
.toast-success { background: var(--color-accent); }
.toast-error { background: var(--color-danger); }

/* ==========================================================================
   Model combobox
   ========================================================================== */
.combo { position: relative; }
.combo-list {
  position: absolute;
  z-index: 50;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 16rem;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.combo-item {
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}
.combo-item:hover, .combo-item:focus-visible { background: var(--color-surface-muted); }
[data-channel-row]:hover { background: var(--color-surface-muted); }
.combo-item-name { font-size: 0.85rem; font-weight: 500; color: var(--color-text); }
.combo-item-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}
.combo-item-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.combo-item-price {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.combo-empty { padding: 0.6rem 0.7rem; font-size: 0.8rem; color: var(--color-text-muted); }

/* ==========================================================================
   AI agents: node card, status dot, switch, channel chip
   ========================================================================== */
.node-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.node-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1.1rem;
}

.node-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.node-dot-on { background: var(--color-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 20%, transparent); }
.node-dot-off { background: var(--color-text-faint); }

.switch-btn {
  position: relative;
  width: 2.5rem;
  height: 1.4rem;
  border-radius: var(--radius-full);
  background: var(--color-border);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-fast) var(--ease);
}
.switch-btn.switch-on { background: var(--color-primary); }
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: var(--radius-full);
  background: white;
  transition: transform var(--transition-fast) var(--ease);
}
.switch-btn.switch-on .switch-knob { transform: translateX(1.1rem); }

.channel-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  background: color-mix(in srgb, var(--color-primary) 10%, var(--color-surface));
  color: var(--color-primary);
  border: 1px solid color-mix(in srgb, var(--color-primary) 25%, transparent);
}
.channel-chip-off { opacity: 0.55; }
.connector-dot {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: var(--radius-full);
  background: currentColor;
  flex-shrink: 0;
}
.chip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  background: transparent;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
}
.chip-btn:hover { opacity: 1; }
.chip-btn .icon { width: 0.7rem; height: 0.7rem; }

/* ==========================================================================
   Agent summary card (click to open drawer)
   ========================================================================== */
.agent-summary {
  cursor: pointer;
  transition: box-shadow var(--transition-fast) var(--ease), border-color var(--transition-fast) var(--ease);
}
.agent-summary:hover {
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--color-primary) 40%, transparent);
}
.agent-stat {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ==========================================================================
   Slide-in drawers (agent settings on the right, mobile nav on the left)
   ========================================================================== */
#drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(2 6 23 / 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base) var(--ease);
  z-index: 90;
}
#drawer-backdrop.drawer-open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(30rem, 100vw);
  background: var(--color-surface);
  box-shadow: var(--shadow-xl);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform var(--transition-base) var(--ease), visibility 0s linear var(--transition-base);
  z-index: 91;
  overflow-y: auto;
  padding: 1.25rem;
}
.drawer.drawer-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform var(--transition-base) var(--ease), visibility 0s linear 0s;
}
.drawer-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-muted);
}
.drawer-close-btn:hover { background: var(--color-surface-muted); color: var(--color-text); }

/* ==========================================================================
   Test-chat widget
   ========================================================================== */
.test-chat-messages {
  max-height: 14rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem;
  background: var(--color-surface-muted);
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
}
.test-chat-bubble {
  max-width: 85%;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  white-space: pre-wrap;
}
.test-chat-user {
  align-self: flex-end;
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.test-chat-assistant {
  align-self: flex-start;
  background: var(--color-border);
  color: var(--color-text);
}
.test-chat-error { color: var(--color-danger) !important; }
