/* KIVI backoffice — the Spintex admin theme, same as the Astrolight backoffice.
   Tokens (tokens/*.css) are copied unchanged from the Spintex admin panel.
   This file loads after Django's admin CSS: it points Django's own colour
   variables at the tokens, lays out the sidebar + topbar shell from
   admin/base.html, and restyles the stock admin pages (lists, forms,
   filters, actions) as Spintex cards, tables and buttons. */
@import './tokens/colors.css';
@import './tokens/typography.css';
@import './tokens/spacing.css';

/* ── Django admin variables → Spintex tokens ─────────────────────────────── */
:root {
  color-scheme: light;
  --primary: var(--blue-600); --secondary: var(--blue-800); --accent: var(--orange-500);
  --primary-fg: #fff;
  --body-fg: var(--fg-2); --body-bg: var(--bg-surface);
  --body-quiet-color: var(--fg-3); --body-medium-color: var(--fg-2); --body-loud-color: var(--fg-1);
  --header-color: var(--fg-1); --header-branding-color: var(--fg-1);
  --header-bg: var(--bg-surface); --header-link-color: var(--fg-1);
  --breadcrumbs-fg: var(--fg-3); --breadcrumbs-link-fg: var(--fg-2); --breadcrumbs-bg: transparent;
  --link-fg: var(--blue-600); --link-hover-color: var(--blue-800); --link-selected-fg: var(--blue-700);
  --hairline-color: var(--border-1); --border-color: var(--border-2);
  --error-fg: var(--red-600);
  --message-success-bg: var(--green-50); --message-warning-bg: var(--amber-50); --message-error-bg: var(--red-50);
  --darkened-bg: var(--gray-50); --selected-bg: var(--blue-50); --selected-row: var(--orange-50);
  --button-fg: #fff; --button-bg: var(--blue-600); --button-hover-bg: var(--blue-700);
  --default-button-bg: var(--blue-600); --default-button-hover-bg: var(--blue-700);
  --close-button-bg: var(--gray-400); --close-button-hover-bg: var(--gray-500);
  --delete-button-bg: var(--red-500); --delete-button-hover-bg: var(--red-600);
  --object-tools-fg: #fff; --object-tools-bg: var(--blue-600); --object-tools-hover-bg: var(--blue-700);
  --font-family-primary: var(--font-body); --font-family-monospace: var(--font-mono);
}

html, body { height: auto; min-height: 100%; }
body { margin: 0; background: var(--bg-page); color: var(--fg-2); font-family: var(--font-body);
       font-size: var(--text-base); -webkit-font-smoothing: antialiased; }
a:link, a:visited { color: var(--link-fg); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
summary:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }
svg.icon { flex-shrink: 0; }

/* ── Shell: sidebar + content ───────────────────────────────────────────── */
#container.admin-layout { display: flex; flex-direction: row; min-width: 0; height: auto; min-height: 100vh; }
.admin-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-main { flex: 1; padding: 24px 28px 40px; }
#footer { padding: 0; }

.sidebar { width: 248px; flex-shrink: 0; background: var(--blue-900); display: flex; flex-direction: column;
           height: 100vh; position: sticky; top: 0; z-index: var(--z-sticky); }
.sidebar-logo { padding: 16px 18px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-brand, .sidebar-brand:link, .sidebar-brand:visited { display: flex; align-items: center; gap: 11px; color: #fff; text-decoration: none; }
.sidebar-mark { width: 34px; height: 34px; border-radius: var(--radius-md); background: var(--color-accent);
                color: #fff; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-mark svg { fill: currentColor; }
.sidebar-logo-text { display: block; font-family: var(--font-display); font-weight: 800; font-size: 17px; color: #fff; letter-spacing: 0.5px; line-height: 1.1; }
.sidebar-logo-sub { display: block; font-size: 10px; color: var(--orange-300); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.18) transparent; }
.nav-item, .nav-item:link, .nav-item:visited { display: flex; align-items: center; gap: 11px; padding: 9px 12px; margin-bottom: 4px;
  border-radius: var(--radius-md); color: rgba(255,255,255,0.72); font-size: 13.5px; font-weight: 500; font-family: var(--font-ui);
  text-decoration: none; transition: background var(--transition-fast), color var(--transition-fast); }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--blue-600); color: #fff; font-weight: 600; }

.nav-filter { margin: 8px 0 10px; }
.nav-filter input, .nav-filter input[type=search] { width: 100%; box-sizing: border-box; height: 34px; padding: 0 10px; border-radius: var(--radius-md);
  border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.06); color: #fff; font-size: 13px; font-family: var(--font-ui); }
.nav-filter input::placeholder { color: rgba(255,255,255,0.45); }
.nav-filter input[type=search]:focus { outline: none; border-color: var(--blue-300); background: rgba(255,255,255,0.1); }

.nav-group { margin-bottom: 2px; }
.nav-group-title { list-style: none; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-md);
  cursor: pointer; color: rgba(255,255,255,0.72); font-size: 13.5px; font-weight: 600; font-family: var(--font-ui); user-select: none; }
.nav-group-title::-webkit-details-marker { display: none; }
.nav-group-title::after { content: ''; margin-left: auto; width: 6px; height: 6px; border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); opacity: 0.6; transition: transform var(--transition-base); }
.nav-group[open] > .nav-group-title::after { transform: rotate(45deg); }
.nav-group-title:hover, .nav-group-title.current { color: #fff; }
.nav-group-title:hover { background: rgba(255,255,255,0.06); }
.nav-link, .nav-link:link, .nav-link:visited { display: block; margin: 1px 0 1px 21px; padding: 6px 10px 6px 16px; border-left: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6); font-size: 13px; font-family: var(--font-ui); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,0.05); }
.nav-link.active { color: #fff; font-weight: 600; border-left: 2px solid var(--color-accent); background: rgba(255,255,255,0.08); padding-left: 15px; }
.nav-empty { color: rgba(255,255,255,0.5); font-size: 12px; padding: 8px 12px; margin: 0; }

.sidebar-user { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.08); display: flex; align-items: center; gap: 10px; }
.sidebar-user-text { min-width: 0; }
.user-avatar { width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%; background: var(--blue-500); display: flex;
  align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 13px; font-family: var(--font-ui); }
