/* ==========================================================================
   ImportExport design system
   Visual direction inspired by the Vuexy vertical-menu admin template.
   Hand-written; no third-party CSS framework. See docs/UI_UX_Guidelines.md.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  --primary: #7367f0;
  --primary-rgb: 115, 103, 240;
  --primary-hover: #685dd8;
  --secondary: #808390;
  --secondary-rgb: 128, 131, 144;
  --success: #28c76f;
  --success-rgb: 40, 199, 111;
  --info: #00bad1;
  --info-rgb: 0, 186, 209;
  --warning: #ff9f43;
  --warning-rgb: 255, 159, 67;
  --danger: #ff4c51;
  --danger-rgb: 255, 76, 81;

  --body-bg: #f8f7fa;
  --surface: #ffffff;
  --surface-alt: #f6f6f8;
  --heading: #444050;
  --text: #6d6b77;
  --muted: #9a98a3;
  --border: #e6e6e8;
  --input-border: #d1d0d4;
  --hover-bg: rgba(47, 43, 61, 0.05);
  --shadow-sm: 0 0.125rem 0.375rem rgba(47, 43, 61, 0.12);
  --shadow: 0 0.1875rem 0.75rem rgba(47, 43, 61, 0.14);
  --shadow-lg: 0 0.625rem 1.25rem rgba(47, 43, 61, 0.18);
  --backdrop: rgba(23, 21, 31, 0.5);

  --font: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 78px;
  --topbar-h: 62px;
  --gutter: 1.5rem;
  --transition: 0.2s ease;
  color-scheme: light;
}

[data-theme="dark"] {
  --body-bg: #25293c;
  --surface: #2f3349;
  --surface-alt: #2a2e42;
  --heading: #e1def5;
  --text: #b2b1cb;
  --muted: #7c7d98;
  --border: #44485e;
  --input-border: #56596f;
  --hover-bg: rgba(225, 222, 245, 0.06);
  --shadow-sm: 0 0.125rem 0.375rem rgba(15, 20, 34, 0.24);
  --shadow: 0 0.1875rem 0.75rem rgba(15, 20, 34, 0.3);
  --shadow-lg: 0 0.625rem 1.25rem rgba(15, 20, 34, 0.4);
  --backdrop: rgba(10, 12, 20, 0.65);
  color-scheme: dark;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--body-bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5 { margin: 0 0 0.5rem; color: var(--heading); font-weight: 600; line-height: 1.3; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.125rem; }
p { margin: 0 0 1rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
code, .ref-code { font-family: var(--mono); font-size: 0.85em; }
[hidden] { display: none !important; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
:focus-visible { outline: 2px solid rgba(var(--primary-rgb), 0.6); outline-offset: 2px; }

.icon { width: 1.25rem; height: 1.25rem; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.icon.flip { transform: rotate(180deg); }
.text-muted { color: var(--muted) !important; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-uppercase { text-transform: uppercase; }
.text-end { text-align: end; }
.nowrap { white-space: nowrap; }
.fw-semibold { font-weight: 600; color: var(--heading); }
.skip-link { position: absolute; left: -999px; top: 0.5rem; z-index: 2000; background: var(--primary); color: #fff; padding: 0.5rem 1rem; border-radius: var(--radius); }
.skip-link:focus { left: 0.5rem; }

/* ---------- 3. Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.layout-page { flex: 1; min-width: 0; display: flex; flex-direction: column; margin-left: var(--sidebar-w); transition: margin-left var(--transition); }
.content { flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; padding: var(--gutter); }
.content:focus { outline: none; }

/* Sidebar */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 1100;
  width: var(--sidebar-w); display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow-sm);
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; height: var(--topbar-h); padding: 0 1rem 0 1.4rem; flex-shrink: 0; }
.brand { display: inline-flex; align-items: center; gap: 0.65rem; color: var(--heading); font-weight: 700; font-size: 1.3rem; letter-spacing: -0.01em; white-space: nowrap; }
.brand:hover { color: var(--heading); }
.brand-logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.4); flex-shrink: 0; }
.brand-logo .icon { width: 1.3rem; height: 1.3rem; }
.sidebar-pin { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--heading); background: transparent; color: var(--heading); cursor: pointer; padding: 0; transition: transform var(--transition); }
.sidebar-pin .icon { width: 0.95rem; height: 0.95rem; stroke-width: 2.5; }

