:root {
  --header-bg: #0f1720;
  --header-border: #1e293b;
  --accent: #3d8bfd;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-on-dark: #e8eef6;
  --muted-on-dark: #94a3b8;
  --surface: #ffffff;
  --page: #f1f5f9;
  --card-border: #e2e8f0;
  --up: #15803d;
  --down: #b91c1c;
  --chart-bar: #3d8bfd;
  --type-1: #0b3d5c;
  --type-2: #3d8bfd;
  --type-3: #0d9488;
  --type-4: #f59e0b;
  --type-5: #94a3b8;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --gap: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  font-family: var(--font);
  background: var(--page);
  color: var(--text);
}

body.embed-mode .chrome-only { display: none !important; }
body.embed-mode { background: var(--page); }
body.embed-mode .app-shell { min-height: 100vh; }

.hidden { display: none !important; }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 30% 0%, #1e293b 0%, var(--header-bg) 55%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #1a2332;
  border: 1px solid var(--header-border);
  border-radius: 12px;
  padding: 28px 24px;
  color: var(--text-on-dark);
}
.login-card h1 { margin: 0 0 6px; font-size: 1.25rem; }
.login-card .sub { margin: 0 0 18px; color: var(--muted-on-dark); font-size: 0.88rem; }
.login-card label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted-on-dark);
  margin-bottom: 6px;
}
.login-card input {
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f1419;
  color: var(--text-on-dark);
  font-size: 0.95rem;
}
.login-card button {
  width: 100%;
  margin-top: 4px;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.login-error { color: #f87171; font-size: 0.85rem; min-height: 1.2em; margin: 0 0 8px; }
.login-hint {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--header-border);
  font-size: 0.72rem;
  color: var(--muted-on-dark);
  line-height: 1.45;
}
.login-hint code {
  background: #243044;
  padding: 1px 5px;
  border-radius: 4px;
}

/* ---- Header ---- */
.portal-header {
  background: var(--header-bg);
  color: var(--text-on-dark);
  border-bottom: 1px solid var(--header-border);
  padding: 14px 20px 12px;
}
.portal-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.partner-logo {
  height: 40px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  background: transparent;
  border-radius: 4px;
}
.header-titles { min-width: 0; }
.header-titles h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.header-meta {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--muted-on-dark);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}
.header-meta .sep { opacity: 0.4; }
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.admin-select-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.admin-select-wrap label {
  font-size: 0.68rem;
  color: var(--muted-on-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.admin-select-wrap select {
  min-width: 220px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0b1220;
  color: var(--text-on-dark);
  font-size: 0.88rem;
}
.btn-ghost {
  appearance: none;
  border: 1px solid #334155;
  background: transparent;
  color: var(--text-on-dark);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.header-actions .btn-ghost { color: var(--text-on-dark); }
.section-head .btn-ghost {
  color: var(--text);
  border-color: var(--card-border);
  background: var(--surface);
}
.kibana-embed-wrap {
  padding: 0;
  overflow: hidden;
}
.kibana-embed-wrap iframe {
  display: block;
  width: 100%;
  height: min(72vh, 820px);
  border: 0;
  background: #fff;
}
.kibana-embed-wrap .analyst-note {
  margin: 0;
  padding: 10px 14px 14px;
}
.kibana-mode {
  font-size: 0.75rem;
  color: var(--text-muted);
  align-self: center;
  font-family: ui-monospace, Consolas, monospace;
}
.scope-line {
  margin-top: 10px;
  font-size: 0.8rem;
  color: #cbd5e1;
}
.scope-line strong { color: #fff; font-weight: 600; }

/* ---- Content ---- */
.app-main {
  padding: 18px 20px 32px;
  max-width: 1280px;
  margin: 0 auto;
}
.app-shell.kibana-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}
.app-shell.kibana-shell .app-footer {
  display: none;
}
.app-main.kibana-main {
  position: relative;
  flex: 1 1 auto;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  min-height: 0;
  display: block;
}
.kibana-frame-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  border-top: 1px solid var(--card-border);
  overflow: hidden;
}
.kibana-frame {
  display: block;
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  min-width: 100%;
  min-height: 100%;
  border: 0;
  background: #fff;
}
body.embed-mode .app-shell.kibana-shell {
  height: 100vh;
}
body.embed-mode .kibana-frame,
body.embed-mode .kibana-frame-wrap {
  inset: 0;
}
.section {
  margin-bottom: 22px;
}
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.section-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}
.section-head p {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 640px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
}
.kpi-card, .panel-card, .summary-card {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi-card .label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-card .value {
  margin-top: 8px;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.kpi-card .delta {
  margin-top: 8px;
  font-size: 0.82rem;
  font-weight: 600;
}
.kpi-card .delta.up { color: var(--up); }
.kpi-card .delta.down { color: var(--down); }
.kpi-card .delta.flat { color: var(--text-muted); }
.analyst-note {
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--card-border);
}

.ot-layout {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: var(--gap);
  align-items: stretch;
}
.panel-card h3, .summary-card h3 {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-weight: 650;
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.segmented button {
  border: none;
  background: transparent;
  padding: 7px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
}
.segmented button.active {
  background: #0f172a;
  color: #fff;
}
.chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;
}
.chart-wrap.horizontal { height: 280px; }
.summary-stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.summary-card .value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.summary-card .delta {
  margin-top: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}
.summary-card .delta.up { color: var(--up); }
.summary-card .delta.down { color: var(--down); }

.split-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--card-border);
  font-weight: 650;
}
.data-table td {
  padding: 10px;
  border-bottom: 1px solid #f1f5f9;
  font-variant-numeric: tabular-nums;
}
.data-table tr.total td {
  font-weight: 700;
  background: #f8fafc;
  border-top: 1px solid var(--card-border);
}
.data-table td.num, .data-table th.num { text-align: right; }

.status-banner {
  padding: 10px 14px;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  font-size: 0.85rem;
  margin-bottom: 14px;
}

.app-footer {
  padding: 8px 20px 20px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ---- Responsive ---- */
@media (max-width: 960px) {
  .card-grid { grid-template-columns: 1fr; }
  .ot-layout { grid-template-columns: 1fr; }
  .split-2 { grid-template-columns: 1fr; }
  .header-titles h1 { font-size: 1.02rem; }
}
@media (max-width: 640px) {
  .app-main { padding: 14px 12px 24px; }
  .portal-header { padding: 12px; }
  .partner-logo { height: 32px; max-width: 120px; }
  .kpi-card .value { font-size: 1.4rem; }
  .admin-select-wrap select { min-width: 160px; width: 100%; }
}