.user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: rgba(255,255,255,0.5); }

/* Topbar (Django's #header) */
.topbar#header { height: 64px; box-sizing: border-box; background: var(--bg-surface); border-bottom: 1px solid var(--border-1);
  display: flex; flex-direction: row; align-items: center; justify-content: flex-start; padding: 0 28px; gap: 16px;
  position: sticky; top: 0; z-index: 50; color: var(--fg-1); }
.topbar-crumbs { flex: 1; min-width: 0; }
.topbar .breadcrumbs, div.breadcrumbs { background: none; padding: 0; margin: 0; border: none; color: var(--fg-3);
  font-size: 13px; font-family: var(--font-ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
div.breadcrumbs a:link, div.breadcrumbs a:visited { color: var(--fg-2); font-weight: 500; }
div.breadcrumbs a:hover { color: var(--fg-brand); }
div.breadcrumbs span { color: var(--fg-1); font-weight: 600; }
.topbar #user-tools { float: none; margin: 0; display: flex; align-items: center; gap: 8px; font-size: 13px; text-transform: none; letter-spacing: 0; }
#user-tools a, #user-tools a:link, #user-tools a:visited { border: 1px solid var(--border-2); color: var(--fg-2); }
#logout-form { display: inline-flex; margin: 0; }
#logout-form button.btn { border: 1px solid var(--border-2); background: var(--bg-surface); color: var(--fg-2); padding: 0 12px;
  font-size: 12px; text-decoration: none; text-transform: none; }
#logout-form button.btn:hover { background: var(--bg-surface-2); color: var(--fg-1); }
.topbar-menu { display: none; }
.sidebar-scrim { position: fixed; inset: 0; background: var(--bg-overlay); z-index: 99; }

/* ── Spintex components ─────────────────────────────────────────────────── */
.card { background: var(--bg-surface); border-radius: var(--radius-lg); border: 1px solid var(--border-1); box-shadow: var(--shadow-xs); }
.card-body { padding: 18px 20px; }
.btn, a.btn:link, a.btn:visited { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 16px; height: 36px;
  box-sizing: border-box; border-radius: var(--radius-md); border: none; cursor: pointer; font-size: 13px; font-weight: 600;
  font-family: var(--font-ui); text-decoration: none; white-space: nowrap; transition: background var(--transition-fast), color var(--transition-fast); }
.btn-sm, a.btn-sm:link, a.btn-sm:visited { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-primary, a.btn-primary:link, a.btn-primary:visited { background: var(--color-brand); color: #fff; }
.btn-primary:hover { background: var(--color-brand-hover); }
.btn-secondary, a.btn-secondary:link, a.btn-secondary:visited { background: var(--bg-surface); color: var(--fg-2); border: 1px solid var(--border-2); }
.btn-secondary:hover { background: var(--bg-surface-2); color: var(--fg-1); }
.badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 700; border-radius: var(--radius-full); padding: 2px 8px; font-family: var(--font-ui); }
.badge-neutral { background: var(--bg-surface-2); color: var(--fg-3); border: 1px solid var(--border-2); }
.section-header, a.section-header:link, a.section-header:visited { font-family: var(--font-display); font-weight: 700; font-size: 16px; color: var(--fg-1); text-decoration: none; }
a.section-header:hover { color: var(--fg-brand); }

.alert { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: var(--radius-md); margin-bottom: 16px;
  font-size: 13px; font-family: var(--font-ui); font-weight: 600; }
.alert-success { background: var(--green-50); border: 1px solid var(--green-100); color: var(--green-700); }
.alert-error { background: var(--red-50); border: 1px solid var(--red-100); color: var(--red-700); }
.alert-warning { background: var(--amber-50); border: 1px solid var(--amber-100); color: var(--amber-700); }
.alert-info { background: var(--indigo-50); border: 1px solid var(--indigo-100); color: var(--indigo-700); }

/* ── Page heading + object tools ────────────────────────────────────────── */
#content { padding: 0; position: relative; }
.dashboard #content, #content.dashboard { width: auto; max-width: none; }
#content > h1, .page-header h1 { font-family: var(--font-display); font-weight: 700; font-size: var(--text-3xl); color: var(--fg-1);
  line-height: 1.2; margin: 0 0 20px; padding-right: 320px; }
.page-header h1 { margin: 0; padding: 0; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-sub, #content > h2.content-subtitle { font-size: 13px; color: var(--fg-3); font-weight: 400; margin: 4px 0 0; }
#content > h1 + h2.content-subtitle { margin: -14px 0 20px; }

#content .object-tools { position: absolute; top: 0; right: 0; margin: 0; padding: 0; float: none; display: flex; gap: 8px;
  font-size: 13px; font-weight: 600; }
.object-tools li { display: block; float: none; height: auto; margin: 0; }
.object-tools a:link, .object-tools a:visited { display: inline-flex; align-items: center; gap: 6px; float: none; height: 36px; box-sizing: border-box;
  padding: 0 14px; border-radius: var(--radius-md); background: var(--bg-surface); color: var(--fg-2); border: 1px solid var(--border-2);
  font-family: var(--font-ui); font-size: 13px; font-weight: 600; text-transform: none; letter-spacing: 0; line-height: 1; }
.object-tools a:hover { background: var(--bg-surface-2); color: var(--fg-1); }
.object-tools a.addlink, .object-tools a.addlink:link, .object-tools a.addlink:visited { background: var(--color-brand); color: #fff; border-color: var(--color-brand);
  padding-left: 14px; background-image: none; }
.object-tools a.addlink::before { content: '+'; font-size: 17px; font-weight: 500; margin-top: -2px; }
.object-tools a.addlink:hover { background: var(--color-brand-hover); }

/* ── Dashboard ──────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { padding: 18px; position: relative; overflow: hidden; }
.stat-label { font-size: 12px; color: var(--fg-3); font-weight: 500; margin-bottom: 10px; font-family: var(--font-ui); }
.stat-value { font-family: var(--font-display); font-weight: 800; font-size: 30px; color: var(--fg-1); line-height: 1; font-variant-numeric: tabular-nums; }
.dash-card { margin-bottom: 20px; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border-1); background: var(--bg-surface-2); }
.card-head .badge { margin-left: auto; }
.card-head-icon { width: 28px; height: 28px; border-radius: var(--radius-sm); background: var(--color-brand-light); color: var(--color-brand);
  display: inline-flex; align-items: center; justify-content: center; }
.tool-row { display: flex; flex-wrap: wrap; gap: 8px; }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.app-card { margin: 0; }
.app-links { list-style: none; margin: 0; padding: 6px 0; }
.app-links li { display: flex; align-items: center; gap: 8px; padding: 7px 18px; font-size: 13px; list-style: none; }
.app-links li:hover { background: var(--bg-surface-2); }
.app-links a:link, .app-links a:visited { color: var(--fg-2); font-weight: 500; text-decoration: none; }
.app-links a:hover { color: var(--fg-brand); }
.app-links a.app-add:link, .app-links a.app-add:visited { margin-left: auto; font-size: 12px; color: var(--fg-brand); font-weight: 600; opacity: 0; }
.app-links li:hover a.app-add, .app-links a.app-add:focus-visible { opacity: 1; }

/* ── Modules (cards) ────────────────────────────────────────────────────── */
.module { background: var(--bg-surface); border: 1px solid var(--border-1); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); margin-bottom: 20px; }
.module h2, .module caption, .inline-group h2 { background: var(--bg-surface-2); color: var(--fg-1); font-family: var(--font-display);
  font-weight: 700; font-size: 15px; padding: 12px 18px; border-bottom: 1px solid var(--border-1); text-transform: none; letter-spacing: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.module h3 { font-family: var(--font-display); color: var(--fg-1); }
fieldset.module { padding: 0; overflow: hidden; }
fieldset.collapsed .collapse-toggle, .module summary { color: var(--fg-brand); }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-row { padding: 14px 18px; border-bottom: 1px solid var(--border-1); font-size: 13px; }
.form-row:last-child { border-bottom: none; }
.aligned label, form .aligned label { font-family: var(--font-ui); font-size: 12.5px; font-weight: 600; color: var(--fg-2); padding: 9px 10px 0 1px; width: 180px; min-width: 180px; }
.aligned .flex-container > label { width: 180px; min-width: 180px; flex-shrink: 0; box-sizing: content-box; }
form .aligned label.required, label.required { color: var(--fg-1); }
label.required::after { content: ' *'; color: var(--color-accent); }
.aligned label + p, .aligned .checkbox-row + div.help, .aligned label + div.readonly { padding: 9px 0 0; }
.readonly { color: var(--fg-1); }

input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=tel],
input[type=search], textarea, select, .vTextField {
  border: 1.5px solid var(--border-2); border-radius: var(--radius-md); padding: 8px 11px; min-height: 38px; box-sizing: border-box;
  font-family: var(--font-body); font-size: 13px; color: var(--fg-1); background: var(--bg-surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast); }
