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

:root {
  --bg:        #0a0a10;
  --bg-2:      #0f0f18;
  --surface:   #14141f;
  --surface-2: #1a1a28;
  --border:    #2a2a3a;
  --border-h:  #3a3a50;
  --text:      #e8e8f0;
  --text-2:    #b0b0c4;
  --text-3:    #8888a0;
  --accent:    #00ced1;
  --accent-h:  #00b5b8;
  --accent-dim: rgba(0, 206, 209, .12);
  --danger:    #ff4060;
  --danger-h:  #e0304a;
  --danger-dim: rgba(255, 64, 96, .10);
  --success:   #00cc88;
  --success-dim: rgba(0, 204, 136, .10);
  --radius:    6px;
  --shadow:    0 1px 4px rgba(0,0,0,.3), 0 0 1px rgba(0,0,0,.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:      "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

a { color: var(--accent); }

/* ── Typography ──────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
h2 { font-size: 1.4rem; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
h3 { font-size: 1.15rem; font-weight: 600; color: var(--text); }
p  { color: var(--text-2); }

/* ── Top bar ─────────────────────────────────────────── */
header#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}
header#topbar.hidden { display: none; }

.topbar-left  { display: flex; align-items: center; gap: .75rem; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }

.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-decoration: none;
}

#user-info {
  font-size: .9rem;
  color: var(--text-2);
}

#admin-nav {
  display: flex;
  gap: .25rem;
  margin-left: 1.5rem;
}
#admin-nav.hidden { display: none; }
#admin-nav a {
  font-size: .9rem;
  color: var(--text-2);
  text-decoration: none;
  padding: .3rem .65rem;
  border-radius: var(--radius);
  transition: background .15s, color .15s;
}
#admin-nav a:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, opacity .15s, border-color .15s;
  text-decoration: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-h);
  border-color: var(--accent-h);
  box-shadow: 0 0 12px rgba(0, 206, 209, .25);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-h);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-h);
  border-color: var(--danger-h);
  box-shadow: 0 0 12px rgba(255, 64, 96, .2);
}

.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-block { width: 100%; }

/* ── Form elements ───────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.form-group + .form-group { margin-top: 1.1rem; }

label {
  font-size: .95rem;
  font-weight: 500;
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="number"],
select,
textarea {
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-2);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
textarea { resize: vertical; min-height: 5rem; }

/* Placeholder text */
::placeholder {
  color: var(--text-3);
  opacity: 1;
}

/* Date/number input icon coloring for dark theme */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="number"]::-webkit-inner-spin-button {
  filter: invert(1);
}
select { color-scheme: dark; }

/* Validation styles – shown after user interacts with a field */
input.touched:invalid,
textarea.touched:invalid,
select.touched:invalid {
  border-color: var(--danger);
}
input.touched:invalid:focus,
textarea.touched:invalid:focus,
select.touched:invalid:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-dim);
}
.field-error {
  font-size: .85rem;
  color: var(--danger);
  margin-top: .15rem;
  display: none;
}
.field-error.visible {
  display: block;
}

/* Checkbox & radio styling */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}

/* ── Tabs ────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  margin-bottom: 1.25rem;
}
.tab {
  padding: .55rem 1rem;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text-3);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}

.card-link {
  text-decoration: none;
  color: inherit;
  display: block;
  transition: box-shadow .15s, border-color .15s;
}
.card-link:hover {
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(0, 206, 209, .08);
}

/* ── Alerts ──────────────────────────────────────────── */
.alert {
  padding: .6rem .85rem;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 500;
}
.alert-error {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(255, 64, 96, .25);
}
.alert-success {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(0, 204, 136, .25);
}
.alert-info {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(0, 206, 209, .2);
}

/* ── Layout helpers ──────────────────────────────────── */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.center-card {
  max-width: 420px;
  margin: 4rem auto;
  padding: 0 1rem;
}

.page-header {
  margin-bottom: 1.5rem;
}
.page-header p {
  margin-top: .25rem;
}

.grid {
  display: grid;
  gap: 1rem;
}
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

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

.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .75rem; }
.gap-1 { gap: .5rem; }

/* ── Section spacing within forms ────────────────────── */
/* First section: less gap before the heading */
.mt-2:first-child > h3:first-child { margin-top: .25rem; }
/* Between consecutive sections: more breathing room */
.mt-2 + .mt-2 { margin-top: 2.25rem; }
/* After section description text, before first question */
.mt-2 > .text-muted + .form-group { margin-top: 1rem; }

.text-muted { color: var(--text-2); font-size: .95rem; }
.hint { font-size: .9rem; color: var(--text-2); }
code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--surface-2);
  padding: .15em .35em;
  border-radius: 3px;
  color: var(--accent);
}
.hint code {
  font-size: .9em;
}
.hint a { color: var(--accent); text-decoration: underline; }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* ── Spinner ─────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 1.2rem;
  height: 1.2rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  gap: .75rem;
  color: var(--text-2);
  font-size: 1rem;
}