.menu { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0.25rem 0 1.5rem; scrollbar-width: thin; }
.menu-header { padding: 1.25rem 1.6rem 0.4rem; font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); white-space: nowrap; }
.menu-list { list-style: none; margin: 0; padding: 0 0.875rem; }
.menu-link {
  display: flex; align-items: center; gap: 0.6rem; margin: 2px 0; padding: 0.55rem 0.9rem; border-radius: var(--radius);
  color: var(--text); font-size: 0.9375rem; white-space: nowrap; transition: background var(--transition), color var(--transition);
}
.menu-link .icon { width: 1.35rem; height: 1.35rem; }
.menu-link:hover { background: var(--hover-bg); color: var(--heading); }
.menu-link.active {
  color: #fff; background: linear-gradient(270deg, rgba(var(--primary-rgb), 0.7) 0%, var(--primary) 100%);
  box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.45);
}
.menu-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* Collapsed (desktop) — expands on hover like Vuexy */
@media (min-width: 1200px) {
  .sidebar-collapsed .layout-page { margin-left: var(--sidebar-w-collapsed); }
  .sidebar-collapsed .sidebar:not(:hover) { width: var(--sidebar-w-collapsed); }
  .sidebar-collapsed .sidebar:not(:hover) .brand-text,
  .sidebar-collapsed .sidebar:not(:hover) .sidebar-pin,
  .sidebar-collapsed .sidebar:not(:hover) .menu-text,
  .sidebar-collapsed .sidebar:not(:hover) .menu-header span { visibility: hidden; }
  .sidebar-collapsed .sidebar:not(:hover) .menu-header::before { content: ""; display: block; height: 1px; margin-top: 0.5rem; background: var(--border); }
  .sidebar-collapsed .sidebar:not(:hover) .menu-link { justify-content: center; }
  .sidebar-collapsed .sidebar:hover { box-shadow: var(--shadow-lg); }
  .sidebar-collapsed .sidebar-pin { transform: rotate(180deg); }
  .topbar-toggle { display: none !important; }
}
.sidebar-backdrop { display: none; }

@media (max-width: 1199.98px) {
  .layout-page { margin-left: 0; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar-pin { display: none; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 1090; background: var(--backdrop); }
  .sidebar-open { overflow: hidden; }
}

/* Topbar */
.topbar {
  position: sticky; top: 0.75rem; z-index: 1000;
  display: flex; align-items: center; gap: 0.75rem;
  height: var(--topbar-h); margin: 0.75rem var(--gutter) 0; padding: 0 0.75rem 0 1rem;
  background: var(--surface); background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(8px); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.context-chip { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.context-icon { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius); background: rgba(var(--primary-rgb), 0.16); color: var(--primary); flex-shrink: 0; }
.context-icon.is-platform { background: rgba(var(--warning-rgb), 0.18); color: var(--warning); }
.context-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.context-text strong { color: var(--heading); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.context-text small { color: var(--muted); font-size: 0.78rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.35rem; }

.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--heading); cursor: pointer; transition: background var(--transition); }
.icon-btn:hover { background: var(--hover-bg); }
.icon-btn-outline { border-radius: var(--radius); border: 1px solid var(--input-border); }
.theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-icon-dark { display: none; }

.user-btn { display: flex; align-items: center; gap: 0.6rem; padding: 0.25rem 0.4rem; border: 0; border-radius: var(--radius); background: transparent; color: var(--heading); cursor: pointer; font: inherit; text-align: left; }
.user-btn:hover { background: var(--hover-bg); }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-weight: 600; font-size: 0.9rem; }
.user-meta small { color: var(--muted); font-size: 0.78rem; }

.avatar { position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: rgba(var(--primary-rgb), 0.16); color: var(--primary); font-weight: 600; font-size: 0.875rem; flex-shrink: 0; }
.avatar-sm { width: 32px; height: 32px; font-size: 0.78rem; border-radius: var(--radius); }
.avatar-status { position: absolute; right: 0; bottom: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 2px var(--surface); }

.footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; max-width: 1440px; width: 100%; margin: 0 auto; padding: 1rem var(--gutter) 1.25rem; font-size: 0.85rem; color: var(--muted); }

@media (max-width: 767.98px) {
  :root { --gutter: 1rem; }
  .user-meta, .hide-sm { display: none; }
  .context-text small { display: none; }
}

