:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-raised: #21253a;
  --border: #2a2f45;
  --border-subtle: #1e2235;
  --primary: #4f7cff;
  --primary-hover: #6b93ff;
  --primary-dim: rgba(79, 124, 255, 0.15);
  --danger: #f04f4f;
  --danger-hover: #f76e6e;
  --danger-dim: rgba(240, 79, 79, 0.15);
  --success: #3ecf8e;
  --success-dim: rgba(62, 207, 142, 0.12);
  --warning: #f5a623;
  --text: #e4e8f0;
  --text-muted: #7c8499;
  --text-faint: #4a5068;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", ui-monospace, monospace;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --nav-h: 56px;
  --transition: 0.15s ease;
}

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

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

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

h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.75rem; }

/* ── Navbar ─────────────────────────────── */
#navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 2rem;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}

.nav-link {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: color var(--transition), background var(--transition);
}

.nav-link:hover { color: var(--text); background: var(--surface-raised); }
.nav-link.active { color: var(--primary); background: var(--primary-dim); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

/* ── Main ────────────────────────────────── */
#app {
  padding-top: calc(var(--nav-h) + 2rem);
  padding-bottom: 4rem;
  max-width: 1100px;
  margin: 0 auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

.view { display: block; }
.view.hidden { display: none; }

/* ── Badges ─────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-publisher { background: var(--primary-dim); color: var(--primary); }
.badge-reader { background: rgba(62, 207, 142, 0.12); color: var(--success); }
.badge-latest { background: var(--success-dim); color: var(--success); }
.badge-inactive { background: rgba(124, 132, 153, 0.15); color: var(--text-faint); }
.badge-active { background: var(--success-dim); color: var(--success); }

/* ── Buttons ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  white-space: nowrap;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-full { width: 100%; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-secondary { background: var(--surface-raised); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-raised); color: var(--text); }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; border-radius: var(--radius-sm); }

.btn-icon { padding: 0.4rem; border-radius: var(--radius-sm); }

/* ── Forms ───────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }

.field-inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.field-inline label { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }

input[type="text"],
input[type="password"],
input[type="search"],
input[type="datetime-local"],
input[type="file"],
select,
textarea {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  padding: 0.45rem 0.75rem;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

input[type="file"] { padding: 0.35rem 0.6rem; cursor: pointer; }

textarea { resize: vertical; font-family: var(--mono); font-size: 0.8rem; }

select option { background: var(--surface); }

.form-stack { display: flex; flex-direction: column; gap: 1rem; }

.search-input { max-width: 320px; }

/* ── Login ───────────────────────────────── */
#view-login {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - var(--nav-h));
  padding-top: 0;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo { color: var(--primary); margin-bottom: 1rem; }
.login-card h1 { margin-bottom: 0.4rem; }
.login-subtitle { color: var(--text-muted); margin-bottom: 1.75rem; font-size: 0.875rem; }

.login-card .field { text-align: left; margin-bottom: 1rem; }
.login-card input { padding: 0.6rem 0.85rem; font-size: 1rem; }

.error-text { color: var(--danger); font-size: 0.8rem; margin-top: 0.5rem; }
.error-text.hidden { display: none; }

/* ── Page header ─────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

/* ── Toolbar ─────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.toolbar-wrap { align-items: flex-end; }

/* ── Cards / program grid ────────────────── */
.card-grid { display: flex; flex-direction: column; gap: 0.6rem; }

.program-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: border-color var(--transition);
  cursor: pointer;
}

.program-card:hover { border-color: var(--primary); }

.program-card-main { flex: 1; min-width: 0; }
.program-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.program-card-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }

.program-card-actions { display: flex; gap: 0.4rem; align-items: center; }

/* ── Table ───────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  text-align: left;
  padding: 0.6rem 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-raised); }

.mono { font-family: var(--mono); font-size: 0.8rem; color: var(--text-muted); }

/* ── Detail layout ───────────────────────── */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.detail-title { display: flex; flex-direction: column; gap: 0.4rem; }
.detail-title h2 { font-size: 1.35rem; }
.detail-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.meta-item { display: flex; flex-direction: column; gap: 0.15rem; }
.meta-label { font-size: 0.72rem; font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.meta-value { font-size: 0.875rem; color: var(--text); word-break: break-all; }
.meta-value.mono { font-family: var(--mono); font-size: 0.78rem; }

/* ── Tabs ────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }

.tab-btn {
  padding: 0.6rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Section ─────────────────────────────── */
.section { margin-bottom: 2rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.85rem; }

/* ── Upload form ─────────────────────────── */
.upload-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* ── Code / preview ──────────────────────── */
.code-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.7;
  overflow: auto;
  max-height: 480px;
  white-space: pre;
  color: var(--text);
}

/* ── Token list ──────────────────────────── */
.token-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border-subtle);
}

.token-row:last-child { border-bottom: none; }
.token-name { flex: 1; font-weight: 500; font-size: 0.875rem; }
.token-meta { font-size: 0.78rem; color: var(--text-muted); }

/* ── Token reveal ────────────────────────── */
.token-reveal {
  margin-bottom: 1.5rem;
}

.token-reveal-box {
  background: var(--success-dim);
  border: 1px solid rgba(62, 207, 142, 0.3);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.token-reveal-value {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
}

.token-reveal-value code {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.8rem;
  word-break: break-all;
  color: var(--success);
}

/* ── Two-column layout ───────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 700px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ── Pagination ──────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: center;
}

.pagination-info { font-size: 0.8rem; color: var(--text-muted); margin: 0 0.5rem; }

/* ── Breadcrumb ──────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb-sep { color: var(--text-faint); }
.breadcrumb-current { color: var(--text); }

/* ── Back link ───────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  cursor: pointer;
}

.back-link:hover { color: var(--primary); }

/* ── Empty state ─────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ── Spinner ─────────────────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

.spinner.hidden { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ───────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9999;
}

.toast {
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: slide-in 0.2s ease;
  max-width: 340px;
  border: 1px solid transparent;
}

.toast-success { background: #1a2e26; border-color: rgba(62, 207, 142, 0.35); color: var(--success); }
.toast-error   { background: #2e1a1a; border-color: rgba(240, 79, 79, 0.35); color: var(--danger); }
.toast-info    { background: #1a1f35; border-color: rgba(79, 124, 255, 0.35); color: var(--primary); }

@keyframes slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ── Overlay / Confirm ───────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(2px);
}

.overlay.hidden { display: none; }

.confirm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  max-width: 380px;
  width: 90%;
  box-shadow: var(--shadow);
}

.confirm-box p { margin-bottom: 1.25rem; color: var(--text); line-height: 1.6; }

.confirm-actions { display: flex; gap: 0.75rem; justify-content: flex-end; }

/* ── Utility ─────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