/* ── Badge ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .5rem;
  font-size: .8rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
}
h1 > .badge, h2 > .badge, h3 > .badge, h4 > .badge {
  vertical-align: text-bottom;
}

.state-select {
  padding: .2rem .4rem;
  font-size: .85rem;
  font-weight: 600;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color .15s, color .15s;
}
.state-select:focus { border-color: var(--accent); }

/* ── Empty state ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-2);
}
.empty-state svg {
  width: 3rem;
  height: 3rem;
  margin-bottom: .75rem;
  opacity: .4;
}

/* ── Tables ──────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
  white-space: nowrap;
}
thead {
  background: var(--surface);
  position: sticky;
  top: 0;
}
th {
  text-align: left;
  padding: .55rem .75rem;
  font-weight: 600;
  color: var(--text-2);
  border-bottom: 2px solid var(--border);
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color .15s;
}
th.sortable:hover {
  color: var(--accent);
}
th.sorted {
  color: var(--accent);
}
td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
td.wrap {
  white-space: normal;
  word-break: break-word;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

td .sub-table {
  font-size: .9rem;
}
td .sub-table-toggle {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  padding: 0;
  white-space: nowrap;
}
td .sub-table-toggle:hover {
  color: var(--accent);
}
td .sub-table-body {
  display: none;
  flex-direction: column;
  gap: .1rem;
  margin-top: .25rem;
}
td .sub-table-body.open {
  display: flex;
}
td .sub-table-body span {
  color: var(--text-2);
}
td .sub-table-body strong {
  font-weight: 500;
  color: var(--text);
}

/* ── Checkbox lists (admin multi-select) ─────────────── */
.checkbox-list {
  /* Height intentionally not a multiple of item height so the last
     visible item is visibly clipped, hinting that more options exist. */
  max-height: 12.5rem;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .25rem;
  background: var(--bg-2);
}
.checkbox-list-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .5rem;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  font-weight: 400;
  font-size: .95rem;
}
.checkbox-list-item:hover {
  background: var(--surface-2);
}
.checkbox-list-item input[type="number"] {
  width: 5rem;
  padding: .2rem .4rem;
  font-size: .85rem;
}

/* ── Upload file widget ──────────────────────────────── */
.upload-file-list {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.upload-file-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
}
.upload-file-item .spinner {
  width: .9rem;
  height: .9rem;
  flex-shrink: 0;
}
.upload-file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
a.upload-file-name {
  color: var(--accent);
  text-decoration: none;
}
a.upload-file-name:hover {
  text-decoration: underline;
}
.upload-file-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 .2rem;
  border-radius: 3px;
  transition: color .15s, background .15s;
}
.upload-file-remove:hover:not(:disabled) {
  color: var(--danger);
  background: var(--danger-dim);
}
.upload-file-remove:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ── Footer ──────────────────────────────────────────── */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
}
#app > main { flex: 1; }
#footer {
  text-align: center;
  padding: .5rem 1rem;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text-3);
}
#footer.hidden { display: none; }
#footer a {
  color: var(--text-2);
  text-decoration: none;
  transition: color .15s;
}
#footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}
#footer .footer-sep {
  margin: 0 .5rem;
  opacity: .4;
}

/* ── Scrollbar (Webkit / Blink) ──────────────────────── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-h);
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 600px) {
  .container { padding: 1.25rem 1rem; }
  .center-card { margin: 2rem auto; }
  header#topbar { padding: .5rem 1rem; }
}

/* ── Light mode / print ──────────────────────────────── */
@media only screen and (prefers-color-scheme: light), only print {
  :root {
    --bg:        #f5f6f8;
    --bg-2:      #eef0f3;
    --surface:   #ffffff;
    --surface-2: #f0f1f4;
    --border:    #d8dbe0;
    --border-h:  #c0c4cc;
    --text:      #1a1d23;
    --text-2:    #4a4e5a;
    --text-3:    #6b7080;
    --accent:    #007c80;
    --accent-h:  #006a6e;
    --accent-dim: rgba(0, 124, 128, .10);
    --danger:    #dc2626;
    --danger-h:  #b91c1c;
    --danger-dim: rgba(220, 38, 38, .08);
    --success:   #16a34a;
    --success-dim: rgba(22, 163, 74, .08);
    --shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  }

  ::selection { color: #fff; }

  /* Primary button needs white text on the darker light-mode accent */
  .btn-primary { color: #fff; }

  /* Undo dark-mode icon inversion */
  input[type="date"]::-webkit-calendar-picker-indicator,
  input[type="number"]::-webkit-inner-spin-button {
    filter: none;
  }
  select { color-scheme: light; }

  /* Adjusted glow colors for light backgrounds */
  .btn-primary:hover:not(:disabled) {
    box-shadow: 0 0 12px rgba(0, 124, 128, .2);
  }
  .btn-danger:hover:not(:disabled) {
    box-shadow: 0 0 12px rgba(220, 38, 38, .15);
  }
  .card-link:hover {
    box-shadow: 0 0 12px rgba(0, 124, 128, .08);
  }

  /* Table row hover */
  tr:hover td { background: #f8f9fc; }

  /* Alert borders */
  .alert-error { border-color: #fecaca; background: #fef2f2; }
  .alert-success { border-color: #bbf7d0; background: #f0fdf4; }
  .alert-info { border-color: #b2dfdb; background: #e0f7fa; }

  /* Scrollbar */
  ::-webkit-scrollbar-track { background: var(--bg); }
  ::-webkit-scrollbar-thumb { background: var(--border); }
  ::-webkit-scrollbar-thumb:hover { background: var(--border-h); }
}
