/* ── DESIGN TOKENS — DARK (default) ────────────────────────────── */
:root {
  --bg:            #061822;
  --bg-card:       #0b2535;
  --bg-elevated:   #0f2e42;
  --bg-input:      rgba(14, 165, 233, 0.06);
  --white:         #ffffff;
  --text:          #ffffff;
  --text-muted:    #94a3b8;
  --blue:          #0ea5e9;
  --blue-dark:     #0284c7;
  --blue-dim:      #38bdf8;
  --teal:          #06b6d4;
  --teal-dim:      #67e8f9;
  --green:         #10b981;
  --green-dim:     #6ee7b7;
  --neutral:       #94a3b8;
  --neutral-dark:  #64748b;
  --neutral-light: #cbd5e1;
  --warn:          #f59e0b;
  --danger:        #ef4444;
  --border:        rgba(14, 165, 233, 0.15);
  --border-hover:  rgba(14, 165, 233, 0.4);
  --radius:        12px;
  --radius-sm:     8px;
  --radius-lg:     16px;
  --shadow:        0 4px 24px rgba(0, 0, 0, 0.4), 0 0 40px rgba(14, 165, 233, 0.06);
  --header-bg:     rgba(6, 24, 34, 0.92);
  --toggle-icon:   '☀️';
}

/* ── DESIGN TOKENS — LIGHT ──────────────────────────────────────── */
html[data-theme="light"] {
  --bg:            #f5f9fd;
  --bg-card:       #ffffff;
  --bg-elevated:   #edf4fb;
  --bg-input:      #f8fbfe;
  --text:          #111827;
  --text-muted:    #546e8a;
  /* --white remapped so color:var(--white) reads as near-black on light bg */
  --white:         #111827;
  --neutral:       #546e8a;
  --neutral-dark:  #8caabb;
  --neutral-light: #1f3550;
  --green-dim:     #059669;
  --teal-dim:      #0891b2;
  --blue-dim:      #0369a1;
  --border:        rgba(14, 165, 233, 0.2);
  --border-hover:  rgba(14, 165, 233, 0.45);
  --shadow:        0 2px 12px rgba(14, 165, 233, 0.08), 0 1px 3px rgba(0, 0, 0, 0.07);
  --header-bg:     rgba(245, 249, 253, 0.97);
  --toggle-icon:   '🌙';
}

/* ── LIGHT THEME OVERRIDES ──────────────────────────────────────── */
/* Elements that have hardcoded dark-mode colors need explicit overrides */
html[data-theme="light"] .card.subtle {
  border-color: rgba(14, 165, 233, 0.18);
}

html[data-theme="light"] code {
  color: #0284c7;
}

html[data-theme="light"] .muted {
  color: #546e8a;
}

html[data-theme="light"] .link {
  color: #0369a1;
}
html[data-theme="light"] .link:hover {
  color: #0891b2;
}

html[data-theme="light"] .card h2,
html[data-theme="light"] .card h3 {
  color: #111827;
}

html[data-theme="light"] .bullets li {
  color: #1f3550;
}

html[data-theme="light"] .help {
  color: #546e8a;
}

html[data-theme="light"] .btn {
  background: rgba(14, 165, 233, 0.08);
  border-color: rgba(14, 165, 233, 0.25);
  color: #0c2340;
}
html[data-theme="light"] .btn:hover {
  background: rgba(14, 165, 233, 0.14);
  border-color: rgba(14, 165, 233, 0.4);
}

html[data-theme="light"] select option {
  background: #ffffff;
  color: #111827;
}

html[data-theme="light"] label {
  color: #1f3550;
}

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

/* Ensure [hidden] always wins over display:flex/grid on overlays */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.no-scroll { overflow: hidden; }

a { color: inherit; text-decoration: none; }
code { font-family: 'Courier New', monospace; font-size: 0.875em; color: var(--teal-dim); }

/* ── LAYOUT ─────────────────────────────────────────────────────── */
.shell {
  max-width: 960px;
  margin-inline: auto;
  padding-inline: 24px;
}

