/* Instar — Minimal dark theme, monospace accents, terminal aesthetic */

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #111111;
  --bg-tertiary: #1a1a1a;
  --bg-hover: #222222;
  --border: #2a2a2a;
  --border-focus: #444444;
  --text-primary: #e0e0e0;
  --text-secondary: #888888;
  --text-muted: #6b6b6b;
  --accent: #00ff88;
  --accent-dim: #00cc6a;
  --danger: #ff4444;
  --warning: #ffaa00;
  --info: #4488ff;
  --success: #00ff88;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 6px;
}

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

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

a { 
  color: var(--accent); 
  text-decoration: none; 
  transition: color 0.2s ease, text-shadow 0.2s ease; 
}
a:hover { 
  color: var(--accent-dim); 
  text-shadow: 0 0 8px rgba(0, 255, 136, 0.4); 
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: 9999;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
  width: auto;
  height: auto;
  overflow: visible;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 14px;
  text-decoration: none;
}

/* Layout */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary); 
}
::-webkit-scrollbar-thumb {
  background: var(--border-focus);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.app {
  display: flex;
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  text-shadow: 0 0 12px rgba(0, 255, 136, 0.4);
}

.sidebar-logo span { color: var(--text-muted); font-weight: 400; font-size: 11px; display: block; }

.nav-link {
  display: block;
  padding: 8px 20px;
  color: var(--text-secondary);
  font-size: 14px;
  transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  text-align: left;
  width: calc(100% - 24px);
  border-left: 3px solid transparent;
  margin: 2px 12px;
  border-radius: var(--radius);
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  text-decoration: none;
  transform: translateX(2px);
}

.nav-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--bg-tertiary);
  font-weight: 500;
}

.main {
  margin-left: 220px;
  flex: 1;
  min-width: 0;
  padding: 30px;
  width: 100%;
  /* Keeps long dashboard pages cheaper to scroll (layout + paint isolation). */
  contain: layout paint;
}

/* Page header */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  border-color: var(--border-focus);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Dashboard: compact metrics + wide connection panels + full-width RPC card */
.card.card-rpc-health {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.card.card-rpc-health .card-title {
  margin-bottom: 8px;
}

.dash-rpc-health-badges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 10px;
  align-items: stretch;
  margin-top: 0;
}

.dash-rpc-health-badges .badge {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: var(--radius);
  box-sizing: border-box;
}

.dash-rpc-health-badges .dash-rpc-health-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 8px 0;
}

.dash-stats-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.dash-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 8px;
}

.dash-metrics-grid .stat-card--metric {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
}

.dash-metrics-grid .stat-card--metric .stat-label {
  font-size: 10px;
  margin-bottom: 2px;
  line-height: 1.2;
}

.dash-metrics-grid .stat-card--metric .dash-metric-hint {
  display: block;
  font-size: 10px;
  line-height: 1.25;
  margin-top: 2px;
}

/* Build tile: explicit date / time lines so narrow columns don’t wrap one long locale string awkwardly */
.dash-build-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
}

.dash-build-sep {
  color: var(--text-muted);
}

.dash-metrics-grid .stat-card--metric .stat-card--metric-value {
  font-size: 1rem;
  margin-top: auto;
  line-height: 1.2;
}

/* Compound scheduler label (e.g. "13 / 14 enabled") — keep small vs numeric tiles */
.dash-metrics-grid .stat-card--metric .stat-card--metric-value.dash-metric-scheduler-value {
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.2;
  word-break: break-word;
  letter-spacing: -0.01em;
}
.dash-metrics-grid .stat-card--metric .dash-metric-hint--scheduler {
  font-size: 10px;
  margin-top: 2px;
}

/* Simple one-line metrics: larger value text */
.dash-metrics-grid .stat-card--metric .stat-card--metric-value.dash-metric-value-lg {
  font-size: 1.48rem;
  line-height: 1.12;
  font-weight: 700;
}

.dash-metrics-grid .stat-card--metric .stat-card--metric-balance {
  font-size: 0.85rem;
  margin-top: auto;
  font-family: var(--mono);
  font-weight: 700;
  line-height: 1.2;
}

.dash-balance-hint {
  display: block;
  margin-top: 2px;
  margin-bottom: 2px;
  font-size: 10px;
  line-height: 1.35;
  max-width: 14rem;
  min-height: 0;
}

.dash-metrics-grid .stat-card--metric .dash-metric-refresh {
  margin-top: 4px;
  align-self: flex-start;
  font-size: 10px;
  padding: 3px 8px;
}

