:root {
  --sidebar: #07162b;
  --sidebar-2: #0b2340;
  --bg: #f8fafc;
  --card: #fff;
  --text: #172033;
  --muted: #68758a;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #4f46e5;
  --primary-2: #2563eb;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", Arial, sans-serif; font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }

.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: grid; grid-template-rows: auto 1fr auto; height: 100vh; padding: 22px 14px; background: radial-gradient(circle at 55% 0%, rgba(79, 70, 229, .32), transparent 30%), linear-gradient(180deg, var(--sidebar), var(--sidebar-2)); color: #e5e7eb; }
.brand, .profile { display: flex; align-items: center; gap: 12px; }
.brand span, .profile span { display: grid; width: 40px; height: 40px; place-items: center; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; font-weight: 900; box-shadow: 0 10px 24px rgba(79, 70, 229, .35); }
.brand strong, .profile strong { display: block; color: #fff; font-size: 20px; }
.brand small, .profile small { color: #94a3b8; }
.profile { padding: 14px; border: 1px solid rgba(255,255,255,.08); border-radius: 14px; background: rgba(255,255,255,.05); }
.profile strong { font-size: 14px; }
.profile span { width: 38px; height: 38px; }

.nav { display: grid; align-content: start; gap: 4px; margin-top: 28px; overflow: auto; padding-right: 2px; -ms-overflow-style: none; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav button, .subnav button { display: flex; align-items: center; width: 100%; min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: #cbd5e1; text-align: left; font-weight: 600; }
.nav button:hover, .nav button.active, .subnav button.active { background: linear-gradient(135deg, rgba(95,83,255,.76), rgba(49,91,214,.56)); color: #fff; box-shadow: 0 10px 28px rgba(28,50,120,.28); }
.subnav { display: grid; gap: 2px; margin: 2px 0 8px 24px; }
.subnav button { min-height: 30px; color: #aebbd0; font-size: 12px; font-weight: 500; }

.workspace { min-width: 0; padding: 24px 28px 18px; }
.mode-ribbon { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.mode-badge, .engine-badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border: 1px solid var(--line); border-radius: 999px; background: #f8fafc; color: #475569; font-size: 11px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.mode-badge.good, .engine-badge.good { border-color: #bbf7d0; background: #dcfce7; color: var(--good); }
.mode-badge.warn, .engine-badge.warn { border-color: #fde68a; background: #fef3c7; color: var(--warn); }
.mode-badge.bad, .engine-badge.bad { border-color: #fecaca; background: #fee2e2; color: var(--bad); }
.engine-badge.indigo { border-color: #c7d2fe; background: #eef2ff; color: var(--primary); }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-header h1 { margin: 0; color: #111827; font-size: 29px; line-height: 1.15; }
.page-header p { margin: 6px 0 0; color: var(--muted); }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

.btn, .row-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 15px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: #1f2937; font-weight: 600; }
.btn:hover, .row-btn:hover { border-color: #a5b4fc; }
.btn.primary { border-color: transparent; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; }
.btn.light { min-height: 32px; background: #f8fafc; }
.row-btn { min-height: 28px; padding: 0 10px; }

.engine-tabs { display: flex; flex-wrap: wrap; gap: 10px; margin: -6px 0 20px; }
.engine-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: #1f2937; font-weight: 600; transition: all 0.2s ease; }
.engine-tabs button:hover { border-color: #a5b4fc; background: #f8fafc; }
.engine-tabs button.active { border-color: transparent; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 4px 14px rgba(79, 70, 229, 0.25); }

.settings-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.settings-tabs button { min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: #475569; font-weight: 600; }
.settings-tabs button.active { border-color: #c7d2fe; background: #eef2ff; color: var(--primary); }

.summary-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.summary-card, .card { border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.summary-card { min-height: 104px; padding: 16px; }
.summary-card small { color: #111827; font-weight: 600; }
.summary-card strong { display: block; margin-top: 8px; color: #111827; font-size: 28px; line-height: 1; }
.summary-card span { display: inline-block; margin-top: 10px; color: var(--muted); font-size: 12px; font-weight: 500; }

.dashboard-grid, .engine-detail, .insight-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.engine-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.engine-card { display: grid; gap: 14px; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.engine-card p { min-height: 54px; margin: 0; color: var(--muted); line-height: 1.5; }
.engine-card dl { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin: 0; padding: 12px; border-radius: 12px; background: #f8fafc; }
.engine-card dd { margin: 0; font-weight: 600; }
.architecture-card { margin-top: 18px; }
.architecture-card div { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.architecture-card span { padding: 7px 10px; border-radius: 999px; background: #f1f5f9; color: #475569; font-weight: 600; }

.card { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.card h2 { margin: 0; color: #111827; font-size: 17px; }
.table-card { min-width: 0; margin-bottom: 18px; }
.table-tools { display: flex; gap: 10px; }
.table-tools input { width: 240px; min-height: 40px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 12px; outline: 0; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; max-width: 360px; overflow-wrap: anywhere; }
th { position: sticky; top: 0; z-index: 1; background: #f8fafc; color: #64748b; font-size: 12px; font-weight: 600; }
tr:hover td { background: #fbfdff; }
.pagination { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; color: var(--muted); }
.pagination button { border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 99px; background: #f1f5f9; color: #475569; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.good { background: #dcfce7; color: var(--good); }
.pill.warn { background: #fef3c7; color: var(--warn); }
.pill.bad { background: #fee2e2; color: var(--bad); }

.control-card { display: flex; flex-wrap: wrap; align-items: end; gap: 14px; margin-bottom: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.field, .editor label { display: grid; gap: 7px; color: #475569; font-size: 12px; font-weight: 600; }
.field input, .field select, .editor input, .editor textarea { min-height: 40px; border: 1px solid var(--line-strong); border-radius: 10px; background: #fff; color: var(--text); padding: 0 12px; outline: 0; }
.editor textarea { min-height: 220px; padding: 12px; resize: vertical; }
.template-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.template-list { display: grid; align-content: start; gap: 8px; }
.template-list button { min-height: 46px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: #334155; text-align: left; font-weight: 600; }
.template-list button.active { border-color: #c7d2fe; background: #eef2ff; color: var(--primary); }
.template-list button small { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 500; }
.editor { display: grid; gap: 14px; }
.hint, .empty { padding: 18px; border-radius: 12px; background: #f8fafc; color: var(--muted); text-align: center; }
.settings-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

.toast-host { position: fixed; right: 24px; bottom: 24px; z-index: 50; }
.toast { max-width: 360px; padding: 13px 15px; border-radius: 12px; background: #111827; color: #fff; box-shadow: var(--shadow); font-weight: 600; }
.toast.success { background: #166534; }
.toast.error { background: #991b1b; }
.modal.hidden { display: none; }
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(15,23,42,.5); }
.modal-card { position: relative; width: min(720px, calc(100vw - 40px)); max-height: calc(100vh - 80px); overflow-y: auto; padding: 24px; border-radius: 18px; background: #fff; }
.modal-form { display: grid; gap: 14px; }
.icon-button { position: absolute; top: 12px; right: 12px; }
.error-screen { display: grid; min-height: 100vh; place-items: center; color: var(--bad); }

@media (max-width: 1280px) {
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-grid, .engine-detail, .insight-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; max-height: 55vh; }
  .workspace { padding: 18px 14px; }
  .page-header { display: grid; }
  .header-actions { justify-content: flex-start; }
  .summary-grid, .engine-grid, .template-layout { grid-template-columns: 1fr; }
  .table-tools { width: 100%; flex-wrap: wrap; }
  .table-tools input { width: min(100%, 260px); }
}

/* Layout & Component aliases for the new modular frontend */
.app-layout { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
.content-area { min-width: 0; padding: 24px 28px 18px; }
.sidebar-nav { display: grid; align-content: start; gap: 4px; margin-top: 28px; }
.nav-item { display: flex; align-items: center; width: 100%; min-height: 40px; padding: 0 12px; border-radius: 8px; color: #cbd5e1; text-decoration: none; font-weight: 600; }
.nav-item:hover, .nav-item.active { background: linear-gradient(135deg, rgba(95,83,255,.76), rgba(49,91,214,.56)); color: #fff; }
.sidebar-header { margin-bottom: 20px; }
.sidebar-footer { padding: 14px 0; border-top: 1px solid rgba(255,255,255,.08); }
.auth-card { max-width: 420px; margin: 80px auto; padding: 32px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.form-group { display: grid; gap: 7px; margin-bottom: 15px; }
.form-group label { color: #475569; font-size: 12px; font-weight: 600; }
.form-control { min-height: 40px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 12px; outline: 0; width: 100%; }
.data-table { width: 100%; border-collapse: collapse; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-top: 10px; }
.data-table th, .data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; }
.data-table th { background: #f8fafc; color: #64748b; font-size: 12px; font-weight: 600; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card { border: 1px solid var(--line); border-radius: 16px; background: var(--card); padding: 20px; box-shadow: var(--shadow); }
.kpi-card h3 { margin: 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: bold; margin: 10px 0 5px; color: #111827; }
.kpi-sub { margin: 0; color: var(--muted); font-size: 11px; }
.details-card { border: 1px solid var(--line); border-radius: 16px; background: var(--card); padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
.alert-box { padding: 15px; border-radius: 12px; margin-bottom: 20px; font-weight: 600; }
.alert-box.warning { background: #fffbeb; border: 1px solid #fef3c7; color: #b45309; }
.loading { padding: 40px; text-align: center; color: var(--muted); font-style: italic; }
.error-state { padding: 40px; text-align: center; color: var(--bad); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.badge.active, .badge.success, .badge.completed, .badge.sent { background: #dcfce7; color: var(--good); }
.badge.draft, .badge.warning, .badge.pending { background: #fef3c7; color: var(--warn); }
.badge.failed, .badge.error, .badge.cancelled { background: #fee2e2; color: var(--bad); }

/* ─── Premium Login Page ─── */
.login-container {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  padding: 20px;
  font-family: Inter, system-ui, sans-serif;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  text-align: center;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.login-card strong {
  display: block;
  font-size: 18px;
  font-weight: 750;
  color: #0f172a;
  margin-top: 4px;
}
.login-card span {
  display: block;
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}
.field input {
  height: 38px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
  font-size: 13px;
  transition: border-color 0.15s ease;
}
.field input:focus {
  border-color: #6366f1;
}
.primary-btn {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.primary-btn:hover {
  opacity: 0.95;
}
.login-error {
  padding: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
}

