/* ==========================================================================
   FileHost — custom lightweight CSS
   No frameworks. Design tokens + components. Light & dark via [data-theme].
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #101623;
  --muted: #5b6472;
  --border: #e3e8ef;
  --primary: #315efb;
  --primary-ink: #ffffff;
  --primary-soft: #e8edff;
  --accent: #0eb89d;
  --accent-soft: #dcf7f1;
  --warning: #d97706;
  --warning-soft: #fef3e2;
  --danger: #dc2626;
  --danger-soft: #fdeaea;
  --shadow: 0 1px 2px rgb(16 22 35 / .05), 0 4px 16px rgb(16 22 35 / .06);
  --shadow-lg: 0 8px 40px rgb(16 22 35 / .14);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 250px;
  --topbar-h: 60px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --grad: linear-gradient(120deg, #315efb, #0eb89d);
}

[data-theme="dark"] {
  --bg: #0b0e16;
  --surface: #131826;
  --surface-2: #1a2133;
  --ink: #e8ecf4;
  --muted: #8b94a7;
  --border: #232c40;
  --primary: #5b7dff;
  --primary-soft: #1c2647;
  --accent: #2dd4b8;
  --accent-soft: #10312c;
  --warning: #f59e0b;
  --warning-soft: #33240c;
  --danger: #f87171;
  --danger-soft: #3a1414;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
  --shadow-lg: 0 8px 40px rgb(0 0 0 / .5);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  transition: background-color .2s ease, color .2s ease;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; letter-spacing: -.02em; font-weight: 700; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
[x-cloak] { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Utility ---------- */
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85em; }
.num { font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: .5rem; } .mb-1 { margin-bottom: .5rem; }
.mt-2 { margin-top: 1rem; } .mb-2 { margin-bottom: 1rem; }
.mt-3 { margin-top: 1.5rem; } .mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; align-items: center; gap: .75rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px)  { .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 700px)  { .grid-2, .grid-4 { grid-template-columns: 1fr; } }
.text-center { text-align: center; }
.text-right { text-align: right; }
.hide-mobile { display: initial; }
@media (max-width: 800px) { .hide-mobile { display: none !important; } }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.05rem; color: var(--ink); letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  background: var(--grad);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .95rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1.05rem; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: .9rem; line-height: 1.2;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, opacity .15s ease;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { padding: .5rem; border-radius: var(--radius-sm); background: none; border: 0; color: var(--muted); cursor: pointer; display: inline-flex; }
.btn-icon:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-body { padding: 1.25rem; }
.card-header {
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
}
.card-header h2, .card-header h3 { margin: 0; }
.card-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); }

/* ---------- Stat cards ---------- */
.stat .card-body { display: flex; align-items: center; gap: 1rem; }
.stat-icon {
  width: 44px; height: 44px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 1.15rem;
  background: var(--primary-soft); color: var(--primary);
}
.stat-icon.accent { background: var(--accent-soft); color: var(--accent); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-label { font-size: .8rem; color: var(--muted); margin: 0; }
.stat-value { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; margin: 0; font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .55rem; border-radius: 999px;
  font-size: .74rem; font-weight: 700; letter-spacing: .01em;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--accent-soft); color: var(--accent); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--muted); }

/* ---------- Alerts ---------- */
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid transparent; margin-bottom: 1rem; }
.alert-success { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: .35rem; }
.field .hint { font-size: .78rem; color: var(--muted); margin-top: .3rem; }
.field .error { font-size: .78rem; color: var(--danger); margin-top: .3rem; }
.input, .select, .textarea {
  width: 100%; padding: .55rem .75rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: .92rem;
  transition: border-color .15s ease;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 110px; resize: vertical; }
.checkbox { display: flex; align-items: flex-start; gap: .5rem; font-size: .88rem; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin-top: .15rem; accent-color: var(--primary); }