/* Page heading + breadcrumbs */
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin: 0.5rem 0 1.5rem; }
.page-title { margin: 0 0 0.15rem; font-size: 1.375rem; }
.breadcrumb { display: flex; flex-wrap: wrap; list-style: none; margin: 0; padding: 0; font-size: 0.875rem; color: var(--muted); }
.breadcrumb li + li::before { content: "/"; padding: 0 0.5rem; color: var(--muted); }
.breadcrumb a { color: var(--text); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb [aria-current] { color: var(--muted); }

/* ---------- 4. Cards ---------- */
.card { position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.25rem 1.5rem 0.75rem; }
.card-title { margin: 0; font-size: 1.125rem; }
.card-subtitle { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.875rem; }
.card-body { padding: 1.25rem 1.5rem 1.5rem; }

.welcome-card { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; padding: 1.5rem 1.75rem; overflow: hidden; }
.welcome-body { max-width: 640px; }
.welcome-body h2 { font-size: 1.25rem; }
.welcome-art { display: grid; place-items: center; width: 120px; height: 120px; border-radius: 50%; background: rgba(var(--primary-rgb), 0.12); color: var(--primary); flex-shrink: 0; }
.welcome-art .icon { width: 64px; height: 64px; stroke-width: 1.25; }
@media (max-width: 767.98px) { .welcome-art { display: none; } }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.stat-card { display: flex; align-items: center; gap: 1rem; padding: 1.25rem 1.4rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card > div { display: flex; flex-direction: column; min-width: 0; }
.stat-icon { display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: var(--radius); flex-shrink: 0; }
.stat-icon .icon { width: 1.6rem; height: 1.6rem; }
.stat-label { font-size: 0.875rem; color: var(--text); }
.stat-value { font-size: 1.5rem; font-weight: 600; color: var(--heading); line-height: 1.3; min-height: 1.95rem; }
.stat-value.is-pending { color: var(--muted); }
.stat-hint { font-size: 0.78rem; color: var(--muted); }
.tone-primary { background: rgba(var(--primary-rgb), 0.16); color: var(--primary); }
.tone-success { background: rgba(var(--success-rgb), 0.16); color: var(--success); }
.tone-info { background: rgba(var(--info-rgb), 0.16); color: var(--info); }
.tone-warning { background: rgba(var(--warning-rgb), 0.16); color: var(--warning); }
.tone-danger { background: rgba(var(--danger-rgb), 0.16); color: var(--danger); }

/* ---------- 5. Buttons & badges ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.5rem 1.15rem; border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-weight: 500; font-size: 0.9375rem; line-height: 1.4; cursor: pointer; white-space: nowrap;
  transition: background var(--transition), box-shadow var(--transition), color var(--transition), transform 0.1s;
  user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn.is-busy { opacity: 0.65; cursor: not-allowed; }
.btn .icon { width: 1.1rem; height: 1.1rem; }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.65rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.4); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 2px 6px rgba(var(--danger-rgb), 0.4); }
.btn-danger:hover { filter: brightness(0.95); color: #fff; }
.btn-success { background: var(--success); color: #fff; box-shadow: 0 2px 6px rgba(var(--success-rgb), 0.4); }
.btn-success:hover { filter: brightness(0.95); color: #fff; }
.btn-label-primary { background: rgba(var(--primary-rgb), 0.16); color: var(--primary); }
.btn-label-primary:hover { background: rgba(var(--primary-rgb), 0.24); color: var(--primary); }
.btn-label-secondary { background: rgba(var(--secondary-rgb), 0.16); color: var(--secondary); }
.btn-label-secondary:hover { background: rgba(var(--secondary-rgb), 0.24); color: var(--secondary); }
.btn-outline { border-color: var(--input-border); background: transparent; color: var(--heading); }
.btn-outline:hover { background: var(--hover-bg); }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 50%; background: transparent; color: var(--text); }
.btn-icon:hover { background: var(--hover-bg); color: var(--heading); }
.btn-icon.is-danger:hover { background: rgba(var(--danger-rgb), 0.12); color: var(--danger); }
.btn-icon.is-success:hover { background: rgba(var(--success-rgb), 0.12); color: var(--success); }

.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.6rem; border-radius: var(--radius-sm); font-size: 0.8125rem; font-weight: 500; line-height: 1.4; white-space: nowrap; }
.badge-label-primary { background: rgba(var(--primary-rgb), 0.16); color: var(--primary); }
.badge-label-success { background: rgba(var(--success-rgb), 0.16); color: var(--success); }
.badge-label-danger { background: rgba(var(--danger-rgb), 0.16); color: var(--danger); }
.badge-label-warning { background: rgba(var(--warning-rgb), 0.16); color: var(--warning); }
.badge-label-info { background: rgba(var(--info-rgb), 0.16); color: var(--info); }
.badge-label-secondary { background: rgba(var(--secondary-rgb), 0.16); color: var(--secondary); }
.badge-code { font-family: var(--mono); font-size: 0.78rem; background: var(--surface-alt); color: var(--heading); border: 1px solid var(--border); }

/* ---------- 6. Forms ---------- */
.form-stack { display: flex; flex-direction: column; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 575.98px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }
.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.label { font-size: 0.8125rem; font-weight: 500; color: var(--heading); }
.label.required::after { content: " *"; color: var(--danger); }
.input {
  display: block; width: 100%; padding: 0.5rem 0.9rem; font: inherit; font-size: 0.9375rem; line-height: 1.5;
  color: var(--heading); background: var(--surface); border: 1px solid var(--input-border); border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input::placeholder { color: var(--muted); }
.input:focus { outline: none; border-color: var(--primary); border-width: 2px; padding: calc(0.5rem - 1px) calc(0.9rem - 1px); box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.3); }
.input:disabled, .input[readonly] { background: var(--surface-alt); color: var(--muted); }
.input.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus { box-shadow: 0 2px 6px rgba(var(--danger-rgb), 0.3); }
.select { appearance: none; padding-right: 2.25rem; background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8893' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M6 9l6 6l6 -6'/%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right 0.75rem center; background-size: 1rem; }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%); color: var(--muted); width: 1.1rem; height: 1.1rem; pointer-events: none; }
.input-icon > .input { padding-left: 2.5rem; }
.input-icon > .input:focus { padding-left: calc(2.5rem - 1px); }
.field-hint { font-size: 0.78rem; color: var(--muted); }
.field-error { font-size: 0.8125rem; color: var(--danger); }
.field-error:empty { display: none; }
.validation-summary-valid { display: none; }
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }

/* ---------- 7. Alerts ---------- */
.alert { display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.75rem 1rem; border-radius: var(--radius); font-size: 0.9rem; margin-bottom: 1rem; }
.alert .icon { margin-top: 1px; }
.alert-danger { background: rgba(var(--danger-rgb), 0.14); color: var(--danger); }
.alert-info { background: rgba(var(--info-rgb), 0.14); color: var(--info); }
.alert-warning { background: rgba(var(--warning-rgb), 0.16); color: var(--warning); }
.alert-success { background: rgba(var(--success-rgb), 0.14); color: var(--success); }

/* ---------- 8. Data table ---------- */
.table-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); }
.toolbar-search { flex: 1 1 260px; max-width: 360px; }
.toolbar-filters { display: flex; align-items: center; gap: 0.5rem; }
.toolbar-filters .select { min-width: 150px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th, .table td { padding: 0.8rem 1.25rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th:first-child, .table td:first-child { padding-left: 1.5rem; }
.table th:last-child, .table td:last-child { padding-right: 1.5rem; }
.table .text-end { text-align: right; }
.table thead th { font-size: 0.8125rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.2px; color: var(--heading); white-space: nowrap; background: transparent; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--hover-bg); }
.table tbody tr:last-child td { border-bottom: 0; }
.th-sort { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0; border: 0; background: none; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; }
.th-sort .icon { width: 0.95rem; height: 0.95rem; opacity: 0.4; }
.th-sort.is-sorted .icon { opacity: 1; color: var(--primary); }
.cell-entity { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.cell-entity > div { display: flex; flex-direction: column; min-width: 0; }
.cell-entity strong { color: var(--heading); font-weight: 500; }
.cell-entity small { color: var(--muted); font-size: 0.8125rem; }
.cell-actions { display: flex; justify-content: flex-end; gap: 0.15rem; }
.table-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); font-size: 0.875rem; color: var(--muted); }
.page-size { display: inline-flex; align-items: center; gap: 0.5rem; }
.page-size .select { width: auto; padding-top: 0.3rem; padding-bottom: 0.3rem; }
.pagination { display: flex; gap: 0.25rem; list-style: none; margin: 0; padding: 0; }
.page-btn { display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 0.5rem; border: 0; border-radius: 50%; background: rgba(var(--secondary-rgb), 0.12); color: var(--heading); font: inherit; font-size: 0.875rem; cursor: pointer; transition: background var(--transition); }
.page-btn:hover:not(:disabled) { background: rgba(var(--primary-rgb), 0.16); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.4); }
.page-btn:disabled { opacity: 0.45; cursor: default; }
.page-btn .icon { width: 1rem; height: 1rem; }

