:root,
html[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --error: #ef4444;
  --callout-error-bg: rgba(239, 68, 68, 0.12);
  --callout-error-border: rgba(239, 68, 68, 0.35);
  --callout-error-text: #fecaca;
  --callout-info-bg: rgba(59, 130, 246, 0.12);
  --callout-info-border: rgba(59, 130, 246, 0.35);
  --callout-info-text: #bfdbfe;
  --input-bg: #0f1419;
  --radius: 10px;
  --sidebar-w: 260px;
  --tile-shadow: 0 1px 2px rgba(0, 0, 0, 0.18), 0 6px 16px rgba(0, 0, 0, 0.12);
  --tile-shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.2), 0 12px 24px rgba(0, 0, 0, 0.16);
  --tile-border: rgba(148, 163, 184, 0.18);
  --tile-hover-border: rgba(59, 130, 246, 0.45);
  --tile-chevron: #64748b;
  --tile-title: #f1f5f9;
  --tile-orange-bg: rgba(251, 146, 60, 0.18);
  --tile-orange-fg: #fb923c;
  --tile-blue-bg: rgba(96, 165, 250, 0.18);
  --tile-blue-fg: #60a5fa;
  --accent: #fb923c;
  --accent-hover: #f97316;
  --accent-bg: rgba(251, 146, 60, 0.14);
  --accent-bg-hover: rgba(251, 146, 60, 0.22);
  --accent-border: rgba(251, 146, 60, 0.35);
  font-family: "Segoe UI", system-ui, sans-serif;
}

html[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --error: #dc2626;
  --callout-error-bg: rgba(220, 38, 38, 0.08);
  --callout-error-border: rgba(220, 38, 38, 0.25);
  --callout-error-text: #991b1b;
  --callout-info-bg: rgba(37, 99, 235, 0.08);
  --callout-info-border: rgba(37, 99, 235, 0.25);
  --callout-info-text: #1e40af;
  --input-bg: #ffffff;
  --tile-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 14px rgba(15, 23, 42, 0.06);
  --tile-shadow-hover: 0 4px 8px rgba(15, 23, 42, 0.06), 0 12px 28px rgba(15, 23, 42, 0.1);
  --tile-border: rgba(203, 213, 225, 0.9);
  --tile-hover-border: rgba(37, 99, 235, 0.35);
  --tile-chevron: #94a3b8;
  --tile-title: #0f172a;
  --tile-orange-bg: #fff7ed;
  --tile-orange-fg: #ea580c;
  --tile-blue-bg: #eff6ff;
  --tile-blue-fg: #2563eb;
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-bg: #fff7ed;
  --accent-bg-hover: #ffedd5;
  --accent-border: rgba(234, 88, 12, 0.35);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body.portal-login #appRoot { display: none !important; }
body.portal-app #loginView { display: none !important; }

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

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.875rem; }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-title { margin: 0; font-size: 1.35rem; line-height: 1.35; }
.login-tagline { color: var(--muted); margin: 0.5rem 0 0; }
.login-option-title { margin: 0 0 0.35rem; font-size: 1rem; }
.login-option-desc { color: var(--muted); font-size: 0.9rem; margin: 0 0 1rem; }
.login-divider {
  display: flex; align-items: center; gap: 1rem;
  color: var(--muted); margin: 1.25rem 0;
}
.login-divider::before, .login-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field label { font-size: 0.875rem; font-weight: 600; }
.field input, .field select, .field textarea {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.6rem 0.75rem;
}
.field textarea { min-height: 100px; resize: vertical; }
.req { color: var(--error); }
.muted-text { color: var(--muted); font-size: 0.875rem; }