select { padding-right: 28px; }
textarea { min-height: 96px; line-height: 1.5; }
input[type=text]:focus, input[type=password]:focus, input[type=email]:focus, input[type=url]:focus, input[type=number]:focus,
input[type=tel]:focus, input[type=search]:focus, textarea:focus, select:focus, .vTextField:focus {
  border-color: var(--color-brand); box-shadow: 0 0 0 3px var(--blue-50); outline: none; }
.vTextField, .vURLField { width: min(100%, 520px); }
.vLargeTextField, .vXMLLargeTextField { width: min(100%, 680px); }
.vIntegerField, .vBigIntegerField, .vPositiveIntegerField { width: 140px; }
input[type=checkbox], input[type=radio] { accent-color: var(--color-brand); width: 16px; height: 16px; vertical-align: middle; }
input[type=file] { font-size: 13px; color: var(--fg-2); }
input[type=file]::file-selector-button { border: 1px solid var(--border-2); background: var(--bg-surface-2); border-radius: var(--radius-sm);
  padding: 6px 12px; margin-right: 10px; font-weight: 600; font-family: var(--font-ui); color: var(--fg-2); cursor: pointer; }
p.datetime { color: var(--fg-3); font-size: 12px; line-height: 2.6; margin: 0; }
.datetime input.vDateField, .datetime input.vTimeField { min-width: 0; margin-left: 4px; }
.datetimeshortcuts a:link, .datetimeshortcuts a:visited { font-size: 12px; font-weight: 600; }

