/* DWIS AI Portal */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: dark light;
}

html[data-theme="dark"],
html:not([data-theme]) {
  --portal-bg: #0f172a;
  --portal-sidebar: #080e1c;
  --portal-card: #1a2236;
  --portal-border: #1e293b;
  --portal-text: #f1f5f9;
  --portal-muted: #94a3b8;
  --portal-green: #22c55e;
  --accent: #1d4ed8;
  --page-bg: #0b1220;
  --or-error-bg: rgba(239, 68, 68, 0.12);
  --or-error-text: #fca5a5;
  --or-success-bg: rgba(34, 197, 94, 0.08);
  --draft-bg: rgba(15, 23, 42, 0.55);
}

html[data-theme="light"] {
  --portal-bg: #e8edf4;
  --portal-sidebar: #ffffff;
  --portal-card: #ffffff;
  --portal-border: #cbd5e1;
  --portal-text: #0f172a;
  --portal-muted: #475569;
  --portal-table-text: #1e293b;
  --portal-table-head: #334155;
  --page-bg: #dde4ee;
  --or-error-bg: #fef2f2;
  --or-error-text: #b91c1c;
  --or-success-bg: #f0fdf4;
  --draft-bg: #f1f5f9;
}

html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ═══════════════ LOGIN PAGE ═══════════════ */
.login-page { min-height: 100vh; position: relative; background: #ffffff; }

.login-page--light {
  background: #f8fafc;
}

.login-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 35%, #6B8DD6 60%, #0ea5e9 100%);
  background-size: 400% 400%;
  animation: gradientShift 12s ease infinite;
}

.login-page--light .login-bg {
  display: none;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.glass-card {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.15);
}

