/* ==========================================================================
   Workshop — design system
   --------------------------------------------------------------------------
   One stylesheet, no external requests. The palette is defined as custom
   properties so the light/dark themes are a single attribute swap on <html>
   (set by static/js/app.js) rather than duplicated rules.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* Brand */
  --brand-50: #eef4ff;
  --brand-100: #dbe6ff;
  --brand-200: #bdd0ff;
  --brand-300: #90b0ff;
  --brand-400: #5b86fb;
  --brand-500: #3563e9;
  --brand-600: #2549c4;
  --brand-700: #1f3b9c;

  /* Neutrals */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #080f1e;

  /* Semantic */
  --success-50: #ecfdf5;
  --success-100: #d1fae5;
  --success-500: #059669;
  --success-600: #047857;
  --warning-50: #fffbeb;
  --warning-100: #fef3c7;
  --warning-500: #d97706;
  --warning-600: #b45309;
  --danger-50: #fef2f2;
  --danger-100: #fee2e2;
  --danger-500: #dc2626;
  --danger-600: #b91c1c;

  /* Surfaces */
  --bg-app: var(--slate-100);
  --bg-surface: #ffffff;
  --bg-surface-alt: var(--slate-50);
  --bg-sidebar: var(--slate-900);
  --bg-sidebar-hover: rgba(255, 255, 255, 0.08);
  --bg-topbar: rgba(255, 255, 255, 0.85);
  --bg-inset: var(--slate-100);

  /* Text */
  --text-primary: var(--slate-900);
  --text-secondary: var(--slate-600);
  --text-muted: var(--slate-500);
  --text-inverse: #ffffff;
  --text-sidebar: rgba(255, 255, 255, 0.78);
  --text-sidebar-active: #ffffff;

  /* Lines */
  --border: var(--slate-200);
  --border-strong: var(--slate-300);
  --border-sidebar: rgba(255, 255, 255, 0.08);

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.18);

  /* Layout */
  --sidebar-width: 264px;
  --topbar-height: 62px;
  --content-max: 1440px;

  /* Typography */
  --font-sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --focus-ring: 0 0 0 3px rgba(53, 99, 233, 0.35);
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg-app: #060b16;
  --bg-surface: #101827;
  --bg-surface-alt: #16203300;
  --bg-inset: #1a2437;
  --bg-sidebar: #080e1b;
  --bg-topbar: rgba(16, 24, 39, 0.85);

  --text-primary: #eef2f8;
  --text-secondary: #b3c0d4;
  --text-muted: #8494ac;

  --border: #22304a;
  --border-strong: #2f3f5c;

  --slate-50: #101827;
  --slate-100: #16203a;
  --slate-200: #22304a;

  --brand-50: #14213d;
  --brand-100: #1a2c55;
  --danger-50: #2a1417;
  --danger-100: #3d1b1f;
  --success-50: #0f2620;
  --success-100: #14352c;
  --warning-50: #2a2113;
  --warning-100: #3a2d15;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 22px 48px rgba(0, 0, 0, 0.6);
}

/* --------------------------------------------------------------------------
   2. Reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 0.4em;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 1em; }

a {
  color: var(--brand-600);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

img, svg { max-width: 100%; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

code, kbd, pre, .mono {
  font-family: var(--font-mono);
  font-size: 0.86em;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--brand-600);
  color: #fff;
  border-radius: var(--radius);
  transition: top 0.15s ease;
}

.skip-link:focus { top: 1rem; }

/* --------------------------------------------------------------------------
   3. App shell
   -------------------------------------------------------------------------- */
.app {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  z-index: 40;
  transition: transform 0.22s ease;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  height: var(--topbar-height);
  padding: 0 1.15rem;
  border-bottom: 1px solid var(--border-sidebar);
  color: #fff;
  flex: 0 0 auto;
}

.sidebar__brand:hover { text-decoration: none; }

.sidebar__brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  color: #fff;
  flex: 0 0 auto;
}

.sidebar__brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar__brand-name { font-weight: 700; font-size: 0.98rem; letter-spacing: -0.01em; }
.sidebar__brand-sub { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.6; }

.sidebar__nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.9rem 0.7rem 1.4rem;
}

.sidebar__section {
  margin: 1.1rem 0 0.35rem;
  padding: 0 0.55rem;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.38);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.6rem;
  border-radius: var(--radius);
  color: var(--text-sidebar);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.13s ease, color 0.13s ease;
}

.sidebar__link:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-sidebar-active);
  text-decoration: none;
}

.sidebar__link.is-active {
  background: linear-gradient(90deg, var(--brand-600), rgba(37, 73, 196, 0.35));
  color: var(--text-sidebar-active);
  box-shadow: inset 2px 0 0 var(--brand-300);
}

.sidebar__link .icon { flex: 0 0 auto; opacity: 0.9; }

.sidebar__footer {
  flex: 0 0 auto;
  padding: 0.8rem 0.9rem 1rem;
  border-top: 1px solid var(--border-sidebar);
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.45);
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  margin-bottom: 0.6rem;
}

.sidebar__user-name { font-size: 0.83rem; font-weight: 600; color: #fff; }
.sidebar__user-meta { font-size: 0.7rem; color: rgba(255, 255, 255, 0.55); }

.app__main {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  height: var(--topbar-height);
  padding: 0 1.25rem;
  background: var(--bg-topbar);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar__toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
}

.topbar__title-block { min-width: 0; }
.topbar__eyebrow {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.topbar__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__spacer { flex: 1 1 auto; }
.topbar__actions { display: flex; align-items: center; gap: 0.5rem; }

.env-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--warning-100);
  color: var(--warning-600);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Language switcher: compact select in the topbar, right-aligned on auth pages */
.lang-switcher { display: inline-flex; align-items: center; }
.lang-switcher__select {
  width: auto;
  min-width: 7.5rem;
  padding: 0.32rem 1.85rem 0.32rem 0.6rem;
  font-size: 0.8rem;
}

.content {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 1.4rem 1.5rem 3rem;
}

.footer {
  padding: 0.9rem 1.5rem 1.4rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 15, 30, 0.55);
  z-index: 35;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

body.is-sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

/* --------------------------------------------------------------------------
   4. Avatars
   -------------------------------------------------------------------------- */
.avatar {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  flex: 0 0 auto;
  overflow: hidden;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 28px; height: 28px; font-size: 0.66rem; }
.avatar--lg { width: 64px; height: 64px; font-size: 1.25rem; }
.avatar--xl { width: 88px; height: 88px; font-size: 1.6rem; }

/* --------------------------------------------------------------------------
   5. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.87rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.13s ease, border-color 0.13s ease, transform 0.08s ease,
    box-shadow 0.13s ease;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: var(--brand-600);
  color: #fff;
  box-shadow: var(--shadow-xs);
}
.btn--primary:hover { background: var(--brand-700); color: #fff; }

.btn--secondary {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.btn--secondary:hover { background: var(--bg-inset); }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn--ghost:hover { background: var(--bg-inset); color: var(--text-primary); }

.btn--danger {
  background: var(--danger-500);
  color: #fff;
}
.btn--danger:hover { background: var(--danger-600); color: #fff; }

.btn--danger-ghost {
  background: transparent;
  border-color: var(--danger-100);
  color: var(--danger-600);
}
.btn--danger-ghost:hover { background: var(--danger-50); }

.btn--success { background: var(--success-500); color: #fff; }
.btn--success:hover { background: var(--success-600); color: #fff; }

.btn--sm { padding: 0.32rem 0.62rem; font-size: 0.79rem; }
.btn--lg { padding: 0.7rem 1.3rem; font-size: 0.95rem; }
.btn--block { width: 100%; }
.btn--icon { padding: 0.42rem; width: 34px; height: 34px; }

.btn-group { display: inline-flex; gap: 0.4rem; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   6. Cards and layout helpers
   -------------------------------------------------------------------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: 1.1rem; }

.card__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.95rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.card__title { margin: 0; font-size: 0.98rem; font-weight: 650; }
.card__subtitle { margin: 0.15rem 0 0; font-size: 0.78rem; color: var(--text-muted); }
.card__header-actions { margin-left: auto; display: flex; align-items: center; gap: 0.4rem; }
.card__body { padding: 1.15rem; }
.card__body--flush { padding: 0; }
.card__footer {
  padding: 0.8rem 1.15rem;
  border-top: 1px solid var(--border);
  background: var(--bg-surface-alt);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.grid { display: grid; gap: 1.1rem; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }

.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.row { display: flex; align-items: center; gap: 0.6rem; }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.row--end { margin-left: auto; }
.spacer { flex: 1 1 auto; }

.page-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

.page-header__title { margin: 0; font-size: 1.45rem; }
.page-header__meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.3rem;
  color: var(--text-muted);
  font-size: 0.83rem;
}
.page-header__actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 0.83rem; }
.text-xs { font-size: 0.74rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }
.text-danger { color: var(--danger-600); }
.text-success { color: var(--success-600); }
.text-warning { color: var(--warning-600); }
.fw-600 { font-weight: 600; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 1rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------------------
   7. Stat cards
   -------------------------------------------------------------------------- */
.stat {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem 1.1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform 0.13s ease, box-shadow 0.13s ease;
}

a.stat:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat__icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--brand-50);
  color: var(--brand-600);
  flex: 0 0 auto;
}

.stat__icon--success { background: var(--success-50); color: var(--success-600); }
.stat__icon--warning { background: var(--warning-50); color: var(--warning-600); }
.stat__icon--danger { background: var(--danger-50); color: var(--danger-600); }
.stat__body { min-width: 0; }
.stat__value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.stat__label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   8. Badges, counters, chips
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.16rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.73rem;
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
  background: var(--bg-inset);
  color: var(--text-secondary);
}

.badge--neutral { background: var(--bg-inset); color: var(--text-secondary); }
.badge--info { background: var(--brand-100); color: var(--brand-700); }
.badge--primary { background: var(--brand-600); color: #fff; }
.badge--success { background: var(--success-100); color: var(--success-600); }
.badge--warning { background: var(--warning-100); color: var(--warning-600); }
.badge--danger { background: var(--danger-100); color: var(--danger-600); }

.counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--bg-inset);
  color: var(--text-secondary);
}
.counter--success { background: var(--success-100); color: var(--success-600); }
.counter--warning { background: var(--warning-100); color: var(--warning-600); }
.counter--danger { background: var(--danger-100); color: var(--danger-600); }
.counter--info { background: var(--brand-100); color: var(--brand-700); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-surface-alt);
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.chip__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex: 0 0 auto;
}

.dot-indicator {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: var(--radius-full);
  flex: 0 0 auto;
}

/* --------------------------------------------------------------------------
   9. Tables
   -------------------------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.table caption {
  padding: 0.5rem 1rem;
  text-align: left;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}

.table th a { color: inherit; display: inline-flex; align-items: center; gap: 0.25rem; }
.table th a:hover { color: var(--brand-600); text-decoration: none; }
.table th a.is-sorted { color: var(--brand-600); }

.table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:hover { background: var(--bg-surface-alt); }
.table tbody tr:last-child td { border-bottom: 0; }
.table__actions { text-align: right; white-space: nowrap; }
.table__num { text-align: right; font-variant-numeric: tabular-nums; }

.table--compact td, .table--compact th { padding: 0.45rem 0.65rem; }

/* --------------------------------------------------------------------------
   10. Definition lists
   -------------------------------------------------------------------------- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.2rem 1.5rem;
}

.detail {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.6rem 0;
  border-bottom: 1px dashed var(--border);
  min-width: 0;
}

.detail__label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.detail__value { font-size: 0.9rem; word-break: break-word; }
.detail__value--empty { color: var(--text-muted); font-style: italic; }

/* --------------------------------------------------------------------------
   11. Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 0.15rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  padding: 0 0.4rem;
  background: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.tabs__link {
  padding: 0.75rem 0.85rem;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.87rem;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.tabs__link:hover { color: var(--text-primary); text-decoration: none; }
.tabs__link.is-active {
  color: var(--brand-600);
  border-bottom-color: var(--brand-600);
}

.tab-panel[hidden] { display: none; }

/* --------------------------------------------------------------------------
   12. Forms
   -------------------------------------------------------------------------- */
.form { display: block; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.field { display: flex; flex-direction: column; gap: 0.32rem; min-width: 0; }
.field--full { grid-column: 1 / -1; }

.field__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field__label .required { color: var(--danger-500); margin-left: 0.15rem; }
.field__help { font-size: 0.76rem; color: var(--text-muted); }
.field__error {
  display: flex;
  gap: 0.35rem;
  align-items: flex-start;
  font-size: 0.78rem;
  color: var(--danger-600);
  font-weight: 500;
}
.field--error input,
.field--error select,
.field--error textarea { border-color: var(--danger-500); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="tel"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.88rem;
  transition: border-color 0.13s ease, box-shadow 0.13s ease;
}

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

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: var(--focus-ring);
}

input[type="checkbox"], input[type="radio"] {
  width: 17px;
  height: 17px;
  accent-color: var(--brand-600);
  vertical-align: -3px;
}

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.55rem 0;
}

.checkbox-field label { font-size: 0.88rem; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.2rem;
  margin: 0 0 1.2rem;
}

legend {
  padding: 0 0.45rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1.3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
}

.filter-bar .field { flex: 1 1 170px; }
.filter-bar__search { flex: 2 1 260px; }

.search-field { position: relative; }
.search-field .icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-field input { padding-left: 2.1rem; }

.form-errors {
  padding: 0.8rem 1rem;
  border: 1px solid var(--danger-100);
  border-left: 3px solid var(--danger-500);
  border-radius: var(--radius);
  background: var(--danger-50);
  color: var(--danger-600);
  margin-bottom: 1.1rem;
  font-size: 0.85rem;
}

.form-errors ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }

.help-text-list { margin: 0; padding-left: 1.15rem; font-size: 0.78rem; color: var(--text-muted); }

/* --------------------------------------------------------------------------
   13. Alerts and toasts
   -------------------------------------------------------------------------- */
.alert {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.75rem 0.95rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--slate-400);
  border-radius: var(--radius);
  background: var(--bg-surface);
  font-size: 0.86rem;
  margin-bottom: 0.7rem;
}

.alert--success { border-left-color: var(--success-500); background: var(--success-50); color: var(--success-600); }
.alert--error { border-left-color: var(--danger-500); background: var(--danger-50); color: var(--danger-600); }
.alert--warning { border-left-color: var(--warning-500); background: var(--warning-50); color: var(--warning-600); }
.alert--info { border-left-color: var(--brand-500); background: var(--brand-50); color: var(--brand-700); }
.alert__body { flex: 1 1 auto; }

.toast-stack {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-width: min(380px, calc(100vw - 2.2rem));
}

.toast {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand-500);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  animation: toast-in 0.2s ease;
}

.toast--success { border-left-color: var(--success-500); }
.toast--error { border-left-color: var(--danger-500); }
.toast--warning { border-left-color: var(--warning-500); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: all 0.2s ease; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   14. Timeline
   -------------------------------------------------------------------------- */
.timeline { position: relative; margin: 0; padding: 0; list-style: none; }

.timeline::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
}

.timeline__item { position: relative; padding: 0 0 1.15rem 2.6rem; }
.timeline__item:last-child { padding-bottom: 0; }

.timeline__marker {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 2px solid var(--border-strong);
  color: var(--text-muted);
}

.timeline__marker--success { border-color: var(--success-500); color: var(--success-600); background: var(--success-50); }
.timeline__marker--danger { border-color: var(--danger-500); color: var(--danger-600); background: var(--danger-50); }
.timeline__marker--warning { border-color: var(--warning-500); color: var(--warning-600); background: var(--warning-50); }
.timeline__marker--info { border-color: var(--brand-500); color: var(--brand-700); background: var(--brand-50); }

.timeline__head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.timeline__title { font-weight: 650; font-size: 0.9rem; }
.timeline__time { font-size: 0.76rem; color: var(--text-muted); }
.timeline__body { margin: 0.25rem 0 0; font-size: 0.86rem; color: var(--text-secondary); white-space: pre-line; }
.timeline__meta { margin-top: 0.3rem; font-size: 0.76rem; color: var(--text-muted); }

.timeline--compact .timeline__item { padding-bottom: 0.85rem; }

/* --------------------------------------------------------------------------
   15. Progress and meters
   -------------------------------------------------------------------------- */
.meter {
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--bg-inset);
  overflow: hidden;
}

.meter__bar { height: 100%; background: var(--brand-600); border-radius: var(--radius-full); }
.meter__bar--success { background: var(--success-500); }
.meter__bar--warning { background: var(--warning-500); }
.meter__bar--danger { background: var(--danger-500); }

/* --------------------------------------------------------------------------
   16. Kanban board
   -------------------------------------------------------------------------- */
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 1fr);
  gap: 0.9rem;
  overflow-x: auto;
  padding-bottom: 0.6rem;
}

.board__column {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  min-height: 180px;
}

.board__column-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.board__card {
  display: block;
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--slate-400);
  box-shadow: var(--shadow-xs);
  color: inherit;
}

.board__card:hover { text-decoration: none; box-shadow: var(--shadow-md); transform: translateY(-1px); }
.board__card-title { font-size: 0.86rem; font-weight: 650; margin-bottom: 0.2rem; }
.board__card-meta { font-size: 0.74rem; color: var(--text-muted); display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   17. Empty states
   -------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.6rem 1.4rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state__icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--bg-inset);
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.empty-state__title { font-size: 1rem; font-weight: 650; color: var(--text-primary); margin: 0; }
.empty-state__text { font-size: 0.85rem; margin: 0; max-width: 46ch; }

/* --------------------------------------------------------------------------
   18. Pagination
   -------------------------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border);
}

.pagination__info { margin-right: auto; font-size: 0.8rem; color: var(--text-muted); }

.pagination__link {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 600;
}

.pagination__link:hover { background: var(--bg-inset); text-decoration: none; }
.pagination__link.is-active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.pagination__link.is-disabled { opacity: 0.45; pointer-events: none; }

/* --------------------------------------------------------------------------
   19. Modal
   -------------------------------------------------------------------------- */
.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 1.2rem;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 15, 30, 0.6);
  backdrop-filter: blur(2px);
}

.modal__dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.18s ease;
}

.modal__header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

.modal__title { margin: 0; font-size: 1.02rem; }
.modal__close {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: var(--radius-sm);
}
.modal__close:hover { background: var(--bg-inset); color: var(--text-primary); }
.modal__body { padding: 1.2rem; }
.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.9rem 1.2rem;
  border-top: 1px solid var(--border);
  background: var(--bg-surface-alt);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

body.is-modal-open { overflow: hidden; }

/* --------------------------------------------------------------------------
   20. Auth shell
   -------------------------------------------------------------------------- */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: var(--bg-app);
}

.auth__aside {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2rem;
  padding: 3rem;
  background:
    radial-gradient(900px 420px at 15% 8%, rgba(91, 134, 251, 0.35), transparent 60%),
    linear-gradient(160deg, #0b1729 0%, #0f172a 40%, #16213c 100%);
  background-color: var(--slate-900);
  color: #fff;
}

.auth__brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: #fff;
  font-weight: 700;
}
.auth__brand:hover { text-decoration: none; color: #fff; }

.auth__headline { font-size: 2rem; line-height: 1.2; margin-bottom: 0.7rem; max-width: 22ch; }
.auth__lede { color: rgba(255, 255, 255, 0.72); max-width: 46ch; font-size: 0.95rem; }

.auth__points { list-style: none; margin: 1.6rem 0 0; padding: 0; display: grid; gap: 0.6rem; }
.auth__points li {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.82);
}
.auth__points .icon { color: var(--brand-300); flex: 0 0 auto; margin-top: 2px; }
.auth__aside-footer { font-size: 0.76rem; color: rgba(255, 255, 255, 0.45); }

.auth__main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
}

.auth__panel { width: min(410px, 100%); }
.auth__panel-header { margin-bottom: 1.4rem; }
.auth__panel-lang { display: flex; justify-content: flex-end; margin-bottom: 0.5rem; }
.auth__panel-title { font-size: 1.5rem; margin-bottom: 0.25rem; }
.auth__panel-sub { color: var(--text-muted); font-size: 0.88rem; margin: 0; }
.auth__hint {
  margin-top: 1.4rem;
  padding: 0.8rem 0.95rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-surface-alt);
}
.auth__footer-links {
  margin-top: 1.4rem;
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  font-size: 0.82rem;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   21. Small components
   -------------------------------------------------------------------------- */
.progress-track {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
}

.progress-track__step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}

.progress-track__step.is-done { color: var(--success-600); border-bottom-color: var(--success-500); }
.progress-track__step.is-current {
  color: var(--brand-600);
  font-weight: 700;
  border-bottom-color: var(--brand-600);
}

.attachment-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}
.attachment-item:last-child { border-bottom: 0; }
.attachment-item__icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--bg-inset);
  color: var(--text-secondary);
  flex: 0 0 auto;
}
.attachment-item__body { min-width: 0; flex: 1 1 auto; }
.attachment-item__name { font-size: 0.88rem; font-weight: 600; }

.dropzone {
  display: grid;
  place-items: center;
  gap: 0.35rem;
  padding: 1.6rem 1rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-surface-alt);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.84rem;
  cursor: pointer;
  transition: border-color 0.13s ease, background 0.13s ease;
}
.dropzone:hover, .dropzone.is-dragover {
  border-color: var(--brand-500);
  background: var(--brand-50);
  color: var(--brand-700);
}

.note-card {
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand-500);
  border-radius: var(--radius);
  background: var(--bg-surface-alt);
}
.note-card--internal { border-left-color: var(--warning-500); }

.kv-inline { display: flex; gap: 0.4rem; align-items: baseline; flex-wrap: wrap; }
.kv-inline__label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 700; }

.divider { height: 1px; background: var(--border); margin: 1rem 0; border: 0; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-inset), var(--bg-surface-alt), var(--bg-inset));
  background-size: 200% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
  border-radius: var(--radius-sm);
  height: 0.9rem;
}
@keyframes skeleton {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.is-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}
.is-loading::after {
  content: "";
  position: absolute;
  right: 0.6rem;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.scroll-y { max-height: 340px; overflow-y: auto; }

/* --------------------------------------------------------------------------
   22. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--sidebar { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 992px) {
  .auth { grid-template-columns: 1fr; }
  .auth__aside { display: none; }
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.is-sidebar-open .sidebar { transform: none; }
  .app__main { margin-left: 0; }
  .topbar__toggle { display: inline-flex; }
  .content { padding: 1.1rem 1rem 2.5rem; }
  .grid--2, .grid--3, .grid--4 { grid-template-columns: minmax(0, 1fr); }
  .page-header__actions { margin-left: 0; width: 100%; }
}

@media (max-width: 620px) {
  body { font-size: 14.5px; }
  .page-header__title { font-size: 1.25rem; }
  .toast-stack { left: 0.8rem; right: 0.8rem; max-width: none; }
  .table th, .table td { padding: 0.55rem 0.6rem; }
  .card__body { padding: 0.95rem; }
}

/* --------------------------------------------------------------------------
   23. Print
   -------------------------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .footer, .page-header__actions, .btn, .toast-stack { display: none !important; }
  .app__main { margin-left: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  body { background: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