div.help, p.help, form .aligned div.help, form .aligned p.help { font-size: 11.5px; color: var(--fg-muted); margin-top: 6px; padding-left: 0; }
.errornote { display: block; background: var(--red-50); border: 1px solid var(--red-100); color: var(--red-700); border-radius: var(--radius-md);
  padding: 11px 16px; font-size: 13px; font-weight: 600; font-family: var(--font-ui); margin: 0 0 16px; background-image: none; }
ul.errorlist { margin: 0 0 6px; padding: 0; }
ul.errorlist li { background: none; border: none; color: var(--red-600); font-size: 12px; font-weight: 600; padding: 0; margin: 0 0 4px; }
.errors input, .errors select, .errors textarea, td ul.errorlist + input { border-color: var(--red-500); }
.form-row.errors { background: var(--red-50); }

/* Submit row: a sticky action bar */
.submit-row { position: sticky; bottom: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px 16px; margin: 16px 0 0; background: rgba(255,255,255,0.94); backdrop-filter: blur(6px); border: 1px solid var(--border-1);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md); overflow: visible; }
.button, input[type=submit], input[type=button], .submit-row input, a.button {
  font-family: var(--font-ui); font-size: 13px; font-weight: 600; border-radius: var(--radius-md); padding: 0 16px; height: 36px; line-height: 36px; }
.submit-row input, .submit-row input.default { text-transform: none; background: var(--bg-surface); color: var(--fg-2); border: 1px solid var(--border-2); }
.submit-row input:hover { background: var(--bg-surface-2); color: var(--fg-1); }
.submit-row input.default, input[type=submit].default { order: -1; background: var(--color-brand); color: #fff; border-color: var(--color-brand); }
.submit-row input.default:hover { background: var(--color-brand-hover); }
.submit-row a.deletelink, .submit-row a.deletelink:link, .submit-row a.deletelink:visited { margin-left: auto; height: 36px; line-height: 36px; padding: 0 14px;
  border-radius: var(--radius-md); background: var(--red-50); color: var(--red-700); border: 1px solid var(--red-100); font-weight: 600; font-size: 13px; }
.submit-row a.deletelink:hover { background: var(--red-100); }
.submit-row a.closelink { border-radius: var(--radius-md); height: 36px; line-height: 36px; padding: 0 14px; }

/* Inline groups */
.inline-group { border: 1px solid var(--border-1); border-radius: var(--radius-lg); overflow: hidden; background: var(--bg-surface); margin-bottom: 20px; }
.inline-group .tabular { border: none; margin: 0; box-shadow: none; }
.inline-group .tabular tr.add-row td, .inline-group div.add-row { background: var(--bg-surface-2); padding: 10px 18px; border: none; }
.inline-related h3 { background: var(--bg-surface-2); color: var(--fg-2); padding: 10px 18px; font-size: 13px; border-bottom: 1px solid var(--border-1); }

/* ── Change list ────────────────────────────────────────────────────────── */
#changelist.module { background: none; border: none; box-shadow: none; }
#changelist { display: flex; align-items: flex-start; gap: 20px; }
#changelist .changelist-form-container { flex: 1 1 auto; min-width: 0; background: var(--bg-surface); border: 1px solid var(--border-1);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); overflow: hidden; }
#toolbar { margin: 0; padding: 14px 16px; background: var(--bg-surface); border: none; border-bottom: 1px solid var(--border-1); color: var(--fg-3); }
#toolbar form > div { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#toolbar label[for=searchbar] { display: none; }
#toolbar #searchbar { height: 38px; width: min(100%, 340px); padding: 0 12px 0 36px; font-size: 13px; vertical-align: middle;
  background: var(--bg-surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237D8796' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 12px center; }
#toolbar #searchbar:focus { background-color: var(--bg-surface); }
#toolbar form input[type=submit] { background: var(--color-brand); color: #fff; border: none; padding: 0 16px; height: 38px; line-height: 38px; }
#toolbar form input[type=submit]:hover { background: var(--color-brand-hover); }
#toolbar .small.quiet { color: var(--fg-3); font-size: 12px; }

#changelist .actions { width: auto; box-sizing: border-box; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 10px 16px; background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border-1); color: var(--fg-3); font-size: 12.5px; line-height: normal; }
#changelist .actions label { font-weight: 600; color: var(--fg-2); display: inline-flex; align-items: center; gap: 8px; }
#changelist .actions select { min-height: 32px; height: 32px; padding: 0 28px 0 10px; font-size: 12.5px; }
#changelist .actions .button { height: 32px; line-height: 32px; padding: 0 14px; background: var(--bg-surface); color: var(--fg-1);
  border: 1px solid var(--border-2); font-size: 12.5px; }
#changelist .actions .button:hover { background: var(--bg-surface-3); }
#changelist .actions span.all, #changelist .actions span.action-counter, #changelist .actions span.clear, #changelist .actions span.question {
  font-size: 12.5px; margin: 0; }