.brand-logo {
  display: block;
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
}
.brand-logo.lg {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
}

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
}
.sidebar-brand {
  display: flex; gap: 0.75rem; align-items: center;
  background: none; border: none; color: inherit; cursor: pointer;
  text-align: left; padding: 0.5rem; border-radius: 8px;
}
.sidebar-brand:hover { background: var(--surface-2); }
.brand-copy { min-width: 0; }
.brand-title { font-weight: 700; font-size: 0.8rem; line-height: 1.35; }
.brand-sub { color: var(--muted); font-size: 0.8rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.35rem; margin: 1.5rem 0; }
.nav-item {
  text-align: left; padding: 0.65rem 0.75rem; border-radius: 8px;
  background: none; border: none; color: var(--muted); cursor: pointer;
}
.nav-item.active, .nav-item:hover { background: var(--surface-2); color: var(--text); }
.sidebar-footer { margin-top: auto; }
.user-card { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 0.75rem; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface-2); display: grid; place-items: center; font-weight: 700;
}
.user-name { font-weight: 600; font-size: 0.9rem; }
.user-email { color: var(--muted); font-size: 0.75rem; }
.sidebar-version { color: var(--muted); font-size: 0.75rem; margin-top: 0.5rem; }

.sidebar-theme-row { margin-top: 0.75rem; }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
}
.theme-toggle:hover { border-color: var(--primary); }
.theme-toggle-icon { font-size: 1rem; line-height: 1; }

.feedback-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--accent-border, rgba(234, 88, 12, 0.45));
  background: var(--accent-bg, rgba(234, 88, 12, 0.12));
  color: var(--accent, #ea580c);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
}
.feedback-toggle:hover { border-color: var(--accent); background: var(--accent-bg-hover, rgba(234, 88, 12, 0.18)); }