.login-page--light .login-card {
  background: #ffffff;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: 1px solid #e2e8f0;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 40px 36px;
  animation: fadeUp 0.6s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.brand-logo {
  max-height: 48px;
  max-width: 92px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}
.brand-icon {
  width: 48px; height: 48px; border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #0ea5e9);
  color: #fff; font-weight: 800; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
}
.brand h1 { font-size: 22px; font-weight: 800; color: #0f172a; }
.brand p { font-size: 13px; color: #64748b; margin-top: 2px; }

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; font-weight: 600; color: #334155;
}
.login-form input {
  padding: 12px 14px;
  border: 1.5px solid rgba(99, 102, 241, 0.25);
  border-radius: 10px;
  font-size: 15px;
  background: rgba(255,255,255,0.9);
}
.login-form input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  width: 100%;
  padding-right: 44px;
  box-sizing: border-box;
}

.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-toggle:hover {
  color: #6366f1;
  background: rgba(99, 102, 241, 0.08);
}

.password-toggle:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

.password-toggle-icon[hidden] {
  display: none;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 20px; border-radius: 10px; font-size: 14px; font-weight: 700;
  border: none; cursor: pointer; text-decoration: none; transition: transform 0.15s, opacity 0.15s;
}
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-block { width: 100%; }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

.login-hint {
  font-size: 12px; color: #64748b; margin-top: 20px; text-align: center;
}

/* ═══════════════ PORTAL DASHBOARD (website match) ═══════════════ */
.portal-body {
  background: var(--page-bg);
  min-height: 100vh;
  color: var(--portal-text);
}

.portal-body.portal-full .portal-app {
  min-height: 100vh;
  background: var(--page-bg);
}

.portal-page-wrap {
  padding: 24px 20px 48px;
  max-width: 1200px;
  margin: 0 auto;
}

.portal-window {
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  border: 1px solid var(--portal-border);
}

/* Browser chrome */
.portal-chrome {
  background: #1e2535;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #0f172a;
}

.chrome-dots { display: flex; gap: 6px; }
.chrome-dots span {
  width: 12px; height: 12px; border-radius: 50%;
}
.chrome-dots span:nth-child(1) { background: #ef4444; }
.chrome-dots span:nth-child(2) { background: #f59e0b; }
.chrome-dots span:nth-child(3) { background: #22c55e; }

.chrome-url {
  flex: 1;
  background: #0f172a;
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 11px;
  color: #64748b;
  font-family: ui-monospace, monospace;
}

/* Layout */
.portal-layout {
  display: flex;
  align-items: stretch;
  background: var(--portal-bg);
  min-height: 620px;
}

/* Sidebar */
.portal-sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--portal-sidebar);
  border-right: 1px solid var(--portal-border);
  display: flex;
  flex-direction: column;
  padding: 20px 0 16px;
}

.sidebar-brand {
  padding: 12px 16px 18px;
  border-bottom: 1px solid var(--portal-border);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
}

.sidebar-logo {
  width: 100%;
  max-width: 168px;
  height: auto;
  max-height: 56px;
  object-fit: contain;
  display: block;
}

.sidebar-brand-title {
  font-size: 13px;
  font-weight: 900;
  color: var(--accent);
  transition: color 0.2s;
}

.sidebar-brand-sub {
  font-size: 10px;
  color: var(--portal-muted);
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
}

.sidebar-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  font-size: 11px;
  font-weight: 400;
  color: #94a3b8;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.sidebar-item:hover:not(.is-static) {
  color: #94a3b8;
  background: rgba(255,255,255,0.03);
}

.sidebar-item.is-active {
  font-weight: 700;
  color: var(--portal-text);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-left-color: var(--accent);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .sidebar-item.is-active {
    background: rgba(29, 78, 216, 0.12);
  }
}

.sidebar-item.is-static {
  cursor: default;
  opacity: 0.45;
  font-size: 10px;
}

.sidebar-divider {
  height: 1px;
  background: var(--portal-border);
  margin: 8px 14px;
}

.sidebar-label {
  padding: 8px 14px 4px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #334155;
}

.sidebar-footer {
  padding: 12px 14px 0;
  border-top: 1px solid var(--portal-border);
  margin-top: 8px;
}

.sidebar-user {
  font-size: 11px;
  font-weight: 700;
  color: #cbd5e1;
}

.sidebar-user-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-user-meta {
  font-size: 10px;
  font-weight: 500;
  color: #94a3b8;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  color: #fff;
  font-weight: 900;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 6px 20px rgba(29, 78, 216, 0.25);
}

.sidebar-plan {
  font-size: 10px;
  color: var(--portal-muted);
  margin-top: 2px;
}

.sidebar-logout {
  display: inline-block;
  margin-top: 8px;
  font-size: 10px;
  color: #64748b;
  text-decoration: none;
}

.sidebar-logout:hover { color: #94a3b8; }

/* Main */
.portal-main {
  flex: 1;
  padding: 24px 28px 28px;
  overflow-y: auto;
  min-width: 0;
}

.portal-main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  gap: 12px;
}

.portal-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--portal-text);
  margin-bottom: 3px;
}

.portal-subtitle {
  font-size: 11px;
  color: var(--portal-muted);
}

.live-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--portal-green);
  background: rgba(34, 197, 94, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(34, 197, 94, 0.25);
}