.dash-connections-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.dash-connections-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 100%;
}

.dash-webchat-panel {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.dash-quick-actions-card .dash-quick-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

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

.stat-card--panel {
  padding: 14px 16px;
  min-height: 0;
}

/* Dashboard wallet glance: keep tile short; full address on hover + copy */
.stat-card--panel--dash-wallet .dash-mono-grow {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: normal;
  line-height: 1.35;
}

.stat-card--panel--dash-wallet .dash-wallet-ens {
  font-size: 0.82rem;
  margin: 2px 0 4px;
}

.dash-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.dash-panel-row--tight {
  margin-top: 4px;
}

.dash-mono-inline {
  font-family: var(--mono);
  font-size: 12px;
}

.dash-mono-grow {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 11px;
  word-break: break-all;
  line-height: 1.35;
}

.dash-panel-btn {
  margin-top: 8px;
  font-size: 11px;
}

.dash-webchat-url-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.dash-url-label {
  margin-bottom: 6px;
  margin-top: 0;
}

.dash-webchat-url-section .dash-url-label:not(:first-child) {
  margin-top: 12px;
}

.dash-url-code {
  display: block;
  font-size: 12px;
  font-family: var(--mono);
  word-break: break-all;
  user-select: all;
  margin-bottom: 8px;
  line-height: 1.4;
  color: var(--text-primary);
}

.dash-url-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.dash-wallet-ens {
  font-size: 1rem;
  font-weight: 600;
  margin: 4px 0 2px;
}

/* Stats grid (other pages) */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-focus);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-value.accent { color: var(--accent); }
.stat-value.warning { color: var(--warning); }

/* Utilities */
.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

.text-muted { color: var(--text-muted); font-size: 12px; }
.stat-card small.text-muted { display: block; margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; max-width: 100%; }

.identity-page-tagline {
  max-width: 36rem;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.portfolio-add-merge-hint {
  font-size: 12px;
  line-height: 1.4;
  margin: 0 0 10px;
}

/* Wallet page: balances + limits side by side; snapshots/metrics below full width */
.wallet-page-tagline {
  max-width: 40rem;
}
.wallet-summary-grid {
  margin-bottom: 20px;
}
.wallet-stat-address .stat-value.wallet-address-value {
  font-size: 11px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  word-break: break-all;
}
.wallet-address-code {
  flex: 1;
  min-width: 0;
  font-size: 10px;
}
.wallet-qr-btn {
  margin-top: 8px;
  font-size: 11px;
}
.wallet-qr-wrap {
  margin-top: 8px;
  text-align: center;
}
.wallet-body-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.wallet-balances-limits-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}
@media (max-width: 720px) {
  .wallet-balances-limits-row {
    grid-template-columns: 1fr;
  }
}
.wallet-body-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.wallet-card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.wallet-card-hint {
  margin: 0 0 10px 0;
  font-size: 12px;
}
.wallet-limits-card .form-group:last-of-type {
  margin-bottom: 12px;
}

/* Portfolio holdings / watchlist / overlap: center body cells; keep header row left-aligned */
table.portfolio-table {
  width: 100%;
  border-collapse: collapse;
}
table.portfolio-table th {
  text-align: left;
  vertical-align: bottom;
}
table.portfolio-table tr:not(:first-child) td {
  text-align: center;
  vertical-align: middle;
}
table.portfolio-table tr:not(:first-child) td:last-child {
  text-align: center;
}

/* Sortable portfolio headers — click to sort (client-side); keeps same table layout. */
table.portfolio-table th.pf-sortable {
  text-align: left;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s ease;
}
table.portfolio-table th.pf-sortable:hover {
  color: var(--text-primary);
}
table.portfolio-table th.pf-sortable.pf-sorted-asc::after {
  content: " \2191";
  opacity: 0.65;
  font-size: 0.82em;
}
table.portfolio-table th.pf-sortable.pf-sorted-desc::after {
  content: " \2193";
  opacity: 0.65;
  font-size: 0.82em;
}

