/* Breadth — premium responsive shell (KPI color palettes preserved at end of file) */

:root {
  --sidebar-w: 260px;
  --topbar-h: 56px;
  --ink: #0b2b33;
  --ink-muted: #4a6670;
  --paper: #f7f7f7;
  --paper-elevated: #ffffff;
  --line: #d4dde0;
  --sidebar-bg: #0b2b33;
  --sidebar-text: #8fa8b0;
  --sidebar-active: #f7f7f7;
  --sidebar-muted: #6a8a94;
  --accent: #f14c23;
  --accent-hover: #c93e1c;
  --accent-soft: rgba(241, 76, 35, 0.14);
  --accent-glow: rgba(241, 76, 35, 0.28);
  --accent-border: rgba(241, 76, 35, 0.45);
  --positive: #467b59;
  --warm: #f1a679;
  --engine-header-bg: #0b2b33;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-soft: 0 1px 2px rgba(26, 29, 35, 0.04), 0 12px 32px rgba(26, 29, 35, 0.08);
  --shadow-panel: 0 0 0 1px rgba(26, 29, 35, 0.04), 0 16px 40px rgba(26, 29, 35, 0.07);
  --font-sans: "IBM Plex Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Code", monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --content-pad-x: clamp(16px, 3vw, 32px);
  --content-pad-y: clamp(16px, 2.5vw, 28px);
  --topbar-bg: rgba(255, 255, 255, 0.94);
  --grid-row-alt: rgba(247, 247, 247, 0.95);
}

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

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body.app-shell {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(ellipse 120% 80% at 100% -20%, rgba(241, 166, 121, 0.14), transparent 50%),
    radial-gradient(ellipse 80% 60% at -10% 100%, rgba(70, 123, 89, 0.08), transparent 45%),
    var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.app-shell.nav-open {
  overflow: hidden;
}

/* —— Mobile top bar —— */

.app-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  height: var(--topbar-h);
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(26, 29, 35, 0.04);
}

.topbar-start {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.topbar-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-left: auto;
}

.topbar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out), opacity 0.2s;
}

.topbar-logo:hover {
  transform: scale(1.04);
  opacity: 0.92;
}

.topbar-logo .brand-icon {
  width: 38px;
  height: 38px;
}

.sidebar-toggle {
  display: grid;
  place-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-elevated);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.2s var(--ease-out), background 0.2s var(--ease-out);
}

.sidebar-toggle:hover {
  border-color: var(--accent);
  background: var(--paper-elevated);
}

.sidebar-toggle__bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  transition: transform 0.25s var(--ease-out), opacity 0.2s;
}

body.nav-open .sidebar-toggle__bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

body.nav-open .sidebar-toggle__bar:nth-child(2) {
  opacity: 0;
}

body.nav-open .sidebar-toggle__bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 150;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(15, 18, 24, 0.45);
  backdrop-filter: blur(2px);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease-out);
}

body.nav-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* —— Sidebar —— */

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  max-width: min(var(--sidebar-w), 88vw);
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, #071a1f 100%);
  display: flex;
  flex-direction: column;
  z-index: 180;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  transition: transform 0.3s var(--ease-out);
}

.brand--sidebar {
  display: block;
}

.brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--sidebar-active);
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(145deg, var(--accent) 0%, var(--warm) 52%, var(--positive) 100%);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.02em;
  box-shadow: 0 2px 8px var(--accent-glow);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--sidebar-text);
}

.app-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px 12px;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 12px 10px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--sidebar-muted);
  padding: 14px 14px 6px;
  margin: 0;
}

.app-nav a {
  display: flex;
  align-items: center;
  padding: 11px 14px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out), border-color 0.2s var(--ease-out);
  min-height: 44px;
}

.app-nav a:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--sidebar-active);
}

.app-nav a.is-active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-active);
  border-left-color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

@keyframes page-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel--animate {
  animation: page-fade-in 0.45s var(--ease-out) backwards;
}

.home-grid__controls .panel:nth-child(2) {
  animation-delay: 0.06s;
}

.home-grid__modules {
  animation-delay: 0.1s;
}