/* KPI row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  padding: 16px 18px;
  text-align: center;
}

.kpi-value {
  font-size: 26px;
  font-weight: 900;
  color: var(--portal-text);
  letter-spacing: -1px;
  line-height: 1;
  margin-bottom: 5px;
}

.kpi-value.is-accent {
  color: var(--accent);
  font-size: 22px;
}

.kpi-label {
  font-size: 10px;
  color: #4b5563;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Status grid */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.status-card {
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.status-name {
  font-size: 11px;
  font-weight: 700;
  color: #cbd5e1;
}

.status-detail {
  font-size: 10px;
  color: var(--portal-green);
  font-weight: 700;
  text-align: right;
  flex-shrink: 0;
}

/* Channel panel */
.channel-panel {
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 12px;
}

.panel-title {
  font-size: 10px;
  color: var(--portal-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 14px;
}

.channel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.channel-row:last-child { margin-bottom: 0; }

.channel-label {
  font-size: 10px;
  color: #6b7280;
  width: 90px;
  flex-shrink: 0;
}

.channel-track {
  flex: 1;
  height: 6px;
  background: var(--portal-bg);
  border-radius: 999px;
  overflow: hidden;
}

.channel-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.channel-stat {
  font-size: 10px;
  font-weight: 700;
  width: 58px;
  text-align: right;
  flex-shrink: 0;
}

/* Activity */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.activity-row {
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.activity-text {
  font-size: 11px;
  color: #cbd5e1;
  font-weight: 600;
}

.activity-stat {
  font-size: 10px;
  font-weight: 700;
  color: var(--portal-green);
  flex-shrink: 0;
}

/* Workspace */
.workspace-panel {
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  padding: 18px 20px;
  border-top: 2px solid var(--accent);
}

.workspace-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.workspace-icon { font-size: 24px; line-height: 1; }

.workspace-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--portal-text);
}

.workspace-desc {
  font-size: 11px;
  color: var(--portal-muted);
  margin-top: 2px;
}

.workspace-form {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.workspace-form.is-visible {
  display: flex;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.workspace-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 10px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.workspace-form input,
.workspace-form select,
.workspace-form textarea {
  padding: 10px 12px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--portal-bg);
  color: var(--portal-text);
}

.workspace-form input:focus,
.workspace-form select:focus,
.workspace-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.25);
}

.workspace-form textarea {
  resize: vertical;
  min-height: 64px;
}

.btn-launch {
  align-self: flex-start;
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  color: #fff;
  border: none;
  padding: 11px 22px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  margin-top: 4px;
}

.btn-launch:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-launch:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.workspace-panel.is-loading .btn-launch { opacity: 0.6; }

/* Results in dark theme */
.agent-result {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--portal-border);
  animation: fadeUp 0.35s ease;
}

.agent-result[hidden] { display: none !important; }

.agent-result.loading {
  display: flex !important;
  align-items: center;
  gap: 10px;
  color: var(--portal-muted);
  font-size: 12px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(29, 78, 216, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.result-error {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  padding: 12px;
  border-radius: 8px;
  font-size: 12px;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.result-block { margin-bottom: 12px; }
.result-block:last-child { margin-bottom: 0; }

.result-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #60a5fa;
  margin-bottom: 4px;
}

.result-value {
  font-size: 12px;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--portal-bg);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--portal-border);
}

.result-score {
  font-size: 28px;
  font-weight: 800;
  color: #60a5fa;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.quick-reply-tag {
  background: rgba(29, 78, 216, 0.2);
  color: #93c5fd;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

/* Responsive */
@media (max-width: 900px) {
  .portal-layout { flex-direction: column; }
  .portal-sidebar {
    width: 100%;
    flex-direction: column;
    padding: 12px;
    border-right: none;
    border-bottom: 1px solid var(--portal-border);
  }
  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }
  .sidebar-label,
  .sidebar-divider,
  .sidebar-item.is-static {
    display: none;
  }
  .sidebar-item[data-agent] {
    width: auto;
    border-left: none;
    border-radius: 6px;
    padding: 8px 12px;
  }
  .kpi-row { grid-template-columns: 1fr; }
  .status-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .portal-page-wrap { padding: 12px 10px 32px; }
  .portal-main { padding: 16px; }
}

/* ── Dashboard top bar + header user + theme toggle ───────────────────── */
.portal-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--portal-border);
}

.portal-topbar-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--portal-text);
  letter-spacing: -0.02em;
  padding-top: 6px;
}

.portal-topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  justify-content: flex-end;
  min-width: 0;
}

.header-user-menu {
  position: relative;
}

.header-user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--portal-text);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.header-user-trigger:hover,
.header-user-menu.is-open .header-user-trigger {
  background: var(--portal-card);
  border-color: var(--portal-border);
}

.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  color: #fff;
  font-weight: 900;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(29, 78, 216, 0.22);
}

.header-user-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--portal-text);
  line-height: 1.2;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-user-chevron {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--portal-muted);
  margin-left: 2px;
  transition: transform 0.15s;
}

