:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --primary: #111827;
  --danger: #b91c1c;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 8px 24px rgba(17, 24, 39, 0.08);
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
}

* {
  box-sizing: border-box;
}

a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration-thickness: 2px;
}

a:focus-visible {
  outline: 3px solid rgba(17, 24, 39, 0.12);
  outline-offset: 2px;
  border-radius: 8px;
}

h1, h2, h3, h4 {
  margin: 0 0 10px 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h1 { font-size: 22px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

p {
  margin: 0 0 12px 0;
  color: var(--text);
}

.muted {
  color: var(--muted);
}

.help {
  color: var(--muted);
  font-size: 13px;
}

.required {
  color: var(--danger);
  font-weight: 700;
}

.upload-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: #fafafa;
}

.upload-actions {
  display: grid;
  gap: 10px;
}

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 14px;
  background: #fafafa;
  cursor: pointer;
}

.dropzone.dragover {
  outline: 3px solid rgba(17, 24, 39, 0.12);
  outline-offset: 0;
  border-color: var(--text);
}

.dropzone-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.dropzone-hint {
  color: var(--muted);
  font-size: 13px;
}

.file-list {
  list-style: none;
  padding-left: 0;
  margin: 10px 0 0 0;
}

.file-item {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.file-meta {
  color: var(--muted);
  font-size: 12px;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 18px;
}

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

.spacer {
  flex: 1;
}

main.container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

main.container > :first-child {
  margin-top: 0;
}

main.container > :last-child {
  margin-bottom: 0;
}

/* Header */
.container > .row {
  min-height: 48px;
}

/* Nav */
.container.nav {
  padding-top: 0;
}

.nav .row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
}

.nav a {
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.nav a:hover {
  border-color: var(--border);
  background: #fafafa;
}

.nav a.active,
.nav a[aria-current="page"] {
  border-color: var(--border);
  background: #fafafa;
}

/* Cards / sections */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
  background: var(--surface);
}

/* Nested cards should stack cleanly inside cards */
.card .card {
  margin: 12px 0 0 0;
}

.card > :first-child {
  margin-top: 0;
}

.card > :last-child {
  margin-bottom: 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.card-grid .card {
  margin: 0;
}

/* Auth pages */
.auth-card {
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

/* Errors */
#global-error {
  padding-top: 0;
}

.error {
  border: 1px solid rgba(185, 28, 28, 0.25);
  background: rgba(185, 28, 28, 0.06);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fafafa;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.6;
  user-select: none;
}

.badge-danger {
  border-color: rgba(185, 28, 28, 0.25);
  background: rgba(185, 28, 28, 0.06);
  color: var(--danger);
}

.badge-muted {
  color: var(--muted);
}

.empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 14px;
  background: #fafafa;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Forms */
form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

/* Opt-in horizontal label layout (useful for checkboxes) */
label.row {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 600;
}

label > input,
label > select,
label > textarea {
  font-weight: 400;
}

input, select, textarea, button {
  font: inherit;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

textarea[rows="2"],
textarea[rows="3"] {
  min-height: unset;
}

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(17, 24, 39, 0.12);
  outline-offset: 0;
  border-color: var(--text);
}

button:focus-visible {
  outline: 3px solid rgba(17, 24, 39, 0.12);
  outline-offset: 2px;
}

button {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

button[type="submit"] {
  border-color: var(--text);
  background: var(--text);
  color: #ffffff;
}

button:hover {
  background: #fafafa;
}

button[type="submit"]:hover {
  filter: brightness(0.95);
  background: var(--text);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Make common inline action buttons (e.g., Logout) feel consistent */
header button,
.container button {
  white-space: nowrap;
}

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

.table-wrap > table {
  min-width: 520px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #fafafa;
}

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

/* Analytics charts (GA4) */
.ga4-chart {
  width: 100%;
  height: 96px;
}

.ga4-chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.ga4-chart .ga4-line {
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
}

.ga4-chart .ga4-area {
  fill: var(--border);
  opacity: 0.35;
}

/* Code / JSON blocks */
code, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

pre {
  margin: 10px 0 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafafa;
  color: #0f172a;
  font-size: 12.5px;
  line-height: 1.4;
  overflow: auto;
  max-height: 520px;
}

details > summary {
  cursor: pointer;
  font-weight: 700;
}

details > summary:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

details[open] > summary {
  margin-bottom: 10px;
}

/* Small-screen spacing */
@media (max-width: 720px) {
  .container {
    padding: 14px;
  }

  .nav .row {
    gap: 8px;
  }

  .row {
    gap: 10px;
  }
}

ul {
  margin: 8px 0 0 0;
  padding-left: 18px;
}

li {
  margin: 6px 0;
}

/* Toasts */
.toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 10px;
  z-index: 1000;
}

.toast {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  max-width: 360px;
}

.toast-error {
  border: 1px solid rgba(185, 28, 28, 0.25);
  background: rgba(185, 28, 28, 0.06);
  color: var(--danger);
}
