/* Predecision Dashboard — White + Dark mixed theme
   Fonts: Nunito (headings), Montserrat (highlights), Google Sans (body)
   Dark sidebar + dark hero cards, white main area and white content cards.
*/

/* Author display rules (flex/grid) can override the UA [hidden] style,
   so keep hidden elements hidden explicitly. */
[hidden] { display: none !important; }

:root {
  /* Dark accent surfaces */
  --sidebar: #1e1b4b;
  --sidebar-hover: #312e81;
  --sidebar-text: #f8fafc;
  --sidebar-text-muted: #a5b4fc;

  /* Light main area */
  --bg: #f1f5f9;
  --panel: #ffffff;
  --panel-hover: #f8fafc;
  --border: #e2e8f0;

  /* Text */
  --text: #0f172a;
  --text-muted: #64748b;

  /* Accent */
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: #eef2ff;

  /* Status */
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --class-a: #6366f1;
  --class-b: #16a34a;
  --class-c: #dc2626;
  --class-d: #d97706;

  /* Fonts */
  --font-heading: "Nunito", sans-serif;
  --font-body: "Google Sans", sans-serif;
  --font-highlight: "Montserrat", sans-serif;
}

/* Reset */
* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 18px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }

/* ---------- App Layout ---------- */
.app {
  display: flex;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar (dark) ---------- */
.sidebar {
  width: 250px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  z-index: 50;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 24px 20px 24px;
}

.sidebar-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  background: #ffffff;
  padding: 3px;
}

.sidebar-brand-text {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--sidebar-text);
  letter-spacing: -0.5px;
}

.sidebar-nav {
  flex: 1;
  padding: 20px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 11px 24px;
  color: var(--sidebar-text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  background: transparent;
  text-align: left;
  transition: all 0.2s;
  position: relative;
}

.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-text);
}

.nav-item.active {
  background: rgba(255,255,255,0.08);
  color: #ffffff;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 22px;
  background: #a5b4fc;
  border-radius: 0 4px 4px 0;
}

.nav-item .nav-icon {
  font-size: 1.15rem;
  width: 24px;
  text-align: center;
}

.sidebar-spacer { flex: 1; }

.sidebar-bottom {
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-version {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-text-muted);
  font-weight: 700;
  margin-top: 8px;
  display: block;
}

/* ---------- Main Content (light) ---------- */
.main-content {
  flex: 1;
  background: var(--bg);
  overflow-y: auto;
  position: relative;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.page-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
}

.page-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--sidebar);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-highlight);
}

.user-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ---------- Views ---------- */
.view {
  display: none;
  padding: 28px 32px;
  max-width: 1400px;
  margin: 0 auto;
}

.view.active { display: block; }

/* ---------- Hero Metric Row (dark gradient mix) ---------- */
.hero-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 20px 24px;
  box-shadow: 0 10px 30px -12px rgba(37, 33, 99, 0.45);
  color: #ffffff;
}

.metric-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #c7d2fe;
  font-weight: 700;
  margin-bottom: 8px;
  font-family: var(--font-highlight);
}

.metric-value {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.1;
}

.metric-delta {
  font-size: 0.8rem;
  color: #c7d2fe;
  margin-top: 6px;
  font-family: var(--font-body);
}

.metric-value-sm {
  font-size: 1.4rem;
  line-height: 1.3;
  overflow-wrap: break-word;
}

/* ---------- KPI Grid (white cards) ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.kpi-icon {
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.kpi-value {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
}

.kpi-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  font-family: var(--font-highlight);
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-body);
}

.kpi-card.kpi-adaptability { border-top: 3px solid var(--accent); }
.kpi-card.kpi-omb { border-top: 3px solid var(--warning); }
.kpi-card.kpi-class { border-top: 3px solid var(--class-a); }
.kpi-card.kpi-flex { border-top: 3px solid var(--success); }

/* ---------- Content Grid ---------- */
.content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  align-items: start;
}

.left-column { display: flex; flex-direction: column; gap: 20px; }
.right-column { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Section Cards (white) ---------- */
.section-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.section-header h3 {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

.section-header .section-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search-input {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--font-body);
  width: 160px;
}

.search-input:focus { outline: none; border-color: var(--accent); }

/* Buttons */
.btn {
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.85rem;
  transition: all 0.2s;
  font-family: var(--font-body);
  white-space: nowrap;
}

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

.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }

.btn-small {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* Level pill */
.level-pill {
  font-family: var(--font-highlight);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid #c7d2fe;
  color: var(--accent-hover);
}

/* Class badge */
.class-badge {
  font-family: var(--font-highlight);
  font-size: 0.8rem;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--border);
}

.class-badge.a { border-color: var(--class-a); color: var(--class-a); }
.class-badge.b { border-color: var(--class-b); color: var(--class-b); }
.class-badge.c { border-color: var(--class-c); color: var(--class-c); }
.class-badge.d { border-color: var(--class-d); color: var(--class-d); }