#changelist .actions.selected { background: var(--orange-50); border-bottom-color: var(--orange-100); }

.results { overflow-x: auto; }
#result_list { width: 100%; border-collapse: collapse; font-size: 13px; }
#result_list thead th { text-align: left; padding: 0; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--fg-3); font-family: var(--font-ui); background: var(--bg-surface); border: none; border-bottom: 1px solid var(--border-1); white-space: nowrap; }
#result_list thead th .text > a, #result_list thead th .text > span { display: block; padding: 11px 16px; }
#result_list thead th .text a:link, #result_list thead th .text a:visited { color: var(--fg-3); }
#result_list thead th.sorted { background: var(--bg-surface-2); }
#result_list thead th.sorted .text a { padding-right: 52px; color: var(--fg-1); }
#result_list thead th .sortoptions { padding: 12px 10px 0 0; }
#result_list thead th.action-checkbox-column { width: 44px; }
#result_list thead th.action-checkbox-column .text span { padding: 11px 0 11px 16px; }
#result_list td, #result_list th { padding: 11px 16px; color: var(--fg-2); border-bottom: 1px solid var(--border-1); vertical-align: middle; font-size: 13px; line-height: 1.4; }
#result_list tbody th a:link, #result_list tbody th a:visited { color: var(--fg-brand); font-weight: 600; }
#result_list tbody tr { background: var(--bg-surface); transition: background var(--transition-fast); }
#result_list tbody tr:hover { background: var(--bg-surface-2); }
#result_list tbody tr.selected, #result_list tbody tr.selected:hover { background: var(--orange-50); }
#result_list tbody tr:last-child td, #result_list tbody tr:last-child th { border-bottom: none; }
#result_list td.action-checkbox { width: 44px; padding-right: 0; }
#result_list img { border-radius: var(--radius-sm); max-height: 44px; }
#result_list td.field-status, #result_list td[class*="status"] { font-weight: 600; }

#changelist .paginator, .paginator { margin: 0; padding: 12px 16px; border-top: 1px solid var(--border-1); background: var(--bg-surface);
  color: var(--fg-3); font-size: 12.5px; font-family: var(--font-ui); line-height: 32px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.paginator a:link, .paginator a:visited, .paginator .this-page { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px;
  padding: 0 8px; box-sizing: border-box; border-radius: var(--radius-sm); border: 1px solid var(--border-2); background: var(--bg-surface);
  color: var(--fg-2); font-size: 12.5px; text-decoration: none; margin: 0; }
.paginator a:hover { background: var(--bg-surface-2); }
.paginator .this-page { background: var(--color-brand); border-color: var(--color-brand); color: #fff; font-weight: 600; }
.paginator a.showall:link, .paginator a.showall:visited { border: none; background: none; color: var(--fg-brand); }
.paginator .end { margin-right: 4px; }
.paginator input[type=submit] { margin-left: auto; height: 32px; line-height: 32px; }
#changelist .changelist-form-container > form > p.paginator:only-child,
#changelist-form > p.paginator:first-of-type:last-child { border-top: none; }


/* Filter bar: one row of dropdowns above the table */
#changelist { flex-direction: column; align-items: stretch; gap: 12px; }
#changelist .changelist-form-container { max-width: 100%; }
#changelist-filter.filter-bar { order: -1; flex: none; width: 100%; box-sizing: border-box; margin: 0; padding: 10px 14px;
  position: static; max-height: none; overflow: visible; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px;
  background: var(--bg-surface); border: 1px solid var(--border-1); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); }
