:root {
  /* Light theme (default) */
  --bg: #f5f7fb;
  --ink: #0f172a;
  --muted: #64748b;
  --brand: #f1f5f9;
  --brand-ink: #0f172a;
  --accent: #5a83b8;
  --accent-hover: #4a6fa0;
  --border: #cbd5e1;
  --soft: #f8fafc;
  --card: #ffffff;
  --error-bg: #fef2f2;
  --error-border: #fca5a5;
  --error-ink: #991b1b;
  --success-bg: #f0fdf4;
  --success-border: #86efac;
  --success-ink: #166534;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);

  /* Slider colors — vary slightly between themes */
  --switch-track: #cbd5e1;
  --switch-thumb: #ffffff;
  --switch-sun: #f59e0b;
  --switch-moon: #64748b;
}

:root[data-theme="dark"] {
  --bg: #0a0e1a;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  /* --brand and --brand-ink inherit from :root and are overridden by
     applyBranding() based on the user-chosen header color. */
  --border: #334155;
  --soft: #1e293b;
  --card: #1e293b;
  --error-bg: #2a0a0a;
  --error-border: #7f1d1d;
  --error-ink: #fca5a5;
  --success-bg: #0a2a14;
  --success-border: #166534;
  --success-ink: #86efac;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.5);

  --switch-track: #334155;
  --switch-thumb: #e2e8f0;
  --switch-sun: #94a3b8;
  --switch-moon: #fde047;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  transition: background 0.2s, color 0.2s;
}

/* Header */
header.topbar {
  background: var(--brand); color: var(--brand-ink);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
header.topbar a.brand {
  color: var(--accent); text-decoration: none;
  font-size: 18px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 10px;
}
header.topbar a.brand:hover { opacity: 0.85; }
header.topbar a.brand img {
  height: 32px; width: auto; max-width: 160px;
  display: block;
}
header.topbar .right {
  display: flex; align-items: center; gap: 14px; font-size: 13px;
}
header.topbar .user { color: var(--brand-ink); opacity: 0.65; }
header.topbar a.muted { color: var(--brand-ink); opacity: 0.65; text-decoration: none; }
header.topbar a.muted:hover { opacity: 1; }

/* ---- Theme slider — sun + moon icons on the track, thumb slides ---- */

.theme-switch {
  position: relative;
  display: inline-block;
  width: 56px;
  height: 28px;
  cursor: pointer;
  flex-shrink: 0;
}
.theme-switch input {
  opacity: 0; width: 0; height: 0;
  position: absolute;
}
.theme-switch .track {
  position: absolute; inset: 0;
  background: var(--switch-track);
  border-radius: 28px;
  transition: background 0.2s;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 7px;
}
.theme-switch .icon {
  width: 14px; height: 14px;
  display: flex; align-items: center; justify-content: center;
  z-index: 1; pointer-events: none;
}
.theme-switch .icon.sun { color: var(--switch-sun); }
.theme-switch .icon.moon { color: var(--switch-moon); }
.theme-switch .icon svg { width: 100%; height: 100%; }
.theme-switch .thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  background: var(--switch-thumb);
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  z-index: 2;
}
.theme-switch input:checked ~ .track .thumb {
  transform: translateX(28px);
}

/* Breadcrumb */
nav.crumbs {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 10px 24px; font-size: 13px; color: var(--muted);
}
nav.crumbs a { color: var(--muted); text-decoration: none; }
nav.crumbs a:hover { color: var(--ink); }
nav.crumbs .sep { margin: 0 6px; color: var(--border); }
nav.crumbs .here { color: var(--ink); font-weight: 500; }

/* Main column */
main { max-width: 900px; margin: 40px auto; padding: 0 16px; }
main.narrow { max-width: 640px; }
h2 { margin: 0 0 8px; font-size: 22px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 24px; }

.card {
  background: var(--card); padding: 28px; border-radius: 10px;
  box-shadow: var(--shadow);
}

