/* ==========================================================================
   Project Vault — admin panel design system
   shadcn/ui-inspired tokens, Geist typography, light + dark themes.
   ========================================================================== */

:root {
  --radius: 0.65rem;
  --radius-sm: calc(var(--radius) - 0.25rem);
  --radius-lg: calc(var(--radius) + 0.25rem);

  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "JetBrains Mono", "Cascadia Code", monospace;

  /* light theme (default) */
  --background: hsl(0 0% 100%);
  --foreground: hsl(240 10% 3.9%);
  --muted: hsl(240 4.8% 95.9%);
  --muted-foreground: hsl(240 3.8% 46.1%);
  --card: hsl(0 0% 100%);
  --card-foreground: hsl(240 10% 3.9%);
  --popover: hsl(0 0% 100%);
  --border: hsl(240 5.9% 90%);
  --input: hsl(240 5.9% 90%);
  --ring: hsl(240 10% 3.9%);
  --primary: hsl(240 5.9% 10%);
  --primary-foreground: hsl(0 0% 98%);
  --secondary: hsl(240 4.8% 95.9%);
  --secondary-foreground: hsl(240 5.9% 10%);
  --accent: hsl(240 4.8% 95.9%);
  --accent-foreground: hsl(240 5.9% 10%);
  --destructive: hsl(0 72% 45%);
  --destructive-foreground: hsl(0 0% 98%);
  --success: hsl(142 66% 34%);
  --warning: hsl(35 92% 38%);
  --info: hsl(262 70% 52%);
  --sidebar: hsl(240 5% 98%);
  --sidebar-border: hsl(240 5.9% 90%);
  --shadow-sm: 0 1px 2px 0 hsl(240 10% 3.9% / 0.06);
  --shadow: 0 1px 3px 0 hsl(240 10% 3.9% / 0.08), 0 1px 2px -1px hsl(240 10% 3.9% / 0.08);
  --shadow-lg: 0 10px 30px -12px hsl(240 10% 3.9% / 0.22);
}

.dark {
  --background: hsl(240 10% 3.9%);
  --foreground: hsl(0 0% 98%);
  --muted: hsl(240 3.7% 15.9%);
  --muted-foreground: hsl(240 5% 64.9%);
  --card: hsl(240 6% 7%);
  --card-foreground: hsl(0 0% 98%);
  --popover: hsl(240 6% 8%);
  --border: hsl(240 3.7% 17%);
  --input: hsl(240 3.7% 20%);
  --ring: hsl(240 4.9% 83.9%);
  --primary: hsl(0 0% 98%);
  --primary-foreground: hsl(240 5.9% 10%);
  --secondary: hsl(240 3.7% 15.9%);
  --secondary-foreground: hsl(0 0% 98%);
  --accent: hsl(240 3.7% 15.9%);
  --accent-foreground: hsl(0 0% 98%);
  --destructive: hsl(0 72% 58%);
  --destructive-foreground: hsl(0 0% 98%);
  --success: hsl(142 60% 55%);
  --warning: hsl(38 92% 60%);
  --info: hsl(262 80% 74%);
  --sidebar: hsl(240 7% 5.5%);
  --sidebar-border: hsl(240 3.7% 15%);
  --shadow-sm: 0 1px 2px 0 hsl(0 0% 0% / 0.4);
  --shadow: 0 1px 3px 0 hsl(0 0% 0% / 0.5);
  --shadow-lg: 0 16px 40px -16px hsl(0 0% 0% / 0.7);
}

* { box-sizing: border-box; }
::selection { background: var(--foreground); color: var(--background); }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 0.98rem; }
p { margin: 0; }
code { font-family: var(--font-mono); font-size: 0.82em; }
small { font-size: 0.8rem; }

.muted { color: var(--muted-foreground); }
.nowrap { white-space: nowrap; }
.truncate { max-width: 150px; display: inline-block; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; white-space: nowrap; }

/* ------------------------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.15rem 0.85rem;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 0.7rem; padding: 0.25rem 0.4rem 0.5rem; }
.brand strong { display: block; font-size: 0.9rem; font-weight: 600; letter-spacing: -0.01em; }
.brand small { display: block; color: var(--muted-foreground); font-size: 0.75rem; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: none;
  border-radius: var(--radius);
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.03em;
  background: var(--primary); color: var(--primary-foreground);
  box-shadow: var(--shadow-sm);
}
.brand-mark.large { width: 46px; height: 46px; border-radius: var(--radius-lg); font-size: 0.95rem; margin: 0 auto 0.9rem; }

.nav-label {
  padding: 0 0.6rem;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted-foreground);
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500;
  color: var(--muted-foreground);
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar nav a svg { width: 16px; height: 16px; flex: none; opacity: 0.85; }
.sidebar nav a:hover { background: var(--accent); color: var(--accent-foreground); }
.sidebar nav a.active {
  background: var(--card); color: var(--foreground); font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-sm);
}
.sidebar nav a.external { margin-top: 0.35rem; font-size: 0.8rem; }

.who {
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card);
}
.who strong { font-size: 0.83rem; font-weight: 600; }
.who small { display: block; color: var(--muted-foreground); font-size: 0.72rem; text-transform: capitalize; }

/* ----------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  height: 56px; padding: 0 1.75rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--background) 82%, transparent);
  backdrop-filter: blur(10px);
}
.crumbs { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; color: var(--muted-foreground); }
.crumbs strong { color: var(--foreground); font-weight: 600; }
.crumbs .sep { opacity: 0.5; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); color: var(--foreground);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--accent); }
.icon-btn svg { width: 16px; height: 16px; }
.theme-toggle .sun { display: none; }
.dark .theme-toggle .sun { display: block; }
.dark .theme-toggle .moon { display: none; }

.content { padding: 0 0 4rem; max-width: 100%; }
.content > *:not(.topbar) { margin-left: auto; margin-right: auto; max-width: 1280px; padding-left: 1.75rem; padding-right: 1.75rem; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1.25rem;
  padding-top: 1.75rem; padding-bottom: 1.25rem;
}
.page-head p { margin-top: 0.25rem; font-size: 0.875rem; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card > h2 { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.card > h2 + .card-sub { margin-bottom: 1rem; font-size: 0.82rem; color: var(--muted-foreground); }
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  margin: -1.25rem -1.25rem 1rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; }
.card-head .card-sub { margin-top: 0.2rem; font-size: 0.8rem; color: var(--muted-foreground); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { margin: 0; }
.card.flush table { margin: 0; }

.grid { display: grid; gap: 1.25rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.grid.sidebar-right { grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr); align-items: start; }
section.grid { margin-bottom: 1.25rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 0.85rem; margin-bottom: 1.25rem; }
.stat {
  padding: 1rem 1.1rem;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}
.stat small { display: block; color: var(--muted-foreground); font-size: 0.75rem; font-weight: 500; letter-spacing: 0.01em; }
.stat strong { display: block; margin-top: 0.35rem; font-size: 1.65rem; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

.row { display: flex; align-items: center; gap: 0.6rem; }
.row.between { justify-content: space-between; padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
.row.between:last-child { border-bottom: none; padding-bottom: 0; }
.row.end { justify-content: flex-end; }
.row.gap { gap: 0.6rem; margin-bottom: 1rem; align-items: flex-start; }

/* ----------------------------------------------------------------- tables */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted-foreground); background: color-mix(in srgb, var(--muted) 55%, transparent);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--muted) 60%, transparent); }
td form { display: inline-block; margin-left: 0.35rem; }
td strong { font-weight: 600; }