#changelist-filter .filter-bar-title { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 0 4px 0 0; height: 34px;
  background: none; border: none; font-family: var(--font-ui); font-size: 13px; font-weight: 700; color: var(--fg-1);
  text-transform: none; letter-spacing: 0; }
.filter-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; flex: 1; min-width: 0; }
.filter-field { display: flex; flex-direction: column; gap: 4px; min-width: 130px; max-width: 220px; }
.filter-label { font-family: var(--font-ui); font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--fg-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filter-field select { min-height: 34px; height: 34px; padding: 0 28px 0 10px; font-size: 13px; width: 100%; }
.filter-field.is-active select { border-color: var(--color-brand); background-color: var(--color-brand-light); color: var(--color-brand);
  font-weight: 600; }
.filter-actions { display: flex; align-items: center; gap: 12px; height: 34px; margin-left: auto; }
.filter-actions a:link, .filter-actions a:visited { font-family: var(--font-ui); font-size: 12.5px; font-weight: 600; white-space: nowrap;
  color: var(--fg-brand); background-image: none; padding: 0; }
.filter-actions a.filter-clear:link, .filter-actions a.filter-clear:visited { color: var(--red-700); }

/* Date hierarchy */
#changelist .xfull, .xfull { width: auto; }
#changelist nav.toplinks, .toplinks { padding: 10px 16px; border-bottom: 1px solid var(--border-1); background: var(--bg-surface); margin: 0; }

/* ── Other stock pages: delete confirmation, history, popups ────────────── */
.delete-confirmation #content-main, .delete-confirmation #content > p, .delete-confirmation #content > ul { max-width: 820px; }
.delete-confirmation form .cancel-link, .delete-confirmation form a.cancel-link:link { display: inline-flex; align-items: center; height: 36px;
  padding: 0 16px; border-radius: var(--radius-md); background: var(--bg-surface); color: var(--fg-2); border: 1px solid var(--border-2); font-weight: 600; }
.delete-confirmation form input[type=submit] { background: var(--red-500); }
.delete-confirmation form input[type=submit]:hover { background: var(--red-600); }
#change-history { background: var(--bg-surface); border: 1px solid var(--border-1); border-radius: var(--radius-lg); overflow: hidden; }
body.popup .admin-main { padding: 20px; }
body.popup #content > h1 { padding-right: 0; }

/* Calendar / clock pop-ups from DateTimeShortcuts */
.calendarbox, .clockbox { border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); border: 1px solid var(--border-1); }
.calendar caption, .calendarbox h2 { background: var(--color-brand); color: #fff; }
.calendar td.selected a, .calendar td a:active { background: var(--color-brand); }

/* Generic tables (delete summaries, custom pages) */
#content table:not(#result_list) th, #content table:not(#result_list) td { border-bottom: 1px solid var(--border-1); }

/* ── Sign-in / signed-out screens ───────────────────────────────────────── */
body.auth-page { background: var(--blue-900); }
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; box-sizing: border-box;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(240,99,24,0.16), transparent 60%),
              radial-gradient(900px 500px at -10% 110%, rgba(45,106,194,0.30), transparent 60%), var(--blue-900); }
.auth-box { width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-mark { width: 52px; height: 52px; border-radius: var(--radius-xl); margin-bottom: 14px; box-shadow: 0 8px 24px rgba(240,99,24,0.35); }
.auth-brand-name { font-family: var(--font-display); font-weight: 800; font-size: 28px; color: #fff; letter-spacing: 1px; }
.auth-brand-sub { font-size: 13px; color: rgba(255,255,255,0.6); margin-top: 4px; }
.auth-card { padding: 32px; box-shadow: var(--shadow-xl); }
.auth-title { font-family: var(--font-display); font-weight: 700; font-size: 20px; color: var(--fg-1); margin: 0 0 6px; }
.auth-sub { font-size: 13px; color: var(--fg-3); margin: 0 0 24px; }
.auth-foot { text-align: center; margin-top: 16px; font-size: 12px; color: rgba(255,255,255,0.4); }
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--fg-2); font-family: var(--font-ui); margin-bottom: 6px; }
.form-control { display: block; width: 100%; height: 42px; }
.form-error { font-size: 12px; color: var(--color-error); margin-top: 5px; font-weight: 600; }
.auth-card .btn-block { margin-top: 8px; }

/* ── Phone and small-tablet layout ──────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: 100%; z-index: 100; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
  .topbar-menu { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; margin-left: -6px; border: none;
    background: none; color: var(--fg-1); border-radius: var(--radius-md); cursor: pointer; flex-shrink: 0; }
  .topbar#header { padding: 0 16px; gap: 10px; }
  #user-tools a.btn, #logout-form .btn span { display: none; }
  #logout-form .btn { width: 36px; padding: 0; }
  .admin-main { padding: 16px 16px 32px; }
  #content > h1 { padding-right: 0; font-size: var(--text-2xl); margin-bottom: 12px; }
  #content .object-tools { position: static; margin: 0 0 16px; flex-wrap: wrap; }
  .aligned .form-row > div, .aligned .flex-container { flex-direction: column; align-items: stretch; }
  .aligned label, form .aligned label, .aligned .flex-container > label { width: auto; min-width: 0; padding: 0 0 6px; }
  .vTextField, .vURLField, .vLargeTextField, textarea, select { width: 100%; }
  .submit-row { padding: 10px; }
  .submit-row a.deletelink { margin-left: 0; }
  #result_list { white-space: nowrap; }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 26px; }
  .app-grid { grid-template-columns: minmax(0, 1fr); }
  #toolbar #searchbar { width: 100%; }
}

/* Help text under a field lines up with the field, not the label. */
.aligned .form-row > .help, .aligned .form-row > div.help { margin-left: 191px; }
.form-intro { margin: -8px 0 16px; }
@media (max-width: 900px) { .aligned .form-row > .help, .aligned .form-row > div.help { margin-left: 0; } }