main.shell {
  padding-block: 32px 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── HEADER / NAV ───────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.site-header .shell {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-light { display: none !important; }
.logo-dark  { display: inline !important; }
html[data-theme="light"] .logo-light { display: inline !important; }
html[data-theme="light"] .logo-dark  { display: none !important; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.3);
}

.brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--white);
}

.subtitle {
  font-size: 0.78rem;
  color: var(--neutral);
  margin-top: 1px;
}

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

/* ── BUTTONS ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.01em;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--white);
  transition: background 0.15s, border-color 0.15s, transform 0.15s cubic-bezier(.34,1.56,.64,1), box-shadow 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
}

.btn:active { transform: scale(0.97); }

.btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--bg);
  font-weight: 700;
}

.btn.primary:hover {
  background: var(--blue);
  border-color: var(--blue);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.35);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-icon { font-size: 1rem; }

/* ── CARDS ───────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  box-shadow: var(--shadow);
}

.card.subtle {
  background: var(--bg-elevated);
  border-color: rgba(255, 255, 255, 0.06);
  box-shadow: none;
}

.card h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
  color: var(--white);
}

/* ── FORM ELEMENTS ───────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--neutral-light);
  letter-spacing: 0.02em;
}

.req { color: var(--teal); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[inputmode="numeric"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--white);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

input::placeholder,
textarea::placeholder { color: var(--neutral-dark); }

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath stroke='%2394a3b8' stroke-width='1.5' fill='none' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

select option {
  background: var(--bg-card);
  color: var(--white);
}

textarea { resize: vertical; min-height: 90px; line-height: 1.6; }

.help {
  font-size: 0.75rem;
  color: var(--neutral-dark);
  margin-top: 2px;
}

.muted { color: var(--neutral); font-size: 0.875rem; }
.link  { color: var(--blue-dim); cursor: pointer; }
.link:hover { color: var(--teal-dim); text-decoration: underline; }

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

fieldset { border: none; padding: 0; }

/* ── FILE DROPZONE ───────────────────────────────────────────────── */
.uploader { margin-top: 20px; margin-bottom: 20px; display: flex; flex-direction: column; gap: 12px; }

.drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--bg-input);
}

.drop:hover,
.drop.drag {
  border-color: var(--teal);
  background: rgba(6, 182, 212, 0.06);
}

.drop:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.drop-icon  { font-size: 2rem; }
.drop-title { font-weight: 600; font-size: 0.95rem; color: var(--white); }
.drop-sub   { font-size: 0.875rem; color: var(--neutral); }
.drop-hint  { font-size: 0.75rem; color: var(--neutral-dark); margin-top: 4px; }

/* ── FILE LIST ───────────────────────────────────────────────────── */
.file-list { display: flex; flex-direction: column; gap: 8px; }

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  gap: 12px;
}

.file-meta { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.file-name { font-size: 0.875rem; font-weight: 500; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 0.75rem; color: var(--neutral); }
.file-btn {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid rgba(239,68,68,0.25);
  background: rgba(239,68,68,0.08);
  color: #f87171;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.file-btn:hover {
  background: rgba(239,68,68,0.18);
  border-color: rgba(239,68,68,0.55);
  color: #fca5a5;
}
.file-btn:active { transform: scale(0.96); }

html[data-theme="light"] .file-btn {
  border-color: rgba(220,38,38,0.25);
  background: rgba(220,38,38,0.06);
  color: #dc2626;
}
html[data-theme="light"] .file-btn:hover {
  background: rgba(220,38,38,0.12);
  border-color: rgba(220,38,38,0.45);
  color: #b91c1c;
}

/* ── PROGRESS ──────────────────────────────────────────────────────  */
.progress-wrap { flex: 1; }

progress {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
}

progress::-webkit-progress-bar  { background: var(--bg-elevated); border-radius: 2px; }
progress::-webkit-progress-value{ background: var(--teal); border-radius: 2px; }

/* ── TOAST ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 200;
  max-width: 420px;
  text-align: center;
  white-space: nowrap;
}

/* ── LOADING OVERLAY ─────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 24, 34, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  opacity: 0;
  transition: opacity 0.25s;
}

.loading-overlay.active { opacity: 1; }

.loading-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 48px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow);
}

.loading-text { display: flex; flex-direction: column; gap: 4px; }
.loading-text strong { font-size: 1rem; font-weight: 700; color: var(--white); }
.loading-text small  { font-size: 0.8rem; color: var(--neutral); }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(6, 182, 212, 0.2);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* ── USER MENU ───────────────────────────────────────────────────── */
.user-menu { position: relative; }

.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--bg);
  flex-shrink: 0;
}