/* Book (profile) card: compact row layout (full content width on wide viewports) */
.portfolio-book-card {
  max-width: 100%;
  margin-bottom: 14px;
}
.portfolio-book-grid .form-group {
  margin-bottom: 6px;
}
.portfolio-book-row-full label {
  margin-bottom: 4px;
}
.portfolio-book-all-msg {
  margin: 0 0 4px;
  font-size: 12px;
  line-height: 1.4;
}
.portfolio-book-inline-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 18px;
  align-items: start;
}
.portfolio-book-inline-2 .form-group {
  margin-bottom: 0;
}
.portfolio-book-inline-2 .form-group label {
  display: block;
  margin-bottom: 6px;
  min-height: 1.25em;
}
.portfolio-book-inline-2 .portfolio-book-field-hint {
  margin-top: 6px;
}
.portfolio-book-field-hint {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.35;
}
.portfolio-book-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px 14px;
  margin-top: 10px;
}
.portfolio-book-digest {
  margin: 0;
  font-size: 12px;
  font-weight: normal;
  line-height: 1.4;
  min-width: 0;
}
@media (max-width: 560px) {
  .portfolio-book-inline-2 {
    grid-template-columns: 1fr;
  }
}

/* Add position + watchlist: two columns on wide viewports */
.portfolio-add-wl-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 14px;
  align-items: start;
}
.portfolio-add-wl-grid .portfolio-add-card,
.portfolio-add-wl-grid .portfolio-watchlist-card {
  max-width: none;
  min-width: 0;
}
.portfolio-add-card {
  min-width: 0;
}
.portfolio-watchlist-add {
  margin-top: 10px;
}
.portfolio-watchlist-add-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}
.portfolio-wl-input-ticker {
  max-width: 8rem;
}
.portfolio-wl-input-name {
  max-width: 12rem;
}
@media (max-width: 960px) {
  .portfolio-add-wl-grid {
    grid-template-columns: 1fr;
  }
}

/* Overlap table: tighter typography; card does not span full page width */
.portfolio-overlap-card {
  max-width: 100%;
}
.portfolio-overlap-hint {
  margin: 0 0 8px;
  font-size: 11px;
  line-height: 1.35;
}
.portfolio-overlap-card .table-wrap {
  margin: 0;
}
.portfolio-overlap-card table.portfolio-table {
  font-size: 12px;
}
.portfolio-overlap-card table.portfolio-table th,
.portfolio-overlap-card table.portfolio-table td {
  padding: 6px 8px;
}
.portfolio-overlap-books {
  font-size: 11px;
  line-height: 1.35;
  max-width: 14rem;
}

/* Watchlist card: use available width (add/watchlist grid still caps column ratio) */
.portfolio-watchlist-card {
  max-width: 100%;
}

/* All Books: watchlist is full-width under holdings — avoid inner horizontal scroll */
.portfolio-watchlist-card--combined {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.portfolio-watchlist-card--combined #pf-watchlist-table-shell {
  min-width: 0;
}
.portfolio-watchlist-card--combined #pf-watchlist-table-shell .table-wrap {
  overflow-x: visible;
  max-width: 100%;
  width: 100%;
  min-width: 0;
}
.portfolio-watchlist-card--combined table.portfolio-table {
  table-layout: fixed;
  width: 100%;
}
.portfolio-watchlist-card--combined table.portfolio-table th.pf-sortable {
  white-space: normal;
  word-break: break-word;
  line-height: 1.25;
}
.portfolio-watchlist-card--combined table.portfolio-table td:nth-child(2),
.portfolio-watchlist-card--combined table.portfolio-table th:nth-child(2) {
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: left;
}
.portfolio-watchlist-card--combined table.portfolio-table th:nth-child(1),
.portfolio-watchlist-card--combined table.portfolio-table td:nth-child(1) {
  width: 9%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.portfolio-watchlist-card--combined table.portfolio-table th:nth-child(2),
.portfolio-watchlist-card--combined table.portfolio-table td:nth-child(2) {
  width: 38%;
}
.portfolio-watchlist-card--combined table.portfolio-table th:nth-child(3),
.portfolio-watchlist-card--combined table.portfolio-table td:nth-child(3) {
  width: 14%;
}
.portfolio-watchlist-card--combined table.portfolio-table th:nth-child(4),
.portfolio-watchlist-card--combined table.portfolio-table td:nth-child(4) {
  width: 12%;
}
.portfolio-watchlist-card--combined table.portfolio-table th:nth-child(5),
.portfolio-watchlist-card--combined table.portfolio-table td:nth-child(5) {
  width: 11%;
}
.portfolio-watchlist-card--combined table.portfolio-table th:nth-child(6),
.portfolio-watchlist-card--combined table.portfolio-table td:nth-child(6) {
  width: 16%;
  white-space: nowrap;
}

.page-header--portfolio .portfolio-page-desc {
  max-width: min(100%, 72rem);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* Portfolio P/L and day Δ: green / red (not weekend-specific — see live quote timestamp fix). */
.pf-pl-pos {
  color: var(--success);
}
.pf-pl-neg {
  color: var(--danger);
}
.stat-value .pf-pl-pos,
.stat-value .pf-pl-neg {
  font-weight: 700;
}

/** Memory list: keep table within the card (no page-wide horizontal scroll). */
table.memory-stored-table {
  table-layout: fixed;
  width: 100%;
}
table.memory-stored-table th,
table.memory-stored-table td {
  word-break: break-word;
  overflow-wrap: anywhere;
  vertical-align: top;
}
table.memory-stored-table col.memory-col-key { width: 14%; }
table.memory-stored-table col.memory-col-type { width: 10%; }
table.memory-stored-table col.memory-col-imp,
table.memory-stored-table col.memory-col-embed { width: 6%; }
table.memory-stored-table col.memory-col-content { width: 28%; }
table.memory-stored-table col.memory-col-updated { width: 18%; }
table.memory-stored-table col.memory-col-actions { width: 12%; }
table.memory-stored-table td.memory-col-content {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.memory-stored-table td.memory-col-updated {
  font-size: 11px;
}
table.memory-stored-table td.memory-col-actions {
  white-space: nowrap;
}

.memory-stats-card p {
  overflow-wrap: anywhere;
}

/* Settings — Face display (avoid full-width selects overlapping toggles) */
.face-settings-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 40rem;
}
.face-settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}
.face-settings-row--stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.face-settings-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  flex: 0 0 auto;
}
.face-settings-select {
  width: auto !important;
  min-width: 11rem;
  max-width: min(22rem, 100%);
  flex: 0 1 auto;
}
.face-settings-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