/* Menu groups: item count + tool pages */
.nav-count { margin-left: auto; font-size: 10.5px; font-weight: 600; color: rgba(255,255,255,0.4); }
.nav-group-title.current .nav-count { color: rgba(255,255,255,0.7); }
.nav-group-title::after { margin-left: 8px; }
.nav-link.nav-tool::before { content: '›'; margin-right: 6px; color: var(--orange-300); }
.app-card h2.section-header { margin: 0; padding: 0; background: none; border: none; font-size: 16px; }
.app-card { scroll-margin-top: 84px; }
.app-card:target { border-color: var(--color-brand-border); box-shadow: 0 0 0 3px var(--blue-50); }
.app-links li.is-tool a:first-child { color: var(--fg-1); }
.tool-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-accent);
  background: var(--color-accent-light); border: 1px solid var(--color-accent-border); border-radius: var(--radius-full); padding: 1px 7px; }

/* ── Dashboard: date range, figures, charts ─────────────────────────────── */
.dash-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 20px; }
.range-presets { display: flex; flex-wrap: wrap; gap: 4px; background: var(--bg-surface); border: 1px solid var(--border-1);
  border-radius: var(--radius-md); padding: 4px; }
.range-chip, .range-chip:link, .range-chip:visited { padding: 6px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  font-family: var(--font-ui); color: var(--fg-2); text-decoration: none; white-space: nowrap; }
.range-chip:hover { background: var(--bg-surface-2); color: var(--fg-1); }
.range-chip.active, .range-chip.active:link, .range-chip.active:visited { background: var(--color-brand); color: #fff; }
.range-custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.range-custom label { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--fg-3); font-family: var(--font-ui); }
.range-custom input[type=date] { min-height: 32px; height: 32px; padding: 0 8px; font-size: 12.5px; }

.stat-foot { margin-top: 10px; font-size: 12px; font-family: var(--font-ui); display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
.stat-sub { color: var(--fg-muted); font-size: 11.5px; }
.stat-foot > div.stat-sub { flex-basis: 100%; }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--fg-2); }
.delta-up { color: var(--fg-1); }
.delta-down { color: var(--fg-1); }
.delta-flat { color: var(--fg-3); }

.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.chart-card { padding: 16px 18px 12px; min-width: 0; }
.chart-wide { grid-column: 1 / -1; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.chart-head h2 { margin: 0; padding: 0; background: none; border: none; font-size: 15px; }
.chart-total { font-size: 12.5px; color: var(--fg-3); font-family: var(--font-ui); font-variant-numeric: tabular-nums; }
.chart { position: relative; min-height: 120px; }
.chart svg { display: block; overflow: visible; }
.chart svg rect[tabindex]:focus { outline: none; }
.chart svg rect[tabindex]:focus-visible { outline: 2px solid var(--blue-400); outline-offset: -2px; }
.chart-axis { font-size: 11px; fill: var(--fg-muted); font-family: var(--font-ui); font-variant-numeric: tabular-nums; }
.chart-label { font-size: 12.5px; fill: var(--fg-2); font-family: var(--font-ui); font-weight: 600; }
.chart-value { font-size: 12.5px; fill: var(--fg-1); font-family: var(--font-ui); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-empty { height: 160px; display: flex; align-items: center; justify-content: center; color: var(--fg-muted); font-size: 13px;
  border: 1px dashed var(--border-2); border-radius: var(--radius-md); }
.chart-tip { position: absolute; pointer-events: none; z-index: 5; background: var(--gray-900); color: #fff; border-radius: var(--radius-md);
  padding: 6px 10px; box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: 1px; white-space: nowrap; }
.chart-tip strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.chart-tip[hidden] { display: none; }
.chart-tip span { font-size: 11px; color: rgba(255,255,255,0.7); }
.chart-table { margin-top: 6px; }
.chart-table summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--fg-brand); font-family: var(--font-ui); padding: 4px 0; }
.chart-table table { width: 100%; margin-top: 6px; font-size: 12.5px; }
.chart-table th, .chart-table td { padding: 5px 8px; text-align: left; }
.chart-table td:last-child, .chart-table th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.chart-table table { display: block; max-height: 240px; overflow-y: auto; }
.chart-table thead, .chart-table tbody { display: table; width: 100%; table-layout: fixed; }

