:root {
  --bg: #0b1625;
  --surface: #122338;
  --surface-2: #172b42;
  --surface-3: #1c334d;
  --text: #eef4fb;
  --muted: #a8b7c8;
  --line: #29425e;
  --cm-green: #29b7a9;
  --cm-green-2: #5eead4;
  --primary-soft: rgba(41, 183, 169, .16);
  --danger: #e6473b;
  --warning: #e0c92f;
  --success: #2fb86a;
  --shadow: 0 14px 36px rgba(0, 0, 0, .3);
  --radius: 14px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100dvh; overflow-x: hidden; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--cm-green-2); }
h1, h2, h3 { line-height: 1.2; }
.muted { color: var(--muted); }

/* Shell */
.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 248px 1fr; }
.app-nav { background: linear-gradient(180deg, #07111e, #10243a); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 6px; }
.app-brand { display: flex; align-items: center; gap: 12px; padding: 8px 8px 22px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #06231f; font-weight: 900; font-size: 18px; background: linear-gradient(145deg, var(--cm-green), var(--cm-green-2)); box-shadow: 0 8px 18px rgba(41,183,169,.3); }
.brand-name { font-size: 16px; font-weight: 800; letter-spacing: .02em; }
.brand-sub { color: var(--muted); font-size: 11px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; transition: background .15s, color .15s; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--cm-green-2); }
.nav-footer { margin-top: auto; padding: 12px 8px; color: var(--muted); font-size: 11px; }
.app-main { padding: 26px 32px 60px; max-width: 1680px; }
.app-topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 12px; flex-wrap: wrap; }
.conn-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.conn-pill.live .conn-dot { background: var(--success); box-shadow: 0 0 0 3px rgba(47,184,106,.25); }
.conn-pill.live { color: var(--success); }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 20px 22px; }
.card-header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-header h2 { margin: 0; font-size: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.input { width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--text); }
.input:focus { outline: 2px solid var(--cm-green); outline-offset: 1px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; font-weight: 700; font-size: 14px; transition: transform .1s, filter .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--cm-green), var(--cm-green-2)); color: #06231f; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-danger { background: rgba(230,71,59,.14); color: #ff9a8f; border-color: rgba(230,71,59,.4); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }

.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; }
.badge-draft { background: var(--surface-3); color: var(--muted); }
.badge-generated { background: rgba(224,201,47,.16); color: var(--warning); }
.badge-processed { background: rgba(47,184,106,.16); color: var(--success); }

/* Results table (generated preview) */
.results-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.results-table th, .results-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.results-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.party-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; margin-right: 8px; vertical-align: -1px; }
.totals-strip { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 10px; }
.totals-strip .stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; }
.totals-strip .stat .n { font-size: 18px; font-weight: 800; }
.totals-strip .stat .l { font-size: 11px; color: var(--muted); text-transform: uppercase; }

/* Upload / dropzone */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 34px 20px; text-align: center; color: var(--muted); transition: border-color .15s, background .15s; cursor: pointer; }
.dropzone.drag { border-color: var(--cm-green); background: var(--primary-soft); color: var(--text); }
.dropzone input { display: none; }

/* Validation alerts */
.alert { border-radius: 12px; padding: 16px 18px; border: 1px solid; margin-top: 16px; }
.alert h3 { margin: 0 0 6px; font-size: 15px; }
.alert p { margin: 0; font-size: 13px; line-height: 1.55; }
.alert-success { background: rgba(47,184,106,.1); border-color: rgba(47,184,106,.35); color: #a9f0c6; }
.alert-error { background: rgba(230,71,59,.1); border-color: rgba(230,71,59,.35); color: #ffb4ab; }
.alert-warning { background: rgba(224,201,47,.1); border-color: rgba(224,201,47,.35); color: #f2e59a; }

/* PDF viewer */
.pdf-frame { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* Ranking bars */
.bar-row { margin-bottom: 14px; }
.bar-row .bar-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.bar-track { height: 14px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .5s ease; }

/* Ranking cards */
.rank-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.rank-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; position: relative; overflow: hidden; transition: transform .2s; }
.rank-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--party-color, var(--cm-green)); }
.rank-card .medal { font-size: 12px; color: var(--muted); font-weight: 800; }
.rank-card .party { font-weight: 800; margin: 6px 0 10px; display: flex; align-items: center; gap: 8px; }
.rank-card .votes { font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; }
.rank-card .pct { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Guide */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3,10,20,.65); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 60; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-width: 720px; width: 100%; max-height: 84vh; overflow: auto; box-shadow: var(--shadow); }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--surface); }
.modal-body { padding: 20px 22px; }
.scenario { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.scenario h4 { margin: 0 0 8px; font-size: 14px; color: var(--cm-green-2); }
.scenario ol { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); line-height: 1.7; }
.scenario .expect { margin-top: 8px; font-size: 12px; font-weight: 700; }
.icon-btn { background: transparent; border: none; color: var(--muted); font-size: 20px; }