.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--secondary); color: var(--secondary-foreground);
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.01em;
}
.pill.ok { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); background: color-mix(in srgb, var(--success) 12%, transparent); }
.pill.warn { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 40%, transparent); background: color-mix(in srgb, var(--warning) 12%, transparent); }
.pill.level-beginner { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); background: color-mix(in srgb, var(--success) 12%, transparent); }
.pill.level-intermediate { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 40%, transparent); background: color-mix(in srgb, var(--warning) 12%, transparent); }
.pill.level-advanced { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); background: color-mix(in srgb, var(--info) 12%, transparent); }

/* ------------------------------------------------------------------ forms */
label {
  display: block; margin-bottom: 1rem;
  font-size: 0.82rem; font-weight: 500; color: var(--foreground);
}
label small { font-weight: 400; }
label.checkbox {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: color-mix(in srgb, var(--muted) 45%, transparent);
}
label.checkbox input { width: auto; margin: 0.15rem 0 0; accent-color: var(--primary); }

input, select, textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.7rem;
  font-family: var(--font-sans); font-size: 0.875rem;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted-foreground) 85%, transparent); }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--ring) 45%, var(--input)); }
input:focus, select:focus, textarea:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 18%, transparent);
}
select { appearance: none; padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
textarea { resize: vertical; line-height: 1.6; }
textarea.mono { font-family: var(--font-mono); font-size: 0.8rem; }
input[type="file"] { padding: 0.35rem; color: var(--muted-foreground); font-size: 0.8rem; }
input[type="file"]::file-selector-button {
  margin-right: 0.6rem; padding: 0.3rem 0.7rem;
  font-family: var(--font-sans); font-size: 0.78rem; font-weight: 600;
  color: var(--secondary-foreground); background: var(--secondary);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}

.filters { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; padding: 0.85rem; }
.filters input, .filters select { margin-top: 0; width: auto; min-width: 190px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  font-family: var(--font-sans); font-size: 0.85rem; font-weight: 500;
  color: var(--foreground); background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--accent); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 22%, transparent); }
.btn.primary { background: var(--primary); color: var(--primary-foreground); border-color: transparent; font-weight: 600; }
.btn.primary:hover { opacity: 0.9; background: var(--primary); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted-foreground); }
.btn.ghost:hover { background: var(--accent); color: var(--accent-foreground); }
.btn.danger { color: var(--destructive); border-color: color-mix(in srgb, var(--destructive) 35%, transparent); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--destructive) 12%, transparent); }
.btn.small { padding: 0.28rem 0.6rem; font-size: 0.78rem; }
.btn.block { width: 100%; margin-top: 0.25rem; }

.alert {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.75rem 0.9rem; margin-bottom: 1.1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.86rem; background: var(--card);
}
.alert.ok { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); background: color-mix(in srgb, var(--success) 10%, transparent); }
.alert.error { color: var(--destructive); border-color: color-mix(in srgb, var(--destructive) 35%, transparent); background: color-mix(in srgb, var(--destructive) 10%, transparent); }

/* ------------------------------------------------------------------- auth */
body.auth {
  display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(70rem 40rem at 50% -20%, color-mix(in srgb, var(--foreground) 6%, transparent), transparent 70%),
    var(--background);
}
.auth-card {
  width: min(400px, 94vw);
  padding: 2rem;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius-lg) + 0.25rem);
  box-shadow: var(--shadow-lg);
}
.auth-card h1 { font-size: 1.2rem; }
.auth-card p { margin: 0.35rem 0 1.5rem; font-size: 0.85rem; }
.auth-card label { text-align: left; }
.auth-foot { margin-top: 1.25rem; font-size: 0.75rem; color: var(--muted-foreground); }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar .who { margin-top: 1rem; }
  .topbar { padding: 0 1rem; }
  .content > *:not(.topbar) { padding-left: 1rem; padding-right: 1rem; }
  .grid.sidebar-right { grid-template-columns: 1fr; }
}