.header-user-menu.is-open .header-user-chevron {
  transform: rotate(180deg);
}

.header-user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 200;
  min-width: 260px;
  max-width: min(320px, 90vw);
  padding: 14px 16px;
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

.header-user-dropdown[hidden] {
  display: none !important;
}

.header-dropdown-email {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--portal-muted);
  line-height: 1.4;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.header-dropdown-plan {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
  color: var(--portal-text);
}

.header-dropdown-quota {
  margin: 0 0 12px;
  font-size: 11px;
  color: var(--portal-muted);
  line-height: 1.4;
}

.header-dropdown-logout {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.header-dropdown-logout:hover {
  text-decoration: underline;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--portal-border);
  background: var(--portal-card);
  color: var(--portal-text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.theme-toggle-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  justify-content: center;
  border-radius: 12px;
  font-size: 18px;
}

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

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

html[data-theme="light"] .sidebar-item { color: #475569; }
html[data-theme="light"] .sidebar-item.is-active { color: var(--portal-text); }
html[data-theme="light"] .status-name { color: var(--portal-text); }
html[data-theme="light"] .status-detail { color: var(--portal-muted); }
html[data-theme="light"] .or-table th { color: var(--portal-table-head); }
html[data-theme="light"] .or-table td { color: var(--portal-table-text); }
html[data-theme="light"] .or-table .or-cell-strong { color: #0f172a; }
html[data-theme="light"] .or-table tr:hover td { background: rgba(15, 23, 42, 0.04); }
html[data-theme="light"] .or-panel-title { color: #0f172a; }
html[data-theme="light"] .portal-topbar-title { color: #0f172a; }

/* ── Email campaign action buttons ────────────────────────────────────── */
.ec-action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
  border-radius: 12px;
  margin-top: 4px;
}

.btn-ec {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.btn-ec:hover:not(:disabled) { transform: translateY(-1px); }
.btn-ec:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-ec-primary {
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  color: #fff;
  box-shadow: 0 4px 14px rgba(29, 78, 216, 0.35);
}

.btn-ec-success {
  background: linear-gradient(135deg, #15803d, #22c55e);
  color: #fff;
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.3);
}

.btn-ec-ghost {
  background: var(--portal-bg);
  color: var(--portal-text);
  border: 1px solid var(--portal-border);
}

.btn-ec-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.btn-ec-outline:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

.ec-quota-pill {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--portal-muted);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--portal-bg);
  border: 1px solid var(--portal-border);
}

.btn-or-secondary {
  background: var(--portal-bg);
  color: var(--portal-text);
  border: 1px solid var(--portal-border);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-or-secondary:hover { border-color: var(--accent); }

/* ── Email drafts bulk approve ────────────────────────────────────────── */
.ec-drafts-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
  border-radius: 10px;
}

.ec-select-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--portal-text);
  cursor: pointer;
}

.ec-draft-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--portal-muted);
}