/* Toggle switch — full-width state bar: green when on, red when off. */
.switch-title { display: block; font-size: .84rem; font-weight: 600; margin-bottom: .35rem; }
.switch { display: block; cursor: pointer; user-select: none; -webkit-user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch-bar {
  position: relative; display: flex; align-items: center; justify-content: center;
  height: 38px; border-radius: 6px; overflow: hidden;
  background: #cb1f2f; color: #ffffff; font-weight: 700; font-size: .88rem;
  transition: background-color .15s ease;
}
.switch-knob {
  position: absolute; top: 4px; bottom: 4px; left: 4px; width: 15px;
  border-radius: 4px; background: #16181d; transition: left .15s ease;
}
.switch input:checked + .switch-bar { background: #23a63c; }
.switch input:checked + .switch-bar .switch-knob { left: calc(100% - 19px); }
.switch-on { display: none; }
.switch input:checked + .switch-bar .switch-on { display: block; }
.switch input:checked + .switch-bar .switch-off { display: none; }
.switch input:focus-visible + .switch-bar { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; padding: .7rem 1rem;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: .8rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .actions { text-align: right; white-space: nowrap; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
.empty-icon {
  width: 52px; height: 52px; margin: 0 auto 1rem; border-radius: 14px;
  background: var(--surface-2); display: grid; place-items: center; font-size: 1.4rem;
}
.empty h3 { color: var(--ink); }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: .4rem;
}
.dropdown-item {
  display: flex; align-items: center; gap: .55rem; width: 100%;
  padding: .5rem .65rem; border-radius: 6px; border: 0; background: none;
  font: inherit; font-size: .88rem; color: var(--ink); cursor: pointer; text-align: left;
}
.dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-divider { height: 1px; background: var(--border); margin: .35rem 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgb(8 11 18 / .55);
  display: grid; place-items: center; padding: 1rem; backdrop-filter: blur(2px);
}
.modal {
  width: 100%; max-width: 480px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.modal-lg { max-width: 680px; }

/* ---------- Panel layout (admin + user) ---------- */
.panel { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 90;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform .2s ease;
}
.sidebar-head { height: var(--topbar-h); display: flex; align-items: center; padding: 0 1.1rem; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: .9rem .7rem; }
.nav-section { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); padding: .9rem .5rem .35rem; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: .65rem;
  padding: .55rem .65rem; margin-bottom: 2px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: .9rem; font-weight: 500;
}
.nav-link svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link.active::before {
  content: ""; position: absolute; left: -0.7rem; top: 20%; bottom: 20%; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--grad);
}
.sidebar-foot { padding: .9rem 1.1rem; border-top: 1px solid var(--border); font-size: .78rem; color: var(--muted); flex: 0 0 auto; }

.topbar {
  position: sticky; top: 0; z-index: 80; height: var(--topbar-h);
  margin-left: var(--sidebar-w);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem;
}
.topbar-search { flex: 1 1 auto; max-width: 420px; position: relative; }
.topbar-search .input { padding-left: 2.2rem; background: var(--surface-2); border-color: transparent; }
.topbar-search .input:focus { background: var(--surface); border-color: var(--primary); }
.topbar-search svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }

.content { margin-left: var(--sidebar-w); padding: 1.5rem; max-width: 1400px; }
.sidebar-overlay { display: none; }

@media (max-width: 1000px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .topbar, .content { margin-left: 0; }
  .sidebar-overlay { display: block; position: fixed; inset: 0; z-index: 85; background: rgb(8 11 18 / .45); }
  .content { padding: 1rem; }
}

/* ---------- Page header & breadcrumb ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.breadcrumb { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); margin-bottom: .3rem; flex-wrap: wrap; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { opacity: .5; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; }
.tab {
  padding: .6rem .9rem; font-size: .88rem; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Public site ---------- */
.site-header {
  position: sticky; top: 0; z-index: 80;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header-inner { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; height: 62px; display: flex; align-items: center; gap: 1rem; }
.site-nav { display: flex; gap: .25rem; margin-left: 1rem; }
.site-nav a { padding: .45rem .7rem; border-radius: var(--radius-sm); color: var(--muted); font-size: .9rem; font-weight: 500; }
.site-nav a:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.site-nav a.active { color: var(--primary); }
@media (max-width: 800px) { .site-nav { display: none; } }

.hero {
  position: relative; text-align: center; padding: 5rem 1.25rem 4rem; overflow: hidden;
  background-image: radial-gradient(color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1px);
  background-size: 22px 22px;
}
.hero::after {
  content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  width: min(720px, 90%); height: 3px; background: var(--grad); border-radius: 999px; opacity: .9;
}
.hero h1 { font-size: clamp(2rem, 5vw, 3.1rem); letter-spacing: -.03em; margin-bottom: .75rem; }
.hero h1 .grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { max-width: 560px; margin: 0 auto 1.75rem; color: var(--muted); font-size: 1.05rem; }

.section { max-width: 1100px; margin: 0 auto; padding: 3rem 1.25rem; }
.section-narrow { max-width: 760px; }
.feature { padding: 1.4rem; }
.feature-icon {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); margin-bottom: .8rem; font-size: 1.1rem;
}

.site-footer { border-top: 1px solid var(--border); padding: 2.5rem 1.25rem; margin-top: 3rem; }
.site-footer-inner { max-width: 1100px; margin: 0 auto; display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.site-footer a { color: var(--muted); margin-right: 1rem; }
.site-footer a:hover { color: var(--primary); }

/* ---------- Auth & installer shells ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; margin-bottom: 1.5rem; }
.installer-card { max-width: 640px; }
.steps { display: flex; gap: .35rem; margin-bottom: 1.5rem; }
.step-dot { height: 5px; flex: 1; border-radius: 999px; background: var(--border); }
.step-dot.done { background: var(--grad); }

/* ---------- FAQ ---------- */
.faq-item { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); margin-bottom: .6rem; }
.faq-q {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .9rem 1.1rem; background: none; border: 0; font: inherit; font-weight: 600; color: var(--ink);
  cursor: pointer; text-align: left;
}
.faq-a { padding: 0 1.1rem .9rem; color: var(--muted); font-size: .92rem; }

/* ---------- Error pages ---------- */
.error-wrap { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 1.5rem; }
.error-code { font-size: 5rem; font-weight: 800; letter-spacing: -.04em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1; margin-bottom: .5rem; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); border: 0; margin: 1.25rem 0; }
.kbd { font-family: var(--mono); font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: .1rem .4rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 700; flex: 0 0 auto; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; border-radius: 999px; background: var(--grad); }
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 3rem 1.5rem;
  text-align: center; color: var(--muted); background: var(--surface-2);
  transition: border-color .15s ease;
}
.upload-zone:hover, .upload-zone.drag { border-color: var(--primary); }
.check-ok { color: var(--accent); font-weight: 700; }
.check-fail { color: var(--danger); font-weight: 700; }