.snapshot-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; padding: 16px 18px; }
.snapshot-row .stat-label { margin-bottom: 6px; }
.snapshot-value { font-family: var(--font-display); font-weight: 800; font-size: 24px; color: var(--fg-1); font-variant-numeric: tabular-nums; }
.dash-section-title { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--fg-1); margin: 8px 0 12px; padding: 0;
  background: none; text-transform: none; letter-spacing: 0; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: minmax(0, 1fr); } }
.dash-export { margin-left: auto; }
.object-tools a.exportlink::before { content: '↓'; font-weight: 700; }
#result_list td a { white-space: nowrap; }
@media (max-width: 640px) {
  #changelist-filter.filter-bar { flex-direction: column; align-items: stretch; }
  .filter-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-field { min-width: 0; max-width: none; }
  .filter-actions { margin-left: 0; height: auto; }
}
#changelist-filter #changelist-filter-extra-actions { border: none; padding: 0; margin: 0 0 0 auto; }
@media (max-width: 640px) { #changelist-filter #changelist-filter-extra-actions { margin-left: 0; } }

/* Coded values (status, type, flags) as labelled pills — see apps/backoffice/labels.py */
.pill { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: var(--radius-full); border: 1px solid;
  font-family: var(--font-ui); font-size: 11.5px; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.pill-success { background: var(--green-50); color: var(--green-700); border-color: var(--green-100); }
.pill-warning { background: var(--amber-50); color: var(--amber-700); border-color: var(--amber-100); }
.pill-info { background: var(--indigo-50); color: var(--indigo-700); border-color: var(--indigo-100); }
.pill-danger { background: var(--red-50); color: var(--red-700); border-color: var(--red-100); }
.pill-neutral { background: var(--gray-50); color: var(--gray-600); border-color: var(--gray-200); }
#result_list td.field-status { font-weight: 400; }

/* Row actions: Edit/View and Delete at the end of each list row */
#result_list td.field-row_actions, #result_list th.column-row_actions { width: 1%; white-space: nowrap; text-align: right; }
#result_list th.column-row_actions .text span { padding: 11px 16px; display: block; }
.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }
.row-btn, a.row-btn:link, a.row-btn:visited { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px;
  border-radius: var(--radius-md); border: 1px solid var(--border-2); background: var(--bg-surface); color: var(--fg-2);
  font-family: var(--font-ui); font-size: 12px; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1; }
.row-btn:hover { background: var(--color-brand-light); border-color: var(--color-brand-border); color: var(--color-brand); }
.row-btn-danger { color: var(--red-700); }
.row-btn-danger:hover { background: var(--red-50); border-color: var(--red-100); color: var(--red-700); }
@media (max-width: 900px) { .row-btn span { display: none; } .row-btn { padding: 0 8px; } }
/* Keep the Actions column in view on wide tables */
#result_list th.column-row_actions, #result_list td.field-row_actions { position: sticky; right: 0; z-index: 1;
  background: inherit; box-shadow: -8px 0 8px -8px rgba(3,17,30,0.12); }
#result_list thead th.column-row_actions { background: var(--bg-surface); }
#result_list tbody tr td.field-row_actions { background: var(--bg-surface); }
#result_list tbody tr:hover td.field-row_actions { background: var(--bg-surface-2); }
#result_list tbody tr.selected td.field-row_actions { background: var(--orange-50); }

/* ── KIVI additions (dashboard panels, tool tables, alert bell) ─────────── */
.topbar-alerts { position: relative; }
.topbar-alerts .alert-count { background: var(--color-error); color: #fff; border-radius: var(--radius-full); font-size: 11px; font-weight: 700;
  min-width: 18px; padding: 1px 6px; line-height: 16px; text-align: center; }
.kivi-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--space-4); margin: var(--space-4) 0; }
.kivi-panels .dash-card { display: flex; flex-direction: column; }
#content table.kivi-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
#content table.kivi-table th { text-align: left; font-family: var(--font-ui); font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--fg-3); background: var(--bg-surface-2); padding: 8px 12px; }
#content table.kivi-table td { padding: 9px 12px; vertical-align: middle; color: var(--fg-2); }
#content table.kivi-table tbody tr:hover td { background: var(--bg-surface-2); }
.kivi-matrix td, .kivi-matrix th { white-space: nowrap; }
.kivi-center { text-align: center !important; }
.kivi-empty { color: var(--fg-muted); padding: 14px 12px; }
.kivi-more { display: block; margin-top: auto; padding: 10px 14px; font-size: var(--text-sm); font-weight: 600; border-top: 1px solid var(--border-1); }
.kivi-work, .kivi-alerts { list-style: none; margin: 0; padding: 0; }
.kivi-work li a { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border-1); color: var(--fg-2); }
.kivi-work li a:hover { background: var(--bg-surface-2); text-decoration: none; }
.kivi-alerts li { display: flex; justify-content: space-between; gap: var(--space-3); padding: 10px 14px; border-bottom: 1px solid var(--border-1); font-size: var(--text-sm); }
.kivi-alert-meta { color: var(--fg-muted); white-space: nowrap; font-size: 12px; }