/* Loading / empty / error */
.skeleton { display: inline-block; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-alt) 25%, var(--hover-bg) 37%, var(--surface-alt) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skeleton-text { width: 70%; height: 0.9rem; }
.skeleton-row td { padding-top: 1.05rem; padding-bottom: 1.05rem; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.5rem; padding: 3rem 1.5rem; }
.empty-state h3 { margin: 0.5rem 0 0; }
.empty-state p { max-width: 460px; margin-bottom: 0.75rem; }
.empty-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: rgba(var(--primary-rgb), 0.12); color: var(--primary); }
.empty-icon .icon { width: 2rem; height: 2rem; }
.empty-icon.is-danger { background: rgba(var(--danger-rgb), 0.12); color: var(--danger); }
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.ref-code { padding: 0.35rem 0.6rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); color: var(--heading); margin-bottom: 1rem; }

/* ---------- 9. Tabs ---------- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab { position: relative; padding: 0.6rem 1rem; border: 0; background: none; font: inherit; font-weight: 500; color: var(--text); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); }
.tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--primary); }
.tab.has-error::before { content: ""; position: absolute; top: 0.55rem; right: 0.35rem; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in 0.15s ease; }

/* ---------- 10. Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 1200; display: flex; align-items: flex-start; justify-content: center; padding: 3rem 1rem; overflow-y: auto; background: var(--backdrop); animation: fade-in 0.15s ease; }
.modal-dialog { width: 100%; max-width: 520px; animation: slide-down 0.2s ease; }
.modal-lg { max-width: 760px; }
.modal-sm { max-width: 420px; }
.modal-content { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.5rem 1.5rem 0.5rem; }
.modal-title { margin: 0; font-size: 1.25rem; }
.modal-subtitle { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.875rem; }
.modal-body { padding: 1rem 1.5rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.75rem; padding: 0.75rem 1.5rem 1.5rem; }
.modal-open { overflow: hidden; }
.confirm-dialog-body { padding-top: 1.5rem; }
.confirm-body { display: flex; gap: 1rem; align-items: flex-start; }
.confirm-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-down { from { transform: translateY(-16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 11. Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 0.5rem); z-index: 1150; min-width: 240px; padding: 0.5rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); display: none; }
.dropdown.open .dropdown-menu { display: block; animation: fade-in 0.12s ease; }
.dropdown-header { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem; }
.dropdown-header > div { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.dropdown-header strong { color: var(--heading); font-weight: 600; }
.dropdown-header small { color: var(--muted); font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; }
.dropdown-divider { height: 1px; margin: 0.4rem 0; background: var(--border); }
.dropdown-item { display: flex; align-items: center; gap: 0.6rem; width: 100%; padding: 0.55rem 0.75rem; border: 0; border-radius: var(--radius); background: none; font: inherit; color: var(--heading); text-align: left; cursor: pointer; }
.dropdown-item:hover { background: var(--hover-bg); }

/* ---------- 12. Toasts ---------- */
.toast-stack { position: fixed; top: 1.25rem; right: 1.25rem; z-index: 1300; display: flex; flex-direction: column; gap: 0.75rem; width: min(380px, calc(100vw - 2.5rem)); pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.9rem 1rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); pointer-events: auto; animation: toast-in 0.25s ease; border-left: 4px solid var(--toast-color, var(--primary)); }
.toast.is-leaving { animation: toast-out 0.2s ease forwards; }
.toast-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; color: var(--toast-color); background: rgba(var(--toast-rgb), 0.16); }
.toast-icon .icon { width: 1.1rem; height: 1.1rem; }
.toast-body { flex: 1; min-width: 0; font-size: 0.875rem; }
.toast-body strong { display: block; color: var(--heading); font-weight: 600; margin-bottom: 0.1rem; }
.toast-close { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; }
.toast-success { --toast-color: var(--success); --toast-rgb: var(--success-rgb); }
.toast-error { --toast-color: var(--danger); --toast-rgb: var(--danger-rgb); }
.toast-info { --toast-color: var(--info); --toast-rgb: var(--info-rgb); }
.toast-warning { --toast-color: var(--warning); --toast-rgb: var(--warning-rgb); }
@keyframes toast-in { from { transform: translateX(110%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateX(110%); opacity: 0; } }

/* ---------- 13. Auth pages ---------- */
.auth-body { background: var(--surface); }
.auth-wrapper { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(380px, 1fr); min-height: 100vh; }
.auth-illustration { display: grid; place-items: center; padding: 3rem; background: var(--body-bg); }
.auth-illustration-inner { max-width: 480px; }
.auth-hero-badge { display: grid; place-items: center; width: 84px; height: 84px; margin-bottom: 1.5rem; border-radius: 22px; background: var(--primary); color: #fff; box-shadow: 0 8px 24px rgba(var(--primary-rgb), 0.45); }
.auth-hero-badge .icon { width: 44px; height: 44px; stroke-width: 1.5; }
.auth-illustration h2 { font-size: 1.75rem; }
.auth-points { list-style: none; margin: 1.5rem 0 0; padding: 0; display: grid; gap: 0.85rem; }
.auth-points li { display: flex; align-items: center; gap: 0.75rem; color: var(--heading); }
.auth-points .icon { width: 2rem; height: 2rem; padding: 0.4rem; border-radius: var(--radius); background: rgba(var(--primary-rgb), 0.16); color: var(--primary); }
.auth-panel { display: grid; place-items: center; padding: 2rem 1.5rem; }
.auth-card { width: 100%; max-width: 400px; }
.brand-lg { margin-bottom: 2rem; }
.auth-title { font-size: 1.5rem; margin-top: 0.5rem; }
.auth-footnote { display: flex; align-items: center; gap: 0.4rem; margin-top: 1.5rem; font-size: 0.8125rem; }
.auth-footnote .icon { width: 1rem; height: 1rem; }
.auth-credit { margin-top: 0.5rem; }
@media (max-width: 991.98px) { .auth-wrapper { grid-template-columns: 1fr; } .auth-illustration { display: none; } }

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

/* ==========================================================================
   Phase 1 — Administration (checkboxes, permission matrix, profile, misc)
   ========================================================================== */
.check { display: inline-flex; align-items: flex-start; gap: 0.6rem; cursor: pointer; color: var(--heading); font-size: 0.9rem; line-height: 1.35; }
.check input { width: 1.05rem; height: 1.05rem; margin: 0.12rem 0 0; flex-shrink: 0; accent-color: var(--primary); cursor: pointer; }
.check input:disabled, .check input:disabled + span { cursor: not-allowed; }
.check small { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 0.1rem; }

.perm-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; margin: 1.25rem 0 0.75rem; }
.perm-toolbar h3 { margin: 0; font-size: 1rem; }
.perm-toolbar .perm-count { color: var(--muted); font-size: 0.85rem; margin-left: 0.4rem; font-weight: 400; }
.perm-actions { display: flex; gap: 0.5rem; }
.perm-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; max-height: 48vh; overflow-y: auto; padding: 0.15rem 0.25rem 0.15rem 0; }
.perm-group { border: 1px solid var(--border); border-radius: var(--radius); align-self: start; }
.perm-group-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 0.9rem; background: var(--surface-alt); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.perm-group-header .check { font-weight: 600; }
.perm-group-header small { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.perm-list { list-style: none; margin: 0; padding: 0.6rem 0.9rem 0.8rem; display: flex; flex-direction: column; gap: 0.6rem; }
.perm-item.is-locked { opacity: 0.55; }
@media (max-width: 767.98px) { .perm-groups { grid-template-columns: 1fr; max-height: none; } }

.form-section { margin-bottom: 1.5rem; }
.form-section:last-child { margin-bottom: 0; }
.form-section-title { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.9rem; font-size: 0.8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.form-section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.card-footer { display: flex; justify-content: flex-end; gap: 0.75rem; padding: 1rem 1.5rem 1.5rem; }
.badges { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; }
.badge .icon { width: 0.9rem; height: 0.9rem; }
.page-back { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.875rem; }
.page-back .icon { width: 1rem; height: 1rem; }
.cell-muted { color: var(--muted); font-size: 0.85rem; }

/* ==========================================================================
   Phase 2 — Masters
   ========================================================================== */
textarea.input { resize: vertical; min-height: 4.75rem; }
.field-hint .icon { width: 0.85rem; height: 0.85rem; vertical-align: -2px; }
.field > .check { margin-top: 0.15rem; }

/* ==========================================================================
   Phase 3 — Purchases (document list, view and Draft editor)
   ========================================================================== */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.toolbar-filters.is-wrap { flex-wrap: wrap; }
.toolbar-filters.is-wrap > .input { width: auto; max-width: 100%; }
.input-date { width: auto; min-width: 9.5rem; }
fieldset.form-grid { border: 0; margin: 0; padding: 0; min-width: 0; }
.pre-line { white-space: pre-line; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1.1rem 1.5rem; margin: 0; }
.doc-grid dt { margin-bottom: 0.2rem; font-size: 0.8125rem; color: var(--muted); }
.doc-grid dd { margin: 0; color: var(--heading); overflow-wrap: anywhere; }
.doc-grid dd small { display: block; color: var(--muted); font-size: 0.8125rem; }
.doc-grid .span-all { grid-column: 1 / -1; }

.doc-lines td { vertical-align: top; }
.doc-lines .line-no { width: 2.5rem; color: var(--muted); }
.doc-lines .cell-entity small + small { margin-top: 0.1rem; }
.doc-lines.is-editing th, .doc-lines.is-editing td { padding: 0.65rem 0.5rem; }
.doc-lines.is-editing th:first-child, .doc-lines.is-editing td:first-child { padding-left: 1.5rem; }
.doc-lines.is-editing th:last-child, .doc-lines.is-editing td:last-child { padding-right: 1.25rem; }
.doc-lines.is-editing tbody tr:hover { background: transparent; }
.doc-lines.is-editing [data-cell] { padding-top: 1.15rem; }
.doc-lines .line-product { min-width: 260px; }
.doc-lines .line-product .field-error, .doc-lines .line-product .input-sm { margin-top: 0.4rem; }
.doc-lines .line-num { min-width: 7.5rem; }
.doc-lines .line-rate { min-width: 5.75rem; }
.doc-lines .field-error { display: block; margin-top: 0.3rem; font-size: 0.78rem; }
.doc-lines .field-error:empty { display: none; }
.doc-lines .is-danger .icon { color: var(--danger); }
.line-meta { display: block; margin-top: 0.3rem; font-size: 0.78rem; color: var(--muted); }
.input-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.input-sm:focus { padding: calc(0.35rem - 1px) calc(0.7rem - 1px); }
.lines-empty { margin: 0; padding: 1.25rem 1.5rem; text-align: center; color: var(--muted); }
.lines-error { display: block; padding: 0 1.5rem; }

.doc-summary { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1.5rem; border-top: 1px solid var(--border); }
.doc-summary > .field-hint { margin: 0; max-width: 22rem; }
.totals { flex: 0 1 340px; margin: 0 0 0 auto; }
.totals > div { display: flex; justify-content: space-between; gap: 2rem; padding: 0.3rem 0; }
.totals dt { color: var(--text); }
.totals dd { margin: 0; color: var(--heading); font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals .is-grand { margin-top: 0.4rem; padding-top: 0.65rem; border-top: 1px solid var(--border); font-size: 1.05rem; font-weight: 600; }
.totals .is-grand dt { color: var(--heading); }
.doc-history { display: flex; flex-direction: column; gap: 0.45rem; margin: 0; padding: 0; list-style: none; font-size: 0.85rem; color: var(--muted); }
.doc-history li { display: flex; align-items: center; gap: 0.45rem; }
.doc-history .icon { width: 1rem; height: 1rem; }
.doc-history strong { color: var(--heading); font-weight: 500; }
@media (max-width: 575.98px) {
  .totals { flex-basis: 100%; }
  .doc-actions { width: 100%; }
  .doc-actions .btn { flex: 1 1 auto; justify-content: center; }
}
.line-meta.text-danger { color: var(--danger); }

/* ==========================================================================
   Phase 5 — Stock (current stock, history, opening stock)
   ========================================================================== */
.stat-card.is-filter { width: 100%; border: 1px solid transparent; font: inherit; color: inherit; text-align: start; cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.stat-card.is-filter:hover { border-color: rgba(var(--primary-rgb), 0.35); }
.stat-card.is-filter:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stat-card.is-filter[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary), var(--shadow); }
.table-note { margin: 0; padding: 0.85rem 1.5rem 1.25rem; font-size: 0.8125rem; color: var(--muted); }
.product-stock-body { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem 2rem; }
.product-stock-figures { display: flex; flex-wrap: wrap; gap: 0.75rem 2.25rem; margin: 0; }
.product-stock-figures dt { font-size: 0.8125rem; color: var(--muted); }
.product-stock-figures dd { margin: 0.15rem 0 0; color: var(--heading); font-weight: 600; font-variant-numeric: tabular-nums; }
.card-footer .footer-hint { margin: 0 auto 0 0; align-self: center; }
@media (max-width: 575.98px) {
  .stat-grid.is-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
  .stat-grid.is-filters .stat-card { padding: 0.9rem; gap: 0.65rem; }
  .stat-grid.is-filters .stat-icon { width: 36px; height: 36px; }
  .stat-grid.is-filters .stat-hint { display: none; }
  .card-footer { flex-wrap: wrap; }
  .card-footer .footer-hint { flex-basis: 100%; }
}

/* ==========================================================================
   Phase 6 — Company dashboard (ADR-018)
   ========================================================================== */
.stat-card.is-link { border: 1px solid transparent; color: inherit; text-decoration: none; transition: border-color 0.15s, box-shadow 0.15s; }
.stat-card.is-link:hover { border-color: rgba(var(--primary-rgb), 0.35); }
.stat-card.is-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dashboard-kpis .stat-value { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.dashboard-kpis .stat-hint .is-alert { color: var(--danger); font-weight: 600; }
.dashboard-actions { align-items: center; }
.dashboard-updated { font-size: 0.8125rem; color: var(--muted); }
.dashboard-split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.dashboard-split > .card { margin-bottom: 0; }
.dashboard-split > .card:only-child { grid-column: 1 / -1; }
.empty-state.is-compact { padding: 1.5rem; }
.empty-state.is-compact p { margin: 0; }
@media (max-width: 991.98px) {
  .dashboard-split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 575.98px) {
  .dashboard-kpis { gap: 0.75rem; }
  .dashboard-actions .dashboard-updated { flex: 1 1 auto; }
  .dashboard-split .table th, .dashboard-split .table td { padding: 0.7rem 0.4rem; }
  .dashboard-split .table th:first-child, .dashboard-split .table td:first-child { padding-left: 1rem; }
  .dashboard-split .table th:last-child, .dashboard-split .table td:last-child { padding-right: 1rem; }
}

/* ==========================================================================
   Phase 7 — Reports (ADR-019)
   ========================================================================== */
.num { font-variant-numeric: tabular-nums; }
.report-tabs { margin-bottom: 0; padding: 0 1.5rem; }
.report-toolbar { align-items: flex-start; }
.report-period { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.report-period .select { width: auto; min-width: 11rem; }
.report-period-sep { color: var(--muted); }
.report-period-error { flex-basis: 100%; }
.report-check { align-self: center; font-size: 0.875rem; }
.report-toolbar .toolbar-filters { flex: 1 1 auto; }
.report-toolbar .toolbar-search { flex: 1 1 200px; max-width: 300px; }
.report-gst-split { display: block; margin-top: 0.1rem; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.report-heading { padding: 1.1rem 1.5rem 0; }
.report-title { margin: 0; font-size: 1.05rem; }
.report-caption { margin: 0.2rem 0 0; font-size: 0.85rem; color: var(--muted); }
.report-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem 1.5rem; margin: 1rem 1.5rem 0.25rem; padding: 0.9rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-alt); }
.report-totals[hidden] { display: none; }
.report-totals dt { font-size: 0.78rem; color: var(--muted); }
.report-totals dd { margin: 0.15rem 0 0; color: var(--heading); font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.report-totals small { display: block; margin-top: 0.15rem; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.report-totals .is-grand dd { color: var(--primary); }
.report-total-row th, .report-total-row td { font-weight: 600; color: var(--heading); background: var(--surface-alt); border-top: 2px solid var(--border); }
.report-total-row th { text-align: left; }
@media (max-width: 575.98px) {
  .report-tabs { padding: 0 0.75rem; }
  .report-period { width: 100%; }
  .report-period .select { flex: 1 1 100%; }
  .report-period .input-date { flex: 1 1 0; min-width: 0; }
  .report-actions .btn { flex: 1 1 0; }
  .report-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 1rem 1rem 0.25rem; padding: 0.8rem 0.9rem; }
  .report-heading { padding: 1rem 1rem 0; }
}

/* Print: the page content only (used by the report pages; harmless elsewhere). Light colours regardless of the theme. */
@media print {
  :root, [data-theme="dark"] {
    --body-bg: #fff; --surface: #fff; --surface-alt: #f3f3f3; --heading: #111; --text: #333; --muted: #666; --border: #ccc;
    --primary: #111; --shadow: none;
  }
  body { background: #fff; }
  .sidebar, .sidebar-backdrop, .topbar, .footer, .skip-link, .toast-stack, .page-heading .doc-actions,
  .report-tabs, .report-toolbar, .table-footer, .table-note { display: none !important; }
  .layout-page { margin-left: 0 !important; }
  .content { max-width: none; padding: 0; }
  .page-heading { margin: 0 0 0.5rem; }
  .card { box-shadow: none; border: 0; }
  .report-heading { padding: 0; }
  .report-totals { margin: 0.75rem 0; }
  .table-wrap { overflow: visible; }
  .table { font-size: 9pt; }
  .table th, .table td, .table th:first-child, .table td:first-child, .table th:last-child, .table td:last-child { padding: 0.3rem 0.4rem; }
  .th-sort .icon { display: none; }
  .table tbody tr { break-inside: avoid; }
  .table a { color: inherit; text-decoration: none; }
}