.ec-drafts-heading {
  font-size: 11px;
  font-weight: 800;
  color: var(--portal-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.ec-draft-card {
  padding: 14px;
  margin-bottom: 10px;
  background: var(--draft-bg);
  border: 1px solid var(--portal-border);
  border-radius: 10px;
}

.ec-draft-card.is-approved {
  border-color: rgba(34, 197, 94, 0.45);
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.15);
}

.ec-draft-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.ec-draft-name { font-weight: 700; color: var(--portal-text); }
.ec-draft-meta { font-size: 10px; color: var(--portal-muted); }
.ec-approve-label {
  font-size: 11px;
  color: #16a34a;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 700;
}

html[data-theme="dark"] .ec-approve-label { color: #22c55e; }

.ec-draft-subject { font-size: 12px; color: #2563eb; font-weight: 600; margin-top: 8px; }
html[data-theme="dark"] .ec-draft-subject { color: #60a5fa; }

.ec-draft-body {
  font-size: 11px;
  color: var(--portal-muted);
  margin-top: 4px;
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 140px;
  overflow: auto;
}

/* ── Reply inbox ────────────────────────────────────────────────────────── */
.inbox-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 14px;
  min-height: 420px;
}

.inbox-list-panel { max-height: 520px; overflow-y: auto; }

.inbox-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  background: var(--portal-bg);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s;
}

.inbox-item:hover { border-color: var(--accent); }
.inbox-item-unread { border-left: 3px solid #22c55e; background: var(--draft-bg); }

.inbox-item-name { font-weight: 700; font-size: 12px; color: var(--portal-text); }
.inbox-item-sub { font-size: 11px; color: var(--accent); margin-top: 4px; }
.inbox-item-snippet { font-size: 10px; color: var(--portal-muted); margin-top: 4px; line-height: 1.4; }

.inbox-detail-panel { min-height: 400px; }
.inbox-detail-head { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--portal-border); }
.inbox-thread-block { margin-bottom: 14px; padding: 12px; background: var(--draft-bg); border-radius: 8px; border: 1px solid var(--portal-border); }
.inbox-reply-block { border-color: rgba(34, 197, 94, 0.35); }
.inbox-label { font-size: 9px; font-weight: 800; text-transform: uppercase; color: var(--portal-muted); margin-bottom: 6px; }
.inbox-subject { font-size: 12px; font-weight: 700; color: var(--portal-text); margin-bottom: 6px; }
.inbox-body { font-size: 11px; color: var(--portal-muted); white-space: pre-wrap; line-height: 1.5; max-height: 160px; overflow: auto; }

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

/* Data Agent — sample lead cards (theme-aware, readable in light + dark) */
.or-lead-sample {
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--portal-card);
  border: 1px solid var(--portal-border);
}
.or-lead-sample-name {
  font-weight: 700;
  font-size: 12px;
  color: var(--portal-text);
}
.or-lead-sample-meta {
  font-size: 11px;
  color: var(--portal-muted);
  margin-top: 2px;
}
.or-lead-sample-line {
  font-size: 10px;
  color: var(--portal-muted);
  margin-top: 4px;
}
.or-lead-sample-line a {
  color: var(--accent);
}
.or-lead-sample-phone {
  font-size: 11px;
  color: var(--portal-text);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.or-sync-notice {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.45;
}
.or-sync-notice.warn {
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: #b45309;
}
html[data-theme="dark"] .or-sync-notice.warn {
  color: #fcd34d;
}
.or-sync-notice.ok {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: var(--portal-green);
}

.or-kpi-clickable {
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.or-kpi-clickable:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.sidebar-mail-count,
.mail-folder-count {
  float: right;
  font-size: 10px;
  font-weight: 700;
  color: var(--portal-muted);
  background: var(--portal-bg);
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.mail-layout {
  display: grid;
  grid-template-columns: 200px minmax(280px, 340px) 1fr;
  gap: 14px;
  min-height: 480px;
}

.mail-folders {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px !important;
}

.mail-folder-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--portal-text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.mail-folder-btn:hover {
  background: var(--portal-bg);
}
.mail-folder-btn.is-active {
  background: rgba(29, 78, 216, 0.15);
  border-color: rgba(96, 165, 250, 0.35);
  color: var(--accent);
}

.mail-list-scroll {
  max-height: 520px;
  overflow-y: auto;
}

.mail-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: var(--portal-bg);
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}
.mail-item:hover { border-color: var(--accent); }
.mail-item.is-selected {
  border-color: var(--accent);
  background: rgba(29, 78, 216, 0.1);
}

.mail-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.mail-item-name { font-weight: 700; font-size: 12px; color: var(--portal-text); }
.mail-item-date { font-size: 9px; color: var(--portal-muted); white-space: nowrap; }
.mail-item-subject { font-size: 11px; font-weight: 600; color: var(--portal-text); margin-bottom: 4px; }
.mail-item-snippet { font-size: 10px; color: var(--portal-muted); line-height: 1.4; margin-bottom: 6px; }
.mail-item-badges { display: flex; flex-wrap: wrap; gap: 4px; }

.mail-badge {
  font-size: 8px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.3px;
}
.mail-badge.sent { background: rgba(96, 165, 250, 0.2); color: #60a5fa; }
.mail-badge.opened { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.mail-badge.delivered { background: rgba(34, 197, 94, 0.12); color: #4ade80; }
.mail-badge.draft { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
.mail-badge.replied { background: rgba(167, 139, 250, 0.2); color: #a78bfa; }
.mail-badge.approved { background: rgba(148, 163, 184, 0.2); color: var(--portal-muted); }

.mail-empty { font-size: 12px; color: var(--portal-muted); padding: 12px; }

.mail-detail-panel { min-height: 400px; }
.mail-detail-head {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--portal-border);
}
.mail-detail-subject { font-size: 15px; font-weight: 800; color: var(--portal-text); margin-bottom: 8px; }
.mail-detail-to { font-size: 12px; color: var(--portal-muted); margin-bottom: 4px; }
.mail-detail-meta { font-size: 11px; color: var(--portal-muted); margin-bottom: 6px; }
.mail-detail-status { font-size: 10px; color: var(--portal-green); }
.mail-detail-body {
  font-size: 13px;
  color: var(--portal-text);
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
}
.mail-detail-frame {
  width: 100%;
  min-height: 360px;
  max-height: 480px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: #fff;
  margin-top: 8px;
}

/* Pagination */
.or-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.or-pagination button {
  padding: 6px 12px;
  border: 1px solid var(--portal-border);
  border-radius: 6px;
  background: var(--portal-bg);
  color: var(--portal-text);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.or-pagination button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.or-pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.or-pagination .or-page-info {
  font-size: 11px;
  color: var(--portal-muted);
  padding: 0 6px;
}
.or-leads-table-wrap {
  margin-top: 12px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
}
.or-leads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.or-leads-table th {
  position: sticky;
  top: 0;
  background: var(--portal-card);
  color: var(--portal-muted);
  font-weight: 700;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--portal-border);
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 0.4px;
}
.or-leads-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--portal-border);
  color: var(--portal-text);
  vertical-align: top;
}
.or-leads-table tr:last-child td { border-bottom: none; }
.or-leads-table .or-date-cell {
  white-space: nowrap;
  color: var(--portal-muted);
  font-size: 10px;
}

/* Email campaign — subject line toggle + input */
.ec-subject-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.2);
}
.ec-subject-label {
  font-size: 10px;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.ec-subject-controls {
  display: flex;
  align-items: stretch;
  gap: 10px;
}
.ec-subject-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: var(--portal-bg);
  font-size: 12px;
  font-weight: 700;
  color: var(--portal-muted);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.ec-subject-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.ec-subject-row.is-active .ec-subject-check {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: rgba(29, 78, 216, 0.12);
  color: var(--accent);
}
.ec-subject-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--portal-bg);
  color: var(--portal-text);
  transition: opacity 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.ec-subject-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.ec-subject-input:focus:not(:disabled) {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.2);
}
.ec-subject-row.is-active .ec-subject-input:disabled {
  opacity: 1;
}
.ec-subject-hint {
  font-size: 10px;
  color: var(--portal-muted);
  line-height: 1.4;
}

.ec-campaign-picker {
  position: relative;
  margin: 0 0 12px;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  background: var(--portal-card);
  overflow: visible;
}
.ec-campaign-pick-trigger {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px 10px;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: var(--portal-card);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: var(--portal-text);
  transition: background 0.15s, border-color 0.15s;
}
.ec-campaign-pick-trigger:hover {
  background: rgba(59, 130, 246, 0.08);
}
.ec-campaign-picker.is-open .ec-campaign-pick-trigger {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  background: rgba(59, 130, 246, 0.1);
}
.ec-campaign-pick-trigger-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--portal-muted);
  white-space: nowrap;
}
.ec-campaign-pick-trigger-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--portal-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ec-campaign-pick-trigger.has-selection .ec-campaign-pick-trigger-text {
  color: var(--portal-text);
  font-weight: 700;
}
.ec-campaign-pick-chevron {
  font-size: 12px;
  color: var(--portal-muted);
  transition: transform 0.15s;
  line-height: 1;
}
.ec-campaign-picker.is-open .ec-campaign-pick-chevron {
  transform: rotate(180deg);
}
.ec-campaign-pick-panel {
  display: none;
  border-top: 1px solid var(--portal-border);
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  overflow: hidden;
  background: var(--portal-card);
}
.ec-campaign-pick-panel[hidden] {
  display: none !important;
}
.ec-campaign-picker.is-open .ec-campaign-pick-panel:not([hidden]) {
  display: block;
}
.ec-campaign-pick-empty {
  font-size: 11px;
  color: var(--portal-muted);
  padding: 14px 12px;
  margin: 0;
}
.ec-campaign-pick-list {
  max-height: min(520px, 70vh);
  overflow-y: auto;
  background: var(--portal-card);
}
.ec-campaign-pick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--portal-border);
  cursor: pointer;
  margin: 0;
  transition: background 0.15s;
  flex-direction: row;
  text-transform: none;
  letter-spacing: normal;
  font-size: 12px;
  font-weight: 700;
  color: var(--portal-text);
  background: var(--portal-card);
}
.ec-campaign-pick-item:last-child {
  border-bottom: none;
}
.ec-campaign-pick-item:hover {
  background: rgba(59, 130, 246, 0.1);
}
.ec-campaign-pick-item.is-selected {
  background: rgba(59, 130, 246, 0.15);
  border-left: 3px solid #3b82f6;
  padding-left: 9px;
}
html[data-theme="light"] .ec-campaign-picker,
html[data-theme="light"] .ec-campaign-pick-trigger,
html[data-theme="light"] .ec-campaign-pick-panel,
html[data-theme="light"] .ec-campaign-pick-list,
html[data-theme="light"] .ec-campaign-pick-item {
  background: #fff;
}
html[data-theme="light"] .ec-campaign-pick-item:hover {
  background: #f1f5f9;
}
html[data-theme="light"] .ec-campaign-pick-item.is-selected {
  background: #eff6ff;
  border-left-color: #2563eb;
}
.ec-campaign-pick-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  border-radius: 4px;
  cursor: pointer;
  accent-color: #3b82f6;
}
.or-form .ec-campaign-pick-item input[type="checkbox"] {
  padding: 0;
  box-shadow: none;
  background: var(--portal-bg);
}
.or-form .ec-campaign-pick-trigger {
  padding: 10px 12px;
}
.ec-campaign-pick-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ec-campaign-pick-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--portal-text);
}
.ec-campaign-pick-meta {
  font-size: 10px;
  color: var(--portal-muted);
  font-weight: 500;
}
@media (max-width: 640px) {
  .ec-subject-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .ec-subject-check {
    justify-content: center;
  }
}

.ec-sig-block {
  margin: 16px 0 12px;
  padding: 14px 16px;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.25);
}
.ec-sig-block-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--portal-muted);
  margin-bottom: 12px;
}
.ec-sig-preview {
  margin-top: 12px;
  padding: 14px 16px;
  border-top: 1px solid var(--portal-border);
  background: #fff;
  border-radius: 8px;
}
.ec-sig-preview-label {
  font-size: 10px;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ec-sig-preview-body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  color: #475569;
  line-height: 1.5;
}
.ec-sig-preview-body .ec-sig-line { margin: 0 0 6px; }
.ec-sig-preview-body .ec-sig-name { font-weight: 700; color: #0f172a; font-size: 14px; }
.ec-sig-preview-body .ec-sig-logo { margin-top: 10px; }

@media (max-width: 900px) {
  #view-mailbox .mail-layout,
  .mail-layout { grid-template-columns: 1fr; }
  #view-mailbox .mail-folders,
  .mail-folders { flex-direction: row; flex-wrap: wrap; min-height: auto; }
}