/* Wallet — balances card spans main column (avoids a narrow strip beside limits) */
.wallet-balances-card {
  width: 100%;
  max-width: 100%;
}
.wallet-balances-table {
  width: 100%;
  max-width: 28rem;
}
.wallet-balances-table th:first-child,
.wallet-balances-table td:first-child {
  padding-right: 1.25rem;
  white-space: nowrap;
}
.wallet-balances-table .wallet-balance-val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-primary);
}
.wallet-balances-table .wallet-balance-val--zero {
  color: var(--text-muted);
}
.wallet-balances-table tr.wallet-eth-total-row td {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.wallet-balances-table tr.wallet-eth-total-row .text-muted {
  font-weight: normal;
  font-size: 11px;
}
.wallet-balances-empty {
  margin: 0;
  padding: 12px 0 4px;
  font-size: 13px;
  color: var(--text-muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

tr {
  transition: background-color 0.2s ease;
}

tr:hover td { background: var(--bg-hover); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transition: background-color 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.btn:hover { 
  background: var(--bg-hover); 
  border-color: var(--border-focus); 
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.btn:active {
  transform: translateY(1px);
  box-shadow: 0 0px 0px rgba(0,0,0,0);
}

.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 255, 136, 0.2);
}

.btn-primary:hover { 
  background: var(--accent-dim); 
  box-shadow: 0 4px 12px rgba(0, 255, 136, 0.3);
}

.btn-danger { color: var(--danger); border-color: var(--danger); box-shadow: 0 2px 6px rgba(255, 68, 68, 0.1); }
.btn-danger:hover { background: rgba(255, 68, 68, 0.1); box-shadow: 0 4px 12px rgba(255, 68, 68, 0.2); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Forms */
input, textarea, select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--sans);
  width: 100%;
  transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 255, 136, 0.15);
}

/* Checkboxes/radios must not use width:100% (breaks layout, huge hit areas, overflow). */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  min-width: 1rem;
  flex-shrink: 0;
  margin: 0;
  vertical-align: middle;
  align-self: flex-start;
  margin-top: 2px;
}

textarea { font-family: var(--mono); font-size: 13px; resize: vertical; min-height: 100px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group { margin-bottom: 16px; }

/* Inline checkbox + label text (settings, etc.) */
.form-check-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  max-width: 100%;
  box-sizing: border-box;
}
.form-check-label span.form-check-text {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

select.input-fit { width: auto; max-width: 24em; min-width: 12em; }

/* PKMS — Browse row: search grows; kind / link-status stay modest width */
.pkms-browse-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.pkms-browse-filters .pkms-browse-q {
  flex: 1 1 160px;
  min-width: 0;
  width: auto;
  max-width: 100%;
}
.pkms-browse-filters select.pkms-browse-select {
  flex: 0 1 auto;
  width: auto;
  min-width: 6.5rem;
  max-width: 11rem;
}
.pkms-pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 12px 0 0;
}