button, .btn {
  background: var(--accent); color: white; border: none;
  padding: 12px 24px; border-radius: 6px; font-weight: 600;
  cursor: pointer; font-size: 14px; text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { background: var(--accent-hover); filter: brightness(0.92); }
button:disabled { background: var(--border); cursor: not-allowed; filter: none; }

.alert {
  padding: 12px 14px; border-radius: 6px;
  margin-bottom: 16px; font-size: 14px;
}
.alert-error {
  background: var(--error-bg); border: 1px solid var(--error-border);
  color: var(--error-ink);
}
.alert-success {
  background: var(--success-bg); border: 1px solid var(--success-border);
  color: var(--success-ink);
}

details { margin-top: 18px; font-size: 13px; }
summary { cursor: pointer; color: var(--muted); }
pre {
  background: #0f172a; color: #cbd5e1; padding: 12px;
  border-radius: 6px; overflow: auto; max-height: 320px;
  font-size: 12px; white-space: pre-wrap;
}

/* Landing — tool grid */
.tool-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.tool {
  background: var(--card); border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 22px; display: flex; flex-direction: column;
  transition: 0.15s; text-decoration: none; color: inherit;
}
.tool:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.tool .name { font-size: 17px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.tool .desc { color: var(--muted); font-size: 14px; line-height: 1.5; flex-grow: 1; }
.tool .open { margin-top: 16px; color: var(--accent); font-size: 13px; font-weight: 600; }

/* Tool pages — drop zone */
.drop {
  border: 2px dashed var(--border); border-radius: 8px;
  padding: 32px; text-align: center; color: var(--muted);
  background: var(--soft); cursor: pointer; transition: 0.15s;
  display: block;
}
.drop.hover { border-color: var(--accent); color: var(--accent); }
.drop input { display: none; }
.filename { font-weight: 600; color: var(--ink); margin-top: 12px; }
.opts { margin: 16px 0; font-size: 14px; }
.opts label { display: inline-flex; align-items: center; gap: 6px; }

/* Admin form */
.form-row { margin-bottom: 20px; }
.form-row label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--ink); margin-bottom: 8px;
}
.form-row .desc { font-size: 12px; color: var(--muted); margin-top: 4px; }
.color-row {
  display: flex; align-items: center; gap: 12px;
}
.color-row input[type="color"] {
  width: 48px; height: 36px; border: 1px solid var(--border);
  border-radius: 6px; padding: 2px; cursor: pointer; background: var(--card);
}
.color-row input[type="text"] {
  background: var(--soft); border: 1px solid var(--border);
  color: var(--ink); padding: 8px 12px; border-radius: 6px;
  font-family: monospace; font-size: 14px; width: 100px;
}
.logo-preview {
  display: flex; align-items: center; gap: 16px; margin-top: 8px;
  padding: 14px; background: var(--soft); border-radius: 6px;
  border: 1px solid var(--border);
}
.logo-preview img { max-height: 48px; max-width: 200px; display: block; }
.logo-preview .none { color: var(--muted); font-size: 13px; font-style: italic; }
.meta { font-size: 12px; color: var(--muted); margin-top: 16px; }
.meta code { font-family: monospace; color: var(--ink); }

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

body.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--bg) 0%, var(--soft) 100%);
}
.login-theme-corner {
  position: fixed; top: 20px; right: 24px;
}
.login-wrap {
  max-width: 420px; margin: 0 auto; padding: 16px;
  width: 100%;
}
.login-card {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow-hover);
  padding: 40px 32px;
  text-align: center;
}
.login-brand {
  margin-bottom: 14px;
  min-height: 48px;
  display: flex; align-items: center; justify-content: center;
}
.login-brand img {
  max-height: 64px; max-width: 240px; display: block;
}
.login-brand-text {
  color: var(--accent);
  font-size: 26px; font-weight: 700; letter-spacing: -0.02em;
}
.login-hint {
  color: var(--muted); font-size: 14px;
  margin: 0 0 28px;
}
.login-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 12px 22px;
  background: var(--accent);
}
.login-btn:hover { background: var(--accent-hover); }
.login-btn svg { display: block; }