.menu-options {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 200;
  overflow: hidden;
}

.menu-open .menu-options { display: block; }

.user-info {
  padding: 14px 16px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--neutral-light);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.menu-options a,
.menu-options button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--neutral-light);
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.menu-options a:hover,
.menu-options button:hover {
  background: rgba(14, 165, 233, 0.08);
  color: var(--white);
}

#adminBadge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--teal);
  color: var(--bg);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── BULLET LIST ─────────────────────────────────────────────────── */
.bullets {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bullets li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--neutral-light);
  line-height: 1.6;
}

.bullets li::before {
  content: '→';
  color: var(--teal);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── TABLE (Organizations) ───────────────────────────────────────── */
.data-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table thead tr {
  background: var(--bg-elevated);
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--neutral);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--neutral-light);
  vertical-align: middle;
}

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.data-table tbody tr:hover { background: rgba(14, 165, 233, 0.06); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .mono { font-family: 'Courier New', monospace; font-size: 0.85em; color: var(--teal-dim); }
.data-table .dim  { font-size: 0.82rem; color: var(--neutral-dark); }

/* ── FOOTER ──────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
}

.site-footer .shell {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-footer .muted { font-size: 0.8rem; color: var(--neutral-dark); }

/* ── THEME TOGGLE ────────────────────────────────────────────────── */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.theme-toggle:hover {
  border-color: var(--teal);
  transform: rotate(20deg) scale(1.1);
}

/* light-mode card/input overrides */
html[data-theme="light"] .card {
  box-shadow: 0 2px 12px rgba(14,165,233,0.08), 0 1px 3px rgba(0,0,0,0.06);
}

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea {
  background: #ffffff;
  border-color: rgba(14,165,233,0.3);
  color: #0c2340;
}

html[data-theme="light"] input::placeholder,
html[data-theme="light"] textarea::placeholder { color: #7a9cc4; }

html[data-theme="light"] select option { background: #ffffff; color: #0c2340; }

html[data-theme="light"] .drop {
  background: #f0f7ff;
  border-color: rgba(14,165,233,0.3);
}

html[data-theme="light"] .file-item { background: #e8f4fd; border-color: rgba(14,165,233,0.15); }

html[data-theme="light"] .menu-options {
  background: #ffffff;
  box-shadow: 0 8px 32px rgba(14,165,233,0.12), 0 2px 8px rgba(0,0,0,0.08);
}

html[data-theme="light"] .toast { background: #ffffff; box-shadow: 0 8px 32px rgba(0,0,0,0.12); }

html[data-theme="light"] .loading-card { background: #ffffff; }

html[data-theme="light"] .site-footer { background: var(--bg); }

html[data-theme="light"] .data-table thead tr { background: #e8f4fd; }
html[data-theme="light"] .data-table td { color: #1e3a5f; }
html[data-theme="light"] .data-table tbody tr:hover { background: rgba(14,165,233,0.06); }

/* ── RESPONSIVE ──────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .grid { grid-template-columns: 1fr; }
  .card { padding: 20px; }
  .loading-card { padding: 28px 24px; gap: 16px; }
  .site-header .shell { padding-inline: 16px; }
  .brand h1 { font-size: 0.95rem; }
  .subtitle { display: none; }
}