/* Toasts */
#toast-root { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--cm-green); border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); font-size: 13px; min-width: 240px; animation: toast-in .18s ease; }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }
.pagination-status { font-size: 12px; color: var(--muted); }

/* Page grid: main content + simulated ops sidebar */
.page-grid { display: grid; grid-template-columns: minmax(0, 3.6fr) minmax(260px, 1fr); gap: 20px; align-items: start; }
.page-aside { position: sticky; top: 18px; display: flex; flex-direction: column; gap: 16px; }
.widget-card .card-header h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.widget-badge { font-size: 10px; padding: 2px 8px; }

/* Telemetry widget */
.telemetry-row { display: grid; grid-template-columns: 64px 1fr 52px; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.telemetry-track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.telemetry-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--cm-green), var(--cm-green-2)); transition: width .6s ease; }
.telemetry-fill.warn { background: linear-gradient(90deg, var(--warning), #f2b90a); }
.telemetry-fill.hot { background: linear-gradient(90deg, var(--danger), #ff8a7a); }
.container-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.container-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.container-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 2px rgba(47,184,106,.2); }
.container-chip.enter { animation: chip-in .35s ease; }
@keyframes chip-in { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: scale(1); } }

/* Storage latency sparkline */
.spark-line { fill: none; stroke: var(--cm-green-2); stroke-width: 2; }
.spark-fill { fill: rgba(41,183,169,.14); stroke: none; }

/* Live hash chain */
.chain-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow: hidden; }
.chain-block { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; animation: block-in .3s ease; }
.chain-block-top { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 4px; }
.chain-block-top strong { color: var(--cm-green-2); }
@keyframes block-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Network / voting centers */
.center-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.center-row .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); flex-shrink: 0; transition: background .3s, box-shadow .3s; }
.center-row .dot.active { background: var(--success); box-shadow: 0 0 0 3px rgba(47,184,106,.2); }
.center-row .name { flex: 1; color: var(--text); }

/* Worker nodes */
.node-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.node-row .name { flex: 1; color: var(--text); font-weight: 600; }
.node-badge { font-size: 9px; padding: 2px 7px; border-radius: 999px; font-weight: 800; letter-spacing: .03em; }
.node-badge.running { background: rgba(47,184,106,.16); color: var(--success); }
.node-badge.scaling { background: rgba(224,201,47,.16); color: var(--warning); }
.node-mini-track { width: 50px; height: 5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.node-mini-fill { height: 100%; background: var(--cm-green-2); transition: width .5s ease; }
.node-row.enter { animation: chip-in .3s ease; }

@media (max-width: 880px) {
  .page-grid { grid-template-columns: 1fr; }
  .page-aside { position: static; }
}

table.audit-table { width: 100%; font-size: 12px; border-collapse: collapse; }
table.audit-table th, table.audit-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
code.hash { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; color: var(--muted); word-break: break-all; }

/* Mobile public page */
.mobile-shell { min-height: 100dvh; padding: 22px 16px 60px; max-width: 480px; margin: 0 auto; }
.mobile-header { text-align: center; margin-bottom: 18px; }
.mobile-header .eyebrow { color: var(--cm-green-2); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.mobile-header h1 { font-size: 20px; margin: 6px 0 0; }
.mobile-updated { text-align: center; color: var(--muted); font-size: 12px; margin-top: 16px; }

@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-nav { flex-direction: row; overflow-x: auto; padding: 10px; }
  .app-brand { display: none; }
  .nav-footer { display: none; }
  .app-main { padding: 18px 16px 48px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