.helix-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.helix-status:hover { border-color: var(--primary); }
.helix-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.helix-status.is-checking .helix-status-dot {
  background: #94a3b8;
  animation: helix-pulse 1s ease-in-out infinite;
}
.helix-status.is-live {
  color: var(--success);
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.08);
}
.helix-status.is-live .helix-status-dot { background: var(--success); }
.helix-status.is-mock {
  color: #eab308;
  border-color: rgba(234, 179, 8, 0.35);
  background: rgba(234, 179, 8, 0.08);
}
.helix-status.is-mock .helix-status-dot { background: #eab308; }
.helix-status.is-disconnected {
  color: var(--error);
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}
.helix-status.is-disconnected .helix-status-dot { background: var(--error); }
@keyframes helix-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.btn-accent {
  background: var(--accent, #ea580c);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
}
.btn-accent:hover { background: var(--accent-hover, #c2410c); }

.form-actions-end { justify-content: flex-end; }

.section-heading {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}
.section-bar {
  display: inline-block;
  width: 4px;
  height: 1.25rem;
  border-radius: 2px;
  background: var(--accent, #ea580c);
  flex-shrink: 0;
}
.section-sub { margin: 0 0 1rem; }

.feedback-card { max-width: 760px; }

.file-drop {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem 1rem;
  text-align: center;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}
.file-drop.drag-over {
  border-color: var(--accent, #ea580c);
  background: var(--accent-bg, rgba(234, 88, 12, 0.08));
}
.file-drop-title { margin: 0 0 0.25rem; font-weight: 600; }
.file-drop-icon { display: inline-block; margin-right: 0.35rem; }
.file-drop-sub { margin: 0 0 0.35rem; }
.file-drop-hint { margin: 0; font-size: 0.8rem; }

.file-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.file-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.875rem;
}

.help-card { max-width: 800px; }
.help-intro { margin: 0 0 0.35rem; }
.help-intro-desc { margin: 0 0 1.5rem; }
.help-sections { display: flex; flex-direction: column; gap: 1.25rem; }
.help-section {
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.help-section:last-child { border-bottom: none; padding-bottom: 0; }
.help-section h3 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.help-section p { margin: 0; line-height: 1.6; color: var(--muted); }

.catalog-hero { margin-bottom: 1.5rem; }
.catalog-hero-title { margin: 0 0 0.35rem; font-size: 1.25rem; font-weight: 700; }
.catalog-hero-desc { margin: 0; }

.catalog-grid-wide {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
  max-width: 920px;
}

.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.page-header {
  padding: 1.5rem 2rem 0;
  border-bottom: 1px solid var(--border);
}
.eyebrow { color: var(--primary); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.75rem; margin: 0; }
.page-title { margin: 0.25rem 0; font-size: 1.75rem; }
.page-desc { color: var(--muted); margin: 0.5rem 0 1.25rem; }
.page-content { padding: 1.5rem 2rem 2rem; flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.catalog-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--tile-border, var(--border));
  border-radius: 14px;
  padding: 1.35rem 1.5rem 1.5rem;
  min-height: 168px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  box-shadow: var(--tile-shadow);
  transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.catalog-tile:hover {
  border-color: var(--tile-hover-border, var(--primary));
  box-shadow: var(--tile-shadow-hover);
  transform: translateY(-2px);
}

.catalog-tile-chevron {
  position: absolute;
  top: 1.15rem;
  right: 1.15rem;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--tile-chevron, #94a3b8);
  font-weight: 300;
}

.catalog-tile-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.catalog-tile-icon-wrap svg {
  width: 24px;
  height: 24px;
}

.catalog-tile.theme-orange .catalog-tile-icon-wrap {
  background: var(--tile-orange-bg);
  color: var(--tile-orange-fg);
}

.catalog-tile.theme-blue .catalog-tile-icon-wrap {
  background: var(--tile-blue-bg);
  color: var(--tile-blue-fg);
}

.catalog-tile h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  padding-right: 1.5rem;
  color: var(--tile-title, var(--text));
}

.catalog-tile p {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

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

.back-btn {
  background: none; border: none; color: var(--primary);
  cursor: pointer; padding: 0; margin-bottom: 1rem; font-weight: 600;
}
.form-block { margin-bottom: 1.5rem; }
.form-block h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.form-subheading {
  margin: 0.75rem 0 0;
  font-size: 1rem;
  font-weight: 600;
}
.form-section-heading { margin-top: 0.25rem; }
.form-notice {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}
.form-notice-list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.form-notice-list li + li { margin-top: 0.35rem; }
.radio-group,
.checkbox-option {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 0.35rem;
}
.radio-option,
.checkbox-option {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
  cursor: pointer;
}
.radio-group { border: 0; padding: 0; margin-inline: 0; }
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.field-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.selected-banner {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.review-content dl {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}
.review-content dt { color: var(--muted); font-weight: 600; }
.review-content dd { margin: 0; }

.success-card { text-align: center; max-width: 520px; }
.success-icon {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(34, 197, 94, 0.15); color: var(--success);
  display: grid; place-items: center; font-size: 1.5rem;
  margin: 0 auto 1rem;
}

.table-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap;
}
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td {
  text-align: left; padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--muted); font-weight: 600; }
.status-pill {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  background: var(--surface-2); font-size: 0.8rem;
}

.callout {
  border-radius: 8px; padding: 0.75rem 1rem; margin: 0.75rem 0;
}
.callout-error { background: var(--callout-error-bg); border: 1px solid var(--callout-error-border); color: var(--callout-error-text); }
.callout-info { background: var(--callout-info-bg); border: 1px solid var(--callout-info-border); color: var(--callout-info-text); }
.table-state { text-align: center; padding: 2rem; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ticket-detail-meta { display: grid; gap: 0.35rem; margin-bottom: 1rem; }
.comment-list { margin: 1rem 0; padding: 0; list-style: none; }
.comment-list li {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.75rem; margin-bottom: 0.5rem;
}
.comment-meta { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.35rem; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .catalog-grid-wide { grid-template-columns: 1fr; max-width: none; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .span-2 { grid-column: span 1; }
  .review-content dl { grid-template-columns: 1fr; }
}