/* —— Main —— */

.app-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-content {
  flex: 1;
  padding: var(--content-pad-y) var(--content-pad-x) max(32px, env(safe-area-inset-bottom));
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.page-head {
  margin-bottom: 22px;
}

.page-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 6px;
}

.page-title {
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.page-sub {
  margin: 8px 0 0;
  color: var(--ink-muted);
  font-size: 13px;
  max-width: 52ch;
}

/* —— Panels & forms —— */

.panel {
  background: var(--paper-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  padding: clamp(18px, 3vw, 24px);
  transition: box-shadow 0.25s var(--ease-out), border-color 0.2s var(--ease-out);
}

.panel:hover {
  border-color: rgba(241, 166, 121, 0.35);
}

.panel-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.panel-desc {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--ink-muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  min-height: 44px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out), transform 0.15s var(--ease-out), box-shadow 0.2s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:hover {
  background: var(--accent);
  color: #fff;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn--compact {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 13px;
}

.field-input--compact,
.field-select.field-input--compact {
  min-height: 34px;
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
  width: auto;
  max-width: none;
}

.field-input,
.field-select {
  font-family: var(--font-sans);
  font-size: 15px;
  padding: 10px 12px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-elevated);
  color: var(--ink);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.field-input:focus,
.field-select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.status-ok {
  margin-top: 12px;
  font-size: 13px;
  color: #2d6a4f;
  font-family: var(--font-mono);
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.alert {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
}

.alert-success {
  background: #e8f5ee;
  color: #1e6b45;
  border: 1px solid #b7dfc9;
}

.alert-error {
  background: #fdecec;
  color: #b42318;
  border: 1px solid #f5c2c0;
}

.upload-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.upload-status--success {
  background: #d4edda;
  color: #155724;
}

.upload-status--failed {
  background: #f8d7da;
  color: #721c24;
}

.kpi-event,
.kpi-trigger {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-event--start {
  background: #d4edda;
  color: #155724;
}

.kpi-event--stop {
  background: #f8d7da;
  color: #721c24;
}

.kpi-trigger--auto {
  background: #e8f0fe;
  color: #1a4a8a;
}

.kpi-trigger--manual {
  background: #fff3cd;
  color: #856404;
}

.upload-log-table td:first-child {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.upload-log-table .upload-message {
  text-align: left;
  max-width: 280px;
  white-space: normal;
  word-break: break-word;
  font-family: var(--font-sans);
  font-size: 12px;
}

/* —— Live feed status —— */

.live-feed-banner {
  margin: 0;
  padding: 10px 32px;
  font-size: 13px;
  line-height: 1.45;
  border-bottom: 1px solid var(--line);
}

.live-feed-banner a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

.live-feed-banner--expired,
.live-feed-banner--missing_token {
  background: #fdecec;
  color: #9b1c1c;
  border-bottom-color: #f5c2c0;
}

.live-feed-banner--error {
  background: #fff4e5;
  color: #8a4b00;
  border-bottom-color: #ffd699;
}

.live-feed-banner--connecting,
.live-feed-banner--starting,
.live-feed-banner--no_symbols {
  background: #eef4ff;
  color: #1f4fd8;
  border-bottom-color: #c7d7f7;
}

.sidebar-live-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 14px 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
}

.sidebar-live-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-live-status--connected {
  background: rgba(39, 174, 96, 0.15);
  color: #1e7a45;
}
.sidebar-live-status--connected .sidebar-live-status__dot {
  background: #27ae60;
}

.sidebar-live-status--expired,
.sidebar-live-status--missing_token,
.sidebar-live-status--error {
  background: rgba(192, 57, 43, 0.12);
  color: #c0392b;
}
.sidebar-live-status--expired .sidebar-live-status__dot,
.sidebar-live-status--missing_token .sidebar-live-status__dot,
.sidebar-live-status--error .sidebar-live-status__dot {
  background: #c0392b;
}

.sidebar-live-status--connecting,
.sidebar-live-status--starting,
.sidebar-live-status--no_symbols {
  background: rgba(31, 79, 216, 0.1);
  color: #1f4fd8;
}
.sidebar-live-status--connecting .sidebar-live-status__dot,
.sidebar-live-status--starting .sidebar-live-status__dot,
.sidebar-live-status--no_symbols .sidebar-live-status__dot {
  background: #1f4fd8;
}

.live-feed-panel {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  border: 1px solid var(--line);
}

.live-feed-panel--connected {
  background: #e8f5ee;
  border-color: #b7dfc9;
  color: #1e6b45;
}

.live-feed-panel--expired,
.live-feed-panel--missing_token {
  background: #fdecec;
  border-color: #f5c2c0;
  color: #9b1c1c;
}

.live-feed-panel--connecting,
.live-feed-panel--starting {
  background: #eef4ff;
  border-color: #c7d7f7;
  color: #1f4fd8;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 640px;
}

.admin-section {
  margin-bottom: 0;
}

.admin-field {
  margin-bottom: 16px;
}

.admin-field:last-child {
  margin-bottom: 0;
}

.admin-input {
  width: 100%;
  max-width: 220px;
}

.admin-help,
.admin-default,
.admin-updated {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.4;
}

.admin-default {
  font-family: var(--font-mono);
  font-size: 11px;
}

.kpi-snapshot-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  margin-bottom: 16px;
  background: var(--paper-elevated);
}

.kpi-snapshot-bar__info strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.kpi-snapshot-bar__info {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.kpi-snapshot-bar__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.kpi-snapshot-bar__dot--active { background: #27ae60; }
.kpi-snapshot-bar__dot--paused { background: #f1c40f; }
.kpi-snapshot-bar__dot--stopped { background: #c0392b; }
.kpi-snapshot-bar__dot--waiting { background: #1f4fd8; }

.kpi-snapshot-bar__msg {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.4;
}

.kpi-snapshot-bar__msg--error {
  width: 100%;
  margin-top: 8px;
  color: var(--accent-hover);
}

.kpi-snapshot-bar__actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.kpi-snapshot-bar--active {
  border-color: #b7dfc9;
  background: #f6fbf8;
}

.kpi-snapshot-bar--paused {
  border-color: #f1e4a8;
  background: #fffdf5;
}

.kpi-snapshot-bar--stopped {
  border-color: #f5c2c0;
  background: #fffafa;
}

.kpi-reminder-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 32px;
  font-size: 13px;
  line-height: 1.45;
  border-bottom: 1px solid var(--line);
}

.security-unlock-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px var(--content-pad-x);
  font-size: 14px;
  line-height: 1.45;
  border-bottom: 1px solid #f1e4a8;
  background: linear-gradient(180deg, #fffdf5 0%, #faf6eb 100%);
  color: var(--ink);
  flex-shrink: 0;
}

.security-unlock-banner p {
  margin: 4px 0 0;
  color: var(--ink-muted);
  font-size: 12px;
}

.security-unlock-banner__msg {
  color: #8b4513 !important;
  font-weight: 500;
}

.security-unlock-banner__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.security-unlock-banner__actions .field-input {
  min-width: 180px;
}

.kpi-reminder-banner[hidden] {
  display: none !important;
}

.kpi-reminder-banner__text p {
  margin: 4px 0 0;
  opacity: 0.92;
}

.kpi-reminder-banner__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.kpi-reminder-banner--start {
  background: #e8f5ee;
  color: #1e6b45;
  border-bottom-color: #b7dfc9;
}

.kpi-reminder-banner--stop {
  background: #fff8e6;
  color: #8a5a00;
  border-bottom-color: #f1e4a8;
}

/* —— Home dashboard —— */

.home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

.home-alert {
  margin-bottom: 16px;
}

.home-grid__controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.home-grid__modules {
  min-width: 0;
}

.home-unlock-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.home-unlock-row .field-input {
  flex: 1 1 200px;
  min-width: 0;
}

.home-unlock-status {
  margin: 8px 0 0;
}

.home-modules-title {
  margin-bottom: 4px;
}

.home-modules-desc {
  margin-bottom: 16px;
}

.home-panel-footer {
  margin: 14px 0 0;
  font-size: 13px;
}

#tokenForm .field-label {
  margin-top: 12px;
}

#tokenForm .field-input[type="file"] {
  padding: 10px;
}

@media (min-width: 1024px) {
  .home-grid {
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    gap: 24px 28px;
    align-items: start;
  }
}

@media (min-width: 1280px) {
  .home-grid {
    grid-template-columns: minmax(340px, 400px) minmax(0, 1fr);
    gap: 28px 36px;
  }
}

@media (min-width: 1440px) {
  .home-grid {
    grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  }
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

@media (min-width: 1024px) {
  .module-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .module-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1440px) {
  .module-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1680px) {
  .module-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

.module-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 18px;
  background: var(--paper-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: transform 0.25s var(--ease-out), border-color 0.2s, box-shadow 0.25s var(--ease-out);
  box-shadow: var(--shadow-soft);
}

.module-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-border);
  box-shadow: var(--shadow-panel);
}

.module-card:active {
  transform: translateY(-1px);
}

.module-card kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-muted);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 2px 6px;
  border-radius: 2px;
  width: fit-content;
}

.module-card strong {
  font-size: 15px;
  font-weight: 600;
}

.module-card span {
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.4;
}

/* —— KPI tiles (layout only; colors in palette blocks) —— */

.kpi-strip-scroll {
  overflow: visible;
  margin-bottom: 10px;
  flex-shrink: 0;
  width: 100%;
}

.kpi-strip-scroll .kpi-strip {
  margin-bottom: 0;
}

/* Phone / tablet: 4×2 compact grid — all 8 tiles visible, no horizontal scroll */
.kpi-strip.cols-8 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: 100%;
  max-width: 100%;
  gap: 6px;
  box-sizing: border-box;
}

.kpi-strip.cols-8 .kpi-tile {
  width: auto;
  min-width: 0;
  height: auto;
  min-height: 56px;
  padding: 5px 6px 5px 9px;
  box-sizing: border-box;
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.kpi-tile::before {
  width: 3px;
}

.kpi-palette-snapshot .kpi-title {
  font-size: 7px;
  line-height: 1.15;
  min-height: 0;
  max-height: 18px;
  margin-bottom: 2px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  letter-spacing: 0.04em;
}

.kpi-palette-snapshot .kpi-value {
  font-size: 12px;
  line-height: 1.1;
  font-weight: 600;
}

.kpi-palette-snapshot .kpi-count {
  font-size: 9px;
  margin-top: 1px;
  line-height: 1;
  opacity: 0.9;
}

@media (min-width: 769px) and (max-width: 1024px) {
  .kpi-strip.cols-8 .kpi-tile {
    min-height: 62px;
    padding: 6px 8px 6px 10px;
  }

  .kpi-palette-snapshot .kpi-title {
    font-size: 8px;
    max-height: 20px;
  }

  .kpi-palette-snapshot .kpi-value {
    font-size: 14px;
  }
}

@media (min-width: 1025px) {
  .kpi-strip.cols-8 {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 8px;
  }

  .kpi-strip.cols-8 .kpi-tile {
    min-height: 78px;
    height: 78px;
    padding: 8px 10px 8px 13px;
  }

  .kpi-tile::before {
    width: 4px;
  }

  .kpi-palette-snapshot .kpi-title {
    font-size: 9px;
    max-height: none;
    min-height: 22px;
    margin-bottom: 4px;
  }

  .kpi-palette-snapshot .kpi-value {
    font-size: clamp(15px, 1.2vw, 18px);
  }

  .kpi-palette-snapshot .kpi-count {
    font-size: 10px;
    margin-top: 2px;
  }

  .kpi-strip.cols-8 .kpi-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(26, 29, 35, 0.14);
  }
}

@media (max-width: 360px) {
  .kpi-strip.cols-8 {
    gap: 4px;
  }

  .kpi-strip.cols-8 .kpi-tile {
    min-height: 52px;
    padding: 4px 4px 4px 7px;
  }

  .kpi-palette-snapshot .kpi-title {
    font-size: 6px;
  }

  .kpi-palette-snapshot .kpi-value {
    font-size: 11px;
  }
}

.kpi-palette-snapshot .data-grid-wrap {
  min-height: 360px;
}

.kpi-palette-snapshot .data-grid-wrap .ht_master .wtHolder {
  font-size: 12px;
}

/* KPI log pages — fit grid to viewport, no horizontal scroll */

body.app-shell.kpi-palette-log {
  overflow-x: hidden;
}

body.app-shell.kpi-palette-log .app-main {
  min-width: 0;
  overflow-x: hidden;
}

body.app-shell.kpi-palette-log .app-content {
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  padding: 16px 24px 16px 20px;
  overflow-x: hidden;
}

.kpi-palette-log .page-head {
  margin-bottom: 14px;
}

.kpi-palette-log .data-grid-wrap {
  min-height: 360px;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.kpi-palette-log .data-grid-wrap .handsontable {
  width: 100% !important;
  font-size: 11px;
}

.kpi-palette-log .ht_master .wtHolder {
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

.kpi-palette-log .handsontable td {
  padding: 2px 3px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kpi-palette-log .handsontable th {
  padding: 4px 2px;
  line-height: 1.2;
  white-space: normal !important;
  vertical-align: middle;
  font-size: 10px;
}

.kpi-palette-log .handsontable th .colHeader {
  white-space: normal !important;
  line-height: 1.2;
  text-align: center;
}

.kpi-palette-log .ht_clone_top thead tr:first-child th {
  height: 26px;
  font-size: 11px;
}

.kpi-palette-log .ht_clone_top thead tr:last-child th {
  min-height: 36px;
  height: auto;
}

.kpi-strip.cols-6 .kpi-tile {
  flex: 1 1 calc(16.66% - 8px);
  min-width: 110px;
}

.kpi-tile {
  position: relative;
  padding: 10px 12px 10px 14px;
  border-radius: var(--radius-sm);
  text-align: left;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.kpi-tile::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: rgba(255, 255, 255, 0.35);
}

.kpi-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.92;
  margin-bottom: 4px;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.1;
}

.kpi-count {
  font-family: var(--font-mono);
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.88;
}

.kpi-tile {
  color: #fff;
}

/* Snapshot engines — original DS palette */
.kpi-palette-snapshot .white-bg {
  background: #eceae4;
  color: #1a1d23;
}
.kpi-palette-snapshot .white-bg::before {
  background: rgba(0, 0, 0, 0.12);
}
.kpi-palette-snapshot .red-bg {
  background: #c0392b;
}
.kpi-palette-snapshot .darkred-bg {
  background: #922b21;
}
.kpi-palette-snapshot .yellow-bg {
  background: #f1c40f;
  color: #1a1d23;
}
.kpi-palette-snapshot .green-bg {
  background: #27ae60;
}
.kpi-palette-snapshot .darkgreen-bg {
  background: #145a32;
}
.kpi-palette-snapshot .blue-bg {
  background: #1f4fd8;
}

/* KPI log grids — original log palette */
.kpi-palette-log .white-bg {
  background: #eceae4 !important;
  color: #1a1d23 !important;
}
.kpi-palette-log .red-bg {
  background: #c45757 !important;
  color: #fff !important;
}
.kpi-palette-log .darkred-bg {
  background: #8b2e2e !important;
  color: #fff !important;
}
.kpi-palette-log .yellow-bg {
  background: #e7ce69 !important;
  color: #1a1d23 !important;
}
.kpi-palette-log .green-bg {
  background: #4eaf77 !important;
  color: #fff !important;
}
.kpi-palette-log .darkgreen-bg {
  background: #017632 !important;
  color: #fff !important;
}
.kpi-palette-log .blue-bg {
  background: #617dc4 !important;
  color: #fff !important;
}

.kpi-palette-log .ht_clone_top thead th,
.kpi-palette-log .handsontable thead th {
  background: var(--engine-header-bg) !important;
  color: #e8e4dc !important;
  font-weight: 600 !important;
  border-color: #3d4656 !important;
}

/* —— Scrollbars (hidden site-wide, scroll still works) —— */

*,
html,
body {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar,
html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
  background: transparent;
}

/* —— React data grid (virtualized) —— */

.react-grid-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  background: var(--paper-elevated);
  overflow: hidden;
}

.react-grid-scroller {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.react-grid-table {
  display: flex;
  flex-direction: column;
  min-width: 100%;
  width: max-content;
  min-height: 100%;
}

.react-grid-head {
  display: grid;
  grid-template-columns: var(--react-cols);
  width: max-content;
  min-width: 100%;
  flex-shrink: 0;
  background: var(--engine-header-bg, #0b2b33);
  color: #e8e4dc;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  position: sticky;
  top: 0;
  z-index: 2;
}

.react-grid-head-cell {
  padding: 10px 8px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  box-sizing: border-box;
}

.react-grid-head-text {
  display: block;
  white-space: nowrap;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.react-grid-head-cell:first-child {
  justify-content: flex-start;
  padding-left: 10px;
}

.react-grid-head-cell:last-child {
  border-right: none;
}

.react-grid-body {
  overflow-y: auto;
  overflow-x: visible;
  flex: 1;
  min-height: 200px;
  width: max-content;
  min-width: 100%;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.35;
  -webkit-overflow-scrolling: touch;
}

.react-grid-virtual-spacer {
  position: relative;
  width: max-content;
  min-width: 100%;
}

.react-grid-row {
  position: absolute;
  left: 0;
  width: max-content;
  min-width: 100%;
  display: grid;
  grid-template-columns: var(--react-cols);
  height: 30px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  transition: background 0.12s ease;
  box-sizing: border-box;
}

.react-grid-row:hover {
  background: var(--accent-soft) !important;
}

.react-grid-row:nth-child(even) {
  background: var(--grid-row-alt);
}

.react-grid-cell {
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 12px;
  box-sizing: border-box;
}

.react-grid-cell:first-child {
  text-align: left;
  padding-left: 10px;
  font-weight: 500;
}

.react-grid-cell--num {
  font-variant-numeric: tabular-nums;
}

.react-grid-scroll-hint {
  flex-shrink: 0;
  margin: 0;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--ink-muted);
  text-align: center;
  background: var(--paper);
  border-top: 1px solid var(--line);
}

/* Wide screens — stretch columns to full width (no horizontal scroll) */
.react-grid-wrap--fluid .react-grid-scroller {
  overflow-x: hidden;
}

.react-grid-wrap--fluid .react-grid-table,
.react-grid-wrap--fluid .react-grid-head,
.react-grid-wrap--fluid .react-grid-body,
.react-grid-wrap--fluid .react-grid-virtual-spacer,
.react-grid-wrap--fluid .react-grid-row,
.react-grid-wrap--fluid .react-kpi-log-head-group {
  width: 100%;
  max-width: 100%;
}

.react-grid-wrap--fluid .react-grid-head-cell {
  min-height: 38px;
  padding: 6px 4px;
}

.react-grid-wrap--fluid .react-grid-head-text {
  white-space: normal;
  line-height: 1.15;
  font-size: 10px;
}

.react-grid-wrap--fluid .react-grid-head-cell--scrip .react-grid-head-text,
.react-grid-wrap--fluid .react-kpi-log-head .react-grid-head-cell--meta .react-grid-head-text {
  white-space: nowrap;
  font-size: 11px;
}

.react-kpi-log-head {
  flex-shrink: 0;
}

.react-kpi-log-head-group {
  display: grid;
  grid-template-columns: var(--react-cols);
  width: max-content;
  min-width: 100%;
  background: #1a2030;
  color: #e8e4dc;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.react-kpi-log-head-spacer {
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 28px;
}

.react-kpi-log-head-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 28px;
  white-space: nowrap;
}

/* —— Data grid shell (legacy Handsontable) —— */

.data-grid-wrap {
  background: var(--paper-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 2px;
  overflow: hidden;
}

.data-grid-wrap .handsontable {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* —— Current OHLC —— */

.ohlc-grid {
  display: grid;
  gap: clamp(16px, 2.5vw, 24px);
  grid-template-columns: 1fr;
}

.ohlc-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(16px, 2.5vw, 20px) clamp(14px, 2vw, 18px) clamp(14px, 2vw, 18px);
}

.ohlc-grid .ohlc-panel:nth-child(2) {
  animation-delay: 0.08s;
}

.ohlc-section-title {
  margin: 0 0 10px;
  padding: 0 2px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.ohlc-table-wrap {
  flex: 1;
  min-height: 0;
  max-height: min(68vh, 680px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
}

.ohlc-table-wrap .data-table {
  table-layout: fixed;
}

.ohlc-table-wrap .data-table col.col-scrip {
  width: 28%;
}

.ohlc-table-wrap .data-table col.col-date {
  width: 18%;
}

.ohlc-table-wrap .data-table thead th {
  z-index: 1;
  padding: 9px 10px;
}

.ohlc-table-wrap .data-table td {
  padding: 7px 10px;
}

.ohlc-table-wrap .data-table thead th:first-child,
.ohlc-table-wrap .data-table td:first-child {
  text-align: left;
  padding-left: 12px;
  letter-spacing: normal;
  text-transform: none;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
}

.ohlc-table-wrap .data-table td:first-child {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 12px;
}

.ohlc-table-wrap .data-table thead th:not(:first-child):not(:last-child),
.ohlc-table-wrap .data-table td:not(:first-child):not(:last-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ohlc-table-wrap .data-table thead th:last-child,
.ohlc-table-wrap .data-table td:last-child {
  text-align: left;
  padding-right: 12px;
  letter-spacing: normal;
  text-transform: none;
}

@media (min-width: 1100px) {
  .ohlc-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }
}

@media (min-width: 1500px) {
  .ohlc-table-wrap {
    max-height: min(72vh, 760px);
  }
}

.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper-elevated);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 8px 12px;
  text-align: right;
  border-bottom: 1px solid var(--line);
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--engine-header-bg, #0b2b33);
  color: #e8e4dc;
  font-weight: 600;
  font-family: var(--font-sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.data-table tbody tr:hover {
  background: var(--accent-soft);
}

/* —— Responsive shell (tablet & phone) —— */

@media (max-width: 1024px) {
  .app-topbar {
    display: flex;
  }

  .sidebar-backdrop {
    display: block;
  }

  .app-sidebar {
    top: 0;
    padding-top: env(safe-area-inset-top);
    transform: translateX(-105%);
  }

  body.nav-open .app-sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.35);
  }

  .brand--sidebar {
    display: block;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .app-main {
    margin-left: 0;
    padding-top: var(--topbar-h);
  }

  .live-feed-banner,
  .kpi-reminder-banner {
    padding-left: var(--content-pad-x);
    padding-right: var(--content-pad-x);
  }

  .security-unlock-banner {
    padding: 14px var(--content-pad-x);
    flex-direction: column;
    align-items: stretch;
  }

  .security-unlock-banner__actions {
    width: 100%;
  }

  .security-unlock-banner__actions .field-input {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 768px) {
  .module-grid {
    grid-template-columns: 1fr;
  }

  .kpi-snapshot-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .kpi-snapshot-bar__actions {
    width: 100%;
  }

  .kpi-snapshot-bar__actions .btn {
    flex: 1;
  }
}

@media (max-width: 480px) {
  :root {
    --content-pad-x: 14px;
  }

  .page-sub {
    font-size: 13px;
  }

  .toolbar {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .toolbar .btn {
    width: auto;
    flex-shrink: 0;
  }
}

@media (min-width: 1025px) {
  .app-topbar {
    display: none !important;
  }

  .app-sidebar {
    transform: none !important;
  }

  .brand--sidebar {
    display: block;
  }
}

/* —— Theme toggle —— */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  color: var(--sidebar-text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s var(--ease-out), border-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-active);
  border-color: rgba(241, 76, 35, 0.45);
}

.theme-toggle--compact {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-color: var(--line);
  background: var(--paper-elevated);
  color: var(--ink);
}

.theme-toggle--compact:hover {
  border-color: var(--accent);
  background: var(--paper-elevated);
  color: var(--accent);
}

.theme-toggle__icon {
  font-size: 16px;
  line-height: 1;
}

/* —— Dark mode (main content) —— */

[data-theme="dark"] {
  color-scheme: dark;
}

[data-theme="dark"] body.app-shell {
  --ink: #f0f4f5;
  --ink-muted: #8fa8b0;
  --paper: #0b2b33;
  --paper-elevated: #123640;
  --line: rgba(255, 255, 255, 0.12);
  --topbar-bg: rgba(11, 43, 51, 0.96);
  --grid-row-alt: rgba(255, 255, 255, 0.04);
  --engine-header-bg: #071f25;
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.25), 0 12px 32px rgba(0, 0, 0, 0.28);
  --shadow-panel: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 16px 40px rgba(0, 0, 0, 0.3);
  --accent-soft: rgba(241, 76, 35, 0.2);
}

[data-theme="dark"] body.app-shell {
  background:
    radial-gradient(ellipse 120% 80% at 100% -20%, rgba(241, 76, 35, 0.1), transparent 50%),
    radial-gradient(ellipse 80% 60% at -10% 100%, rgba(70, 123, 89, 0.1), transparent 45%),
    var(--paper);
}

[data-theme="dark"] .module-card {
  background: var(--paper-elevated);
}

[data-theme="dark"] .module-card:hover {
  border-color: rgba(241, 166, 121, 0.35);
}

[data-theme="dark"] .react-kpi-log-grid .react-grid-body .react-grid-row:nth-child(even) .react-grid-cell:not(.kpi-log-cell) {
  background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .react-skeleton-strip .react-skeleton-tile,
[data-theme="dark"] .react-skeleton-grid {
  background: linear-gradient(90deg, #163640 25%, #1e4550 50%, #163640 75%);
  background-size: 200% 100%;
}

[data-theme="dark"] .react-skeleton-line {
  background: #163640;
}

[data-theme="dark"] .kpi-log-sheet {
  background: var(--paper-elevated);
}

[data-theme="dark"] .time-picker__select,
[data-theme="dark"] .kpi-log-date-input,
[data-theme="dark"] .time-picker__panel {
  background: #163640;
  color: var(--ink);
  border-color: var(--line);
}

[data-theme="dark"] .kpi-log-chip {
  background: var(--paper-elevated);
}

[data-theme="dark"] .kpi-log-chip:hover {
  background: #163640;
}

[data-theme="dark"] .security-unlock-banner,
[data-theme="dark"] .live-feed-banner,
[data-theme="dark"] .kpi-reminder-banner {
  background: var(--paper-elevated);
  border-color: var(--line);
}

[data-theme="dark"] .kpi-snapshot-bar--active {
  border-color: rgba(70, 123, 89, 0.45);
  background: rgba(70, 123, 89, 0.16);
}

[data-theme="dark"] .kpi-snapshot-bar--paused {
  border-color: rgba(241, 166, 121, 0.45);
  background: rgba(241, 166, 121, 0.12);
}

[data-theme="dark"] .kpi-snapshot-bar--stopped {
  border-color: rgba(241, 76, 35, 0.4);
  background: rgba(241, 76, 35, 0.12);
}

[data-theme="dark"] .kpi-snapshot-bar__info strong {
  color: var(--ink);
}

[data-theme="dark"] .kpi-snapshot-bar__msg {
  color: var(--ink-muted);
}

[data-theme="dark"] .kpi-event--start {
  background: rgba(70, 123, 89, 0.28);
  color: #b8e6c8;
}

[data-theme="dark"] .kpi-event--stop {
  background: rgba(241, 76, 35, 0.28);
  color: #ffc4b5;
}

[data-theme="dark"] .kpi-trigger--auto {
  background: rgba(143, 168, 176, 0.22);
  color: #c8dce2;
}

[data-theme="dark"] .kpi-trigger--manual {
  background: rgba(241, 166, 121, 0.22);
  color: #ffe0c8;
}

[data-theme="dark"] .data-table tbody td {
  color: var(--ink);
}
