:root {
  --bg: #0e1116;
  --surface: #141923;
  --surface-2: #1c232f;
  --border: #2a3445;
  --text: #e6ecf3;
  --text-muted: #8b96a7;
  --accent: #4f8eff;
  --accent-hover: #6ba0ff;
  --success: #3ddc8a;
  --warning: #f3a93c;
  --danger: #ec5b5b;
  --radius: 8px;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* The hidden attribute is how main.js shows/hides the login vs the
   app shell. Default user-agent `[hidden] { display: none }` loses
   the cascade fight with our explicit `.login-shell { display: grid }`
   and `.app-shell { display: grid }` rules below, so we pin it
   globally. Same fix the mini-app made in commit b035aca. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

code, .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  color: var(--text-muted);
}

button {
  font: inherit;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: background 0.12s, border-color 0.12s;
}
button:hover:not(:disabled) { background: var(--border); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
button.danger:hover:not(:disabled) {
  background: var(--danger);
  color: white;
}

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  font: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--radius);
  width: 100%;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}
label.field span { color: var(--text-muted); font-size: 0.88em; }

/* --- Login ---------------------------------------------------------- */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 1.4em; }
.login-card p.lede { margin: 0 0 20px; color: var(--text-muted); font-size: 0.95em; }
.login-error {
  color: var(--danger);
  margin-top: 10px;
  font-size: 0.9em;
}

/* --- App shell ------------------------------------------------------ */

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar-brand h2 { margin: 0; font-size: 1.05em; letter-spacing: 0.4px; }
.sidebar-brand p { margin: 2px 0 0; font-size: 0.78em; color: var(--text-muted); }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; }
.sidebar-nav a {
  padding: 9px 20px;
  color: var(--text);
  border-left: 3px solid transparent;
  font-size: 0.95em;
}
.sidebar-nav a:hover {
  background: var(--surface-2);
  text-decoration: none;
  color: var(--text);
}
.sidebar-nav a.active {
  background: var(--surface-2);
  border-left-color: var(--accent);
  color: var(--text);
}
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.85em;
  color: var(--text-muted);
}
.sidebar-footer button.text-link {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0;
  margin-top: 4px;
  font-size: 0.85em;
}
.sidebar-footer button.text-link:hover { color: var(--text); }

main.content {
  padding: 24px 28px;
  overflow-y: auto;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h1 { margin: 0; font-size: 1.4em; }
.page-header .actions { display: flex; gap: 8px; }

/* --- Tables --------------------------------------------------------- */

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}
.table-card h3 {
  margin: 0;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 0.95em;
  color: var(--text-muted);
  font-weight: 500;
}
table {
  width: 100%;
  border-collapse: collapse;
}
table th, table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.92em;
  white-space: nowrap;
}
table th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.82em;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
table tr:last-child td { border-bottom: none; }
table tr.clickable { cursor: pointer; }
table tr.clickable:hover { background: var(--surface-2); }
table td.num { font-variant-numeric: tabular-nums; text-align: right; }

/* --- Status / Badges ------------------------------------------------ */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78em;
  letter-spacing: 0.3px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: lowercase;
}
.badge.draft     { color: var(--text-muted); }
.badge.joinable  { color: var(--accent); border-color: var(--accent); }
.badge.live      { color: var(--success); border-color: var(--success); }
.badge.finalized,
.badge.payout_pending,
.badge.paid      { color: var(--warning); border-color: var(--warning); }
.badge.canceled  { color: var(--danger); border-color: var(--danger); }
.badge.closed    { color: var(--text-muted); }
.badge.accepted, .badge.open { color: var(--success); border-color: var(--success); }
.badge.pending_submit, .badge.submitted, .badge.closing { color: var(--accent); border-color: var(--accent); }
.badge.rejected, .badge.execution_unknown { color: var(--danger); border-color: var(--danger); }

/* --- Detail layout -------------------------------------------------- */

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}
.kv-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kv-card h3 {
  margin: 0 0 12px;
  font-size: 0.95em;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kv-card dl { margin: 0; display: grid; grid-template-columns: 160px 1fr; gap: 6px 16px; }
.kv-card dt { color: var(--text-muted); font-size: 0.9em; }
.kv-card dd { margin: 0; font-size: 0.92em; word-break: break-all; }

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.92em;
  box-shadow: var(--shadow);
  max-width: 420px;
  z-index: 200;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

/* --- Modal ---------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 300;
  padding: 24px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 12px; }
.modal-card p { color: var(--text-muted); margin: 0 0 16px; }
.modal-card .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.empty {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}

.row-actions { display: flex; gap: 6px; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