/* Flex detail */
.flex-detail { padding: 18px 22px; }

.detail-row {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-family: var(--font-body);
}

.detail-label {
  min-width: 110px;
  color: var(--text-muted);
  font-weight: 700;
  font-family: var(--font-highlight);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-value {
  flex: 1;
  color: var(--text);
  line-height: 1.45;
}

.tell-tale-section { padding: 0 22px 16px 22px; }

.tell-tale-section h4 {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.tell-tale-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tell-tale-section li {
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 6px;
  padding-left: 18px;
  position: relative;
  font-family: var(--font-body);
  font-style: italic;
}

.tell-tale-section li::before {
  content: "“";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
  font-style: normal;
}

.flex-footer { padding: 0 22px 18px 22px; }
.flex-footer p {
  font-size: 0.88rem;
  color: var(--text);
  margin-bottom: 6px;
  font-family: var(--font-body);
}

.flex-footer p strong { color: var(--text-muted); font-family: var(--font-highlight); font-size: 0.8rem; }

/* Callouts */
.callout {
  padding: 12px 16px;
  border-radius: 10px;
  margin: 14px 22px 22px 22px;
  font-size: 0.88rem;
  font-family: var(--font-body);
}

.callout.info {
  background: var(--accent-soft);
  border: 1px solid #c7d2fe;
  color: #3730a3;
}

.callout.warning {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

/* TF Grid */
.tf-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding: 18px 22px;
}

.tf-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tf-item.full { grid-column: span 2; }

.tf-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  font-family: var(--font-highlight);
}

.tf-value {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 700;
  font-family: var(--font-body);
}

.tf-tag {
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  font-family: var(--font-highlight);
  width: fit-content;
}

.tf-tag.reversible { background: #dcfce7; color: var(--success); }
.tf-tag.irreversible { background: #fee2e2; color: var(--danger); }
.tf-tag.reversible_exposure { background: #dcfce7; color: var(--success); }
.tf-tag.reversible_big_mistake { background: #fef3c7; color: var(--warning); }
.tf-tag.reversible_cost_everything { background: #fee2e2; color: var(--danger); }

/* DHT */
.section-note {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding: 0 22px;
  font-family: var(--font-body);
}

.badge.small {
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-weight: 700;
  font-family: var(--font-highlight);
}

.dht-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 22px 22px 22px;
}

.dht-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  animation: fadeIn 0.4s ease;
}

.dht-rank {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--sidebar);
  color: #ffffff;
  font-family: var(--font-highlight);
  font-weight: 900;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dht-content { flex: 1; }

.dht-decision {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.9rem;
  margin-bottom: 3px;
  color: var(--text);
}

.dht-category {
  font-family: var(--font-highlight);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-hover);
  margin-bottom: 2px;
}

.dht-likelihood {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--text-muted);
  font-family: var(--font-highlight);
}

.dht-rationale {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 3px;
  font-family: var(--font-body);
}

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

/* Chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 18px 22px 22px 22px;
}

.chip {
  padding: 9px 15px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--font-highlight);
  color: var(--text);
  cursor: help;
  transition: all 0.2s;
}

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

/* Activity List */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 12px 22px 18px 22px;
}

.activity-item {
  display: flex;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.activity-item:last-child { border-bottom: none; }

.activity-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--sidebar);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-highlight);
  flex-shrink: 0;
}

.activity-content { flex: 1; }

.activity-name {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 2px;
}

.activity-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-family: var(--font-body);
  line-height: 1.4;
}

.activity-meta {
  display: flex;
  gap: 12px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-highlight);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 40vh;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon { font-size: 3rem; margin-bottom: 16px; }

.empty-state h3 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px -10px rgba(15,23,42,0.35);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  padding: 4px;
  line-height: 1;
}

.modal-form {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }

.field label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-highlight);
}

.field label .req { color: var(--danger); margin-left: 4px; }

textarea, input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font-body);
}

textarea { min-height: 80px; resize: vertical; }

textarea:focus, input[type="text"]:focus { outline: none; border-color: var(--accent); }

select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font-body);
}

select:focus { outline: none; border-color: var(--accent); }

.level-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.level-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text-muted);
  font-family: var(--font-highlight);
  font-weight: 800;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

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

.level-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

.level-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-body);
}

.field-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-body);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* ==========================================================================
   Prototype components — transition-aware context layer
   ========================================================================== */

.profile-select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  max-width: 260px;
  min-width: 150px;
  flex: 1 1 150px;
}

.profile-select:focus { outline: none; border-color: var(--accent); }