/* Sidebar toggle button — mobile: off-canvas open, desktop: collapse. */
.menu-btn { display: inline-flex; }

/* ---------- Desktop sidebar collapse ---------- */
@media (min-width: 1001px) {
  .panel.sidebar-collapsed .sidebar { transform: translateX(-100%); }
  .panel.sidebar-collapsed .topbar,
  .panel.sidebar-collapsed .content { margin-left: 0; }
}

/* ---------- Sidebar nav groups (drop-downs) ---------- */
.nav-group-btn {
  width: 100%; background: none; border: 0; cursor: pointer; text-align: left; font: inherit;
}
.nav-group-btn .chev { margin-left: auto; transition: transform .15s ease; }
.nav-group-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.nav-sub { padding-left: 1.55rem; margin: 1px 0 3px; }
.nav-sub .nav-link { padding: .42rem .6rem; font-size: .86rem; }


/* ---------- Color manager ---------- */
.color-swatch {
  width: 44px; height: 36px; padding: 2px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
}


/* ---------- Toasts ---------- */
.toasts {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 200;
  display: flex; flex-direction: column; gap: .5rem; max-width: 340px; width: calc(100% - 2rem);
}
.toast {
  display: flex; align-items: flex-start; gap: .6rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: .7rem .9rem; font-size: .88rem;
  animation: toast-in .18s ease;
}
.toast-success { border-left-color: #23a63c; }
.toast-danger  { border-left-color: #cb1f2f; }
.toast-info    { border-left-color: var(--primary); }
.toast .btn-icon { margin-left: auto; padding: .1rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }