/* ==========================================================================
   wojkwasi design system
   Tokens first, then base, layout, components. Components are the only
   building blocks for screens: see /design-system/ on the my site.
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------ */
:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px;

  --text-xs: 12px; --text-sm: 13px; --text-md: 15px; --text-lg: 18px;
  --text-xl: 22px; --text-2xl: 28px;

  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px;
  --sidebar-w: 232px;
  --content-max: 1120px;

  /* light */
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #e2dfd8;
  --border-strong: #cbc7bd;
  --text: #1c1b19;
  --text-muted: #6b675f;
  --accent: #c2570c;
  --accent-hover: #a54808;
  --accent-soft: #fbeadc;
  --on-accent: #ffffff;
  --success: #1f7a4d;  --success-soft: #e2f3ea;
  --warning: #9a6200;  --warning-soft: #fbf0d9;
  --danger: #b3261e;   --danger-soft: #fbe4e2;
  --focus: #2f6fd6;
  --shadow: 0 1px 2px rgba(28, 27, 25, .06), 0 1px 1px rgba(28, 27, 25, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412;
    --surface: #1c1b19;
    --surface-2: #24231f;
    --border: #33312c;
    --border-strong: #46433c;
    --text: #edebe6;
    --text-muted: #a29d93;
    --accent: #f08a3c;
    --accent-hover: #f59d57;
    --accent-soft: #3a2616;
    --on-accent: #1c1b19;
    --success: #5cc48c;  --success-soft: #16301f;
    --warning: #e3b04b;  --warning-soft: #33280f;
    --danger: #f07b72;   --danger-soft: #3a1917;
    --focus: #7aa7f5;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --surface: #1c1b19; --surface-2: #24231f; --border: #33312c; --border-strong: #46433c;
  --text: #edebe6; --text-muted: #a29d93; --accent: #f08a3c; --accent-hover: #f59d57; --accent-soft: #3a2616;
  --on-accent: #1c1b19; --success: #5cc48c; --success-soft: #16301f; --warning: #e3b04b; --warning-soft: #33280f;
  --danger: #f07b72; --danger-soft: #3a1917; --focus: #7aa7f5; --shadow: none; color-scheme: dark;
}

/* ---- Base -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--text-md)/1.5 var(--font-sans);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: var(--text-2xl); font-weight: 650; }
h2 { font-size: var(--text-lg); font-weight: 600; }
h3 { font-size: var(--text-md); font-weight: 600; }
p { margin: 0 0 var(--space-3); }
code, kbd { font-family: var(--font-mono); font-size: .92em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); }

/* ---- App shell --------------------------------------------------------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: var(--space-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-5);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 700; font-size: var(--text-lg); color: var(--text); }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-size: var(--text-xs); font-weight: 500; color: var(--text-muted); letter-spacing: .04em; text-transform: uppercase; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label { font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; padding: 0 var(--space-2) var(--space-1); }
.nav-link {
  display: block; padding: 6px var(--space-2); border-radius: var(--radius-sm);
  color: var(--text); font-size: var(--text-sm);
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; font-size: var(--text-sm); display: flex; flex-direction: column; gap: 2px; }

.shell > * { min-width: 0; }
.main { min-width: 0; padding: var(--space-6) var(--space-6) var(--space-7); }
.main-inner { max-width: var(--content-max); margin: 0 auto; }

.mobile-bar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-bar {
    display: block; position: sticky; top: 0; z-index: 10;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: var(--space-3) var(--space-4);
  }
  .mobile-bar summary { list-style: none; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
  .mobile-bar summary::-webkit-details-marker { display: none; }
  .mobile-bar .mobile-nav { padding-top: var(--space-3); display: flex; flex-direction: column; gap: var(--space-3); }
  .main { padding: var(--space-5) var(--space-4) var(--space-7); }
}

/* ---- Page header ------------------------------------------------------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); }
.page-header .crumbs { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-1); }
.page-header .subtitle { color: var(--text-muted); margin: var(--space-1) 0 0; }
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 36px; padding: 0 var(--space-4); border-radius: var(--radius-sm);
  font: 600 var(--text-sm)/1 var(--font-sans); cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--danger); }
.btn-sm { min-height: 30px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- Cards, stats, badges, alerts ------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-body { padding: var(--space-5); }
.card-title { margin-bottom: var(--space-2); }
.grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
a.card { color: inherit; display: block; }
a.card:hover { border-color: var(--border-strong); text-decoration: none; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: var(--text-xl); font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: var(--text-sm); color: var(--text-muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: var(--text-xs); font-weight: 600; background: var(--surface-2); color: var(--text-muted); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); margin-bottom: var(--space-3); font-size: var(--text-sm); }
.alert-success { border-color: transparent; background: var(--success-soft); color: var(--success); }
.alert-warning { border-color: transparent; background: var(--warning-soft); color: var(--warning); }
.alert-error, .alert-danger { border-color: transparent; background: var(--danger-soft); color: var(--danger); }
.messages { margin-bottom: var(--space-4); }

/* ---- Toolbar and filters ---------------------------------------------- */
.toolbar { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; margin-bottom: var(--space-3); }
.toolbar .grow { flex: 1 1 220px; }
.toolbar-meta { font-size: var(--text-sm); color: var(--text-muted); margin-left: auto; }

/* ---- Inputs ------------------------------------------------------------ */
.input, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea, .auth input:not([type="checkbox"]):not([type="radio"]) {
  width: 100%; min-height: 36px; padding: 7px var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-md);
}
select.input { width: auto; }
.field textarea { min-height: 110px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus, .auth input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }

.form { display: flex; flex-direction: column; gap: var(--space-4); max-width: 640px; }
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field label { font-size: var(--text-sm); font-weight: 600; }
.field .help { font-size: var(--text-xs); color: var(--text-muted); }
.field .errors { font-size: var(--text-sm); color: var(--danger); margin: 0; padding: 0; list-style: none; }
.field-check { flex-direction: row; align-items: center; gap: var(--space-2); }
.field-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.field-invalid input, .field-invalid select, .field-invalid textarea { border-color: var(--danger); }
.form-actions { display: flex; gap: var(--space-2); padding-top: var(--space-2); }

/* ---- Data table -------------------------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td { padding: 10px var(--space-4); text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table th a { color: inherit; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .col-check { width: 36px; padding-right: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.row-muted td { color: var(--text-muted); }
.table tr.row-muted .row-link { color: var(--text-muted); text-decoration: line-through; }
.table .cell-url { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }
.table .row-link { font-weight: 600; color: var(--text); }
.sort-ind { font-size: 10px; margin-left: 2px; }

/* ---- Detail list ------------------------------------------------------- */
.detail { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; margin: 0; }
.detail dt, .detail dd { padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); margin: 0; }
.detail dt { color: var(--text-muted); font-size: var(--text-sm); }
.detail dd { white-space: pre-line; overflow-wrap: anywhere; }
.detail > :nth-last-child(-n+2) { border-bottom: 0; }
@media (max-width: 600px) { .detail { grid-template-columns: 1fr; } .detail dt { border-bottom: 0; padding-bottom: 0; } }

/* ---- Sections -------------------------------------------------------- */
.section { margin-top: var(--space-6); }
.notices { margin-top: var(--space-4); }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.table-wrap + .muted { margin-top: var(--space-3); }
@media (max-width: 600px) { .table th, .table td { white-space: nowrap; } }

/* ---- Pagination and empty state --------------------------------------- */
.pagination { display: flex; gap: var(--space-2); align-items: center; justify-content: flex-end; margin-top: var(--space-3); font-size: var(--text-sm); }
.empty { text-align: center; padding: var(--space-7) var(--space-5); }
.empty h2 { margin-bottom: var(--space-2); }
.empty p { color: var(--text-muted); max-width: 420px; margin: 0 auto var(--space-4); }

/* ---- Design system gallery -------------------------------------------- */
.ds-section { margin-bottom: var(--space-6); }
.ds-section > h2 { margin-bottom: var(--space-3); }
.ds-row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.swatch { width: 120px; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; font-size: var(--text-xs); background: var(--surface); }
.swatch span { display: block; height: 48px; }
.swatch code { display: block; padding: var(--space-2); }
.sw-bg { background: var(--bg); } .sw-surface { background: var(--surface); } .sw-surface-2 { background: var(--surface-2); }
.sw-text { background: var(--text); } .sw-muted { background: var(--text-muted); } .sw-accent { background: var(--accent); }
.sw-success { background: var(--success); } .sw-warning { background: var(--warning); } .sw-danger { background: var(--danger); }

/* ---- Auth pages (allauth) --------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--space-5) var(--space-4); }
.auth { width: 100%; max-width: 420px; }
.auth .card-body { display: flex; flex-direction: column; gap: var(--space-3); }
.auth h1 { font-size: var(--text-xl); }
.auth form { display: flex; flex-direction: column; gap: var(--space-3); }
.auth form p { display: flex; flex-direction: column; gap: var(--space-1); margin: 0; }
.auth label { font-size: var(--text-sm); font-weight: 600; }
.auth button, .auth .provider a {
  display: inline-flex; align-items: center; justify-content: center; width: 100%;
  min-height: 40px; border-radius: var(--radius-sm); font: 600 var(--text-sm)/1 var(--font-sans); cursor: pointer;
  background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent);
}
.auth .provider a { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.auth ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.auth hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-2) 0; }
.auth-foot { text-align: center; font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-4); }
.auth form p:has(> input[type="checkbox"]) { flex-direction: row; align-items: center; gap: var(--space-2); }
.auth form p:has(> input[type="checkbox"]) input { width: 18px; height: 18px; accent-color: var(--accent); }