.status-badge {
  display: inline-block;
  font-family: var(--font-highlight);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-badge.stable { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.status-badge.pending { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.status-badge.review { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.status-badge.recorded { background: #e0e7ff; color: #4338ca; border-color: #c7d2fe; }
.status-badge.hypothesis { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }

.hypothesis-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 22px 4px;
}

.hypothesis-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.hypothesis-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.hypothesis-title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.35;
}

.hypothesis-principle {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
  padding-left: 14px;
  position: relative;
}

.hypothesis-principle::before {
  content: "↳";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 800;
}

.hypothesis-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 22px 22px;
  flex-wrap: wrap;
}

.generation-meta {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-family: var(--font-body);
  line-height: 1.45;
  flex: 1;
  min-width: 200px;
}

.generation-meta.warn {
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  padding: 8px 10px;
  border-radius: 8px;
}

.log-list {
  display: flex;
  flex-direction: column;
  padding: 6px 22px 18px;
}

.log-item {
  display: flex;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
  flex-wrap: wrap;
}

.log-item:last-child { border-bottom: none; }

.log-time {
  font-family: var(--font-highlight);
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 118px;
  font-weight: 700;
}

.log-text {
  font-size: 0.84rem;
  color: var(--text);
  flex: 1;
  min-width: 180px;
}

.log-text .muted { color: var(--text-muted); }

.log-event { margin-left: auto; }

.empty-mini {
  padding: 14px 22px 20px;
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.control-form {
  padding: 16px 22px 4px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-title {
  font-family: var(--font-highlight);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 800;
}

.control-form .field { margin-bottom: 0; }

.control-form .level-btn {
  width: 36px;
  height: 36px;
  font-size: 0.92rem;
  border-radius: 7px;
}

.control-actions {
  display: flex;
  justify-content: flex-end;
  padding-bottom: 14px;
}

.rule-list {
  list-style: none;
  padding: 8px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rule-list li {
  font-size: 0.82rem;
  color: var(--text);
  padding-left: 18px;
  position: relative;
  line-height: 1.45;
}

.rule-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 800;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  padding: 0 22px 22px;
}

.profile-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-card h4 {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.profile-card p {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.profile-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 8px;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 22px 22px;
}

.event-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--bg);
}

.event-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.event-title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--text);
}

.event-reason {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.event-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-highlight);
  margin-top: 8px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

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

.settings-body {
  padding: 16px 22px 22px;
  font-size: 0.85rem;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.5;
}

.settings-body code,
.code-list code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.78rem;
}

.code-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.82rem;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 8px;
  font-size: 0.82rem;
}

.settings-row:last-child { border-bottom: none; }

.settings-row .label {
  color: var(--text-muted);
  font-family: var(--font-highlight);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.settings-row .value {
  font-weight: 700;
  text-align: right;
  overflow-wrap: anywhere;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.switch {
  appearance: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background 0.2s;
  cursor: pointer;
  flex-shrink: 0;
  border: none;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
}

.switch:checked { background: var(--accent); }
.switch:checked::after { left: 21px; }

.form-error {
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  margin: -4px 0 14px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  max-width: 380px;
  background: #0f172a;
  color: #f8fafc;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 16px 40px -12px rgba(15, 23, 42, 0.5);
  font-size: 0.84rem;
  font-family: var(--font-body);
  line-height: 1.45;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.toast.show { opacity: 1; transform: none; }
.toast.error { background: #7f1d1d; }
.toast.warn { background: #78350f; }
.toast.success { background: #14532d; }

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

.event-status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- Chat widget ---------- */
.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 150;
  font-family: var(--font-body);
}

.chat-toggle {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 8px 24px -6px rgba(99, 102, 241, 0.45);
  transition: transform 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-toggle:hover { background: var(--accent-hover); transform: rotate(-15deg); }

.chat-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 360px;
  height: 520px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px -12px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlide 0.22s ease-out;
}

@keyframes chatSlide {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.chat-title {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
}

.chat-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.chat-close:hover { color: var(--text); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}

.chat-message {
  display: flex;
  gap: 10px;
  max-width: 88%;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.chat-user { align-self: flex-end; flex-direction: row-reverse; }
.chat-assistant { align-self: flex-start; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--text);
}

.chat-user .chat-bubble {
  background: var(--accent);
  color: #ffffff;
  border-bottom-right-radius: 2px;
}

.chat-assistant .chat-bubble {
  background: #ffffff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.chat-input-row input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.86rem;
  outline: none;
}

.chat-input-row input:focus { border-color: var(--accent); }

.chat-send {
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
}

.chat-send:hover { background: var(--accent-hover); }
.chat-send:disabled { opacity: 0.6; cursor: not-allowed; }

/* Responsive */
@media (max-width: 1100px) {
  .content-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .hero-metrics, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .app { flex-direction: column; height: auto; }
  .sidebar { width: 100%; height: auto; }
  .sidebar-nav { display: flex; padding: 12px; overflow-x: auto; }
  .nav-item { padding: 10px 16px; font-size: 0.8rem; white-space: nowrap; }
  .nav-item.active::before { display: none; }
  .main-content { height: auto; overflow: visible; }
  .top-bar { position: static; }
  .view { padding: 20px; }
  .tf-grid { grid-template-columns: 1fr; }
  .tf-item.full { grid-column: span 1; }
}

@media (max-width: 640px) {
  .hero-metrics, .kpi-grid { grid-template-columns: 1fr; }
}