.identity-desc { margin-bottom: 12px; display: block; }
.identity-file-actions { margin-top: 12px; }

.skill-edit-form { margin-bottom: 16px; padding: 12px; background: var(--bg-secondary, #1a1a1a); border-radius: 8px; }

/* Tags / badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-green { background: rgba(0, 255, 136, 0.15); color: var(--accent); }
.badge-yellow { background: rgba(255, 170, 0, 0.15); color: var(--warning); }
.badge-red { background: rgba(255, 68, 68, 0.15); color: var(--danger); }
.badge-blue { background: rgba(68, 136, 255, 0.15); color: var(--info); }

/* Progress bar */
.progress {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-bar.warning { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* Code blocks */
.code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--accent);
}

pre {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  color: var(--text-primary);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.01);
  font-size: 13px;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  align-items: flex-end;
  pointer-events: none;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: slideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transition: all 0.2s ease;
  pointer-events: auto;
}

.toast-error {
  border-color: var(--danger);
  border-left-color: var(--danger);
  background: rgba(255, 68, 68, 0.1);
}

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

/* ── Dashboard focus line ─────────────────────────────────────── */
.dash-focus-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  margin-bottom: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 38px;
}
.dash-focus-icon {
  color: var(--accent);
  font-size: 10px;
  flex-shrink: 0;
}
.dash-focus-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.4;
}
.dash-focus-edit-btn {
  opacity: 0.4;
  font-size: 13px;
  padding: 2px 6px;
  flex-shrink: 0;
}
.dash-focus-line:hover .dash-focus-edit-btn { opacity: 1; }
.dash-focus-editor {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
}
.dash-focus-editor .input {
  flex: 1;
  font-size: 13px;
  padding: 6px 10px;
}

/* ── Dashboard status strip ──────────────────────────────────── */
.dash-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 8px 14px;
  margin-bottom: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-secondary);
  align-items: center;
}
.dash-strip-item {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.dash-strip-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.dash-strip-chip {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--accent);
}
.dash-strip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green { 
  background: var(--success); 
  animation: pulseGreen 2s infinite cubic-bezier(0.66, 0, 0, 1);
}

@keyframes pulseGreen {
  0% { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.4); }
  70% { box-shadow: 0 0 0 4px rgba(0, 255, 136, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0); }
}

.dot-amber { background: var(--warning); }
.dot-red   { background: var(--danger); }

/* ── Sparkline ───────────────────────────────────────────────── */
.sparkline-svg {
  vertical-align: middle;
  opacity: 0.85;
}

/* Long tool names (skill_* ) wrap in Logs / Evolution */
.tool-name-code {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  overflow-wrap: anywhere;
  white-space: normal;
  line-height: 1.4;
}
.evolution-tool-cell,
.logs-tool-cell {
  vertical-align: top;
  max-width: min(420px, 50vw);
}
.evolution-source-cell {
  max-width: min(300px, 40vw);
  overflow-wrap: anywhere;
}
.logs-tool-hint {
  font-size: 11px;
  margin-top: 6px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

/* ── Analytics (daily snapshots & rollups) ─────────────────────── */
.analytics-intro {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}
.analytics-charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px;
}
.analytics-chart-card--mock {
  outline: 1px dashed var(--accent);
  outline-offset: 2px;
}
.analytics-chart-card--mock .card-title::after {
  content: " · sample";
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

.analytics-chart-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 10px;
  min-width: 0;
}
.analytics-chart-card .card-title {
  margin-bottom: 8px;
  font-size: 14px;
}
.analytics-chart-host {
  width: 100%;
  min-height: 232px;
  position: relative;
}
.analytics-chart-host svg {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}
.analytics-chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  padding: 16px;
  line-height: 1.45;
}
.analytics-mock-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
  cursor: pointer;
  user-select: none;
}
.analytics-mock-toggle input {
  margin-top: 3px;
  flex-shrink: 0;
}

.analytics-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Custom Modal Dialogs */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.15s ease-out forwards;
}
.modal-box {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  animation: slideUp 0.15s ease-out forwards;
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}
.modal-message {
  font-size: 14px;
  margin-bottom: 20px;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
}
.modal-input {
  width: 100%;
  margin-bottom: 20px;
  font-size: 14px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Focus ring for keyboard users (visible in Windows High Contrast Mode). */
.btn:focus-visible,
.nav-link:focus-visible,
.menu-close:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .dash-metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-rpc-health-badges { grid-template-columns: 1fr; }
  .dash-strip { font-size: 11px; gap: 4px 10px; }
}
