/*
 * RHL CRM — admin design system (also used by the sign-in screens).
 * Dashboard shell inspired by a collapsible-sidebar back-office layout; supports light and dark themes.
 */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 58px;
  --c-bg: #f5f7fb;
  --c-surface: #ffffff;
  --c-border: #e4e9f0;
  --c-text: #1e2d3d;
  --c-text-muted: #55637c;
  --c-primary: #3b5bdb;
  --c-primary-hover: #2f4ac7;
  --c-primary-soft: #eef2ff;
  --c-primary-ring: #c5d2ff;
  --c-on-primary: #ffffff;
  --c-success: #1f6b32;
  --c-success-soft: #e6f7ea;
  --c-danger: #c92a2a;
  --c-danger-soft: #fff0f0;
  --c-warning: #8a5200;
  --c-warning-soft: #fff6d6;
  --c-info: #1c5fa8;
  --c-info-soft: #e7f1fd;
  --c-row-hover: #f8faff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-lg: 0 10px 40px rgba(30, 45, 61, .12), 0 4px 12px rgba(30, 45, 61, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Type scale: use only these sizes and weights */
  --fs-xs: .75rem;    /* 12px: badges, table headers, captions */
  --fs-sm: .875rem;   /* 14px: tables, labels, buttons, hints, nav */
  --fs-base: 1rem;    /* 16px: body text, inputs */
  --fs-lg: 1.125rem;  /* 18px: card and section titles */
  --fs-xl: 1.5rem;    /* 24px: page titles */
  --fs-2xl: 1.875rem; /* 30px: stat numbers */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
}

html[data-theme="dark"] {
  --c-bg: #0b1220;
  --c-surface: #121d33;
  --c-border: #21304c;
  --c-text: #e6edf9;
  --c-text-muted: #a8b4cb;
  --c-primary: #7aa2ff;
  --c-primary-hover: #98b7ff;
  --c-primary-soft: #1a2b52;
  --c-primary-ring: #2d4a8c;
  --c-on-primary: #0b1220;
  --c-success: #6fd28b;
  --c-success-soft: #11281b;
  --c-danger: #ff8f8f;
  --c-danger-soft: #311418;
  --c-warning: #f5bd66;
  --c-warning-soft: #312611;
  --c-info: #8ec3ff;
  --c-info-soft: #12294a;
  --c-row-hover: #15233d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, .42);
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: var(--fw-semibold); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-base); }
p { margin: 0; }

:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }

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

/* ─── Sidebar ─── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  z-index: 50;
  transition: width .18s ease, transform .18s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 18px;
  border-bottom: 1px solid var(--c-border);
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 9px;
}

.sidebar-brand-name { font-weight: var(--fw-semibold); flex: 1; min-width: 0; }
.sidebar-toggle { margin-left: auto; }
.icon-btn.topbar-menu { display: none; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }

.sidebar-section {
  margin: 14px 10px 4px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--c-text-muted);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--c-text-muted);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}

.sidebar-link:hover { background: var(--c-primary-soft); color: var(--c-text); text-decoration: none; }
.sidebar-link { font-size: var(--fs-sm); }
.sidebar-link.is-active { background: var(--c-primary-soft); color: var(--c-primary); font-weight: var(--fw-semibold); }

.sidebar-footer { border-top: 1px solid var(--c-border); padding: 12px 14px; }
.sidebar-footer { position: relative; }
.sidebar-user {
  display: flex; align-items: center; gap: 10px; min-width: 0; width: 100%;
  padding: 6px; border: 0; border-radius: var(--radius); background: none;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.sidebar-user:hover, .sidebar-user[aria-expanded="true"] { background: var(--c-primary-soft); }
.sidebar-user-caret { margin-left: auto; display: grid; color: var(--c-text-muted); }

.user-menu {
  position: absolute;
  left: 14px;
  bottom: calc(100% - 8px);
  min-width: 200px;
  padding: 6px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
}
.user-menu[hidden] { display: none; }
.user-menu .inline-form { display: block; }
.user-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: 0; border-radius: 6px; background: none;
  color: var(--c-text); font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-medium);
  text-align: left; cursor: pointer;
}
.user-menu-item:hover { background: var(--c-primary-soft); color: var(--c-primary); text-decoration: none; }
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sidebar-user-info strong { font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-info small { color: var(--c-text-muted); font-size: var(--fs-xs); }

.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: var(--fw-semibold);
}

.sidebar-backdrop { display: none; }

html.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
html.sidebar-collapsed .sidebar-label,
html.sidebar-collapsed .sidebar-logo,
html.sidebar-collapsed .sidebar-brand-name { display: none; }
html.sidebar-collapsed .sidebar-brand,
html.sidebar-collapsed .sidebar-link { justify-content: center; padding-inline: 0; }
html.sidebar-collapsed .sidebar-toggle { margin-left: 0; }
html.sidebar-collapsed .sidebar-user { justify-content: center; }
html.sidebar-collapsed .admin-main { margin-left: var(--sidebar-w-collapsed); }

/* ─── Main + topbar ─── */
.admin-main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .18s ease; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}

.topbar-title { font-weight: var(--fw-semibold); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-nav { display: flex; align-items: center; gap: 8px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.admin-content { padding: 20px; width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text-muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--c-text); background: var(--c-primary-soft); }

.theme-icon--dark { display: none; }
html[data-theme="dark"] .theme-icon--light { display: none; }
html[data-theme="dark"] .theme-icon--dark { display: inline; }

/* ─── Page building blocks ─── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-subtitle, .page-header p { font-size: var(--fs-sm); }
.page-breadcrumb { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; color: var(--c-text-muted); font-size: var(--fs-xs); }
.page-breadcrumb a { color: var(--c-primary); font-weight: var(--fw-medium); }
.page-breadcrumb [aria-current] { color: var(--c-text); font-weight: var(--fw-medium); }
.page-breadcrumb-sep { color: var(--c-text-muted); }
.page-subtitle { margin-top: 4px; color: var(--c-text-muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 20px; }
.card-header { padding: 14px 20px; border-bottom: 1px solid var(--c-border); font-weight: var(--fw-semibold); }
.card + .card { margin-top: 20px; }
.stat-grid .card + .card { margin-top: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { padding: 18px 20px; }
.stat-label { color: var(--c-text-muted); font-size: var(--fs-sm); }
.stat-value { margin-top: 4px; font-size: var(--fs-2xl); font-weight: var(--fw-semibold); }

.empty-state { padding: 40px 20px; text-align: center; color: var(--c-text-muted); }
.empty-state h2 { color: var(--c-text); margin-bottom: 6px; }

/* ─── Tables ─── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.table th { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .4px; color: var(--c-text-muted); font-weight: var(--fw-semibold); white-space: nowrap; }
.table tbody tr:hover { background: var(--c-row-hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.cell-muted { color: var(--c-text-muted); font-size: var(--fs-sm); }
.cell-primary { font-weight: var(--fw-semibold); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--c-primary);
  border-radius: var(--radius);
  background: var(--c-primary);
  color: var(--c-on-primary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1.2;
  cursor: pointer;
}
.btn:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); text-decoration: none; }
.btn--ghost { background: transparent; color: var(--c-text); border-color: var(--c-border); }
.btn--ghost:hover { background: var(--c-primary-soft); border-color: var(--c-primary-ring); }
.btn--danger { background: transparent; color: var(--c-danger); border-color: var(--c-danger); }
.btn--danger:hover { background: var(--c-danger-soft); border-color: var(--c-danger); }
.btn--sm { padding: 6px 11px; }
.btn--block { width: 100%; justify-content: center; }

/* ─── Badges + flash ─── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; }
.badge--success { background: var(--c-success-soft); color: var(--c-success); }
.badge--info { background: var(--c-info-soft); color: var(--c-info); }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); }
.badge--muted { background: var(--c-border); color: var(--c-text-muted); }

.toast-stack { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  border-left-width: 4px;
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  animation: toast-in .2s ease;
}
.toast--notice { border-left-color: var(--c-success); }
.toast--alert { border-left-color: var(--c-danger); }
.toast.is-leaving { opacity: 0; transform: translateX(16px); transition: opacity .2s ease, transform .2s ease; }
.toast-message { flex: 1; min-width: 0; }
.toast-close { border: 0; background: none; color: var(--c-text-muted); font-size: var(--fs-lg); line-height: 1; cursor: pointer; padding: 0; }
.toast-close:hover { color: var(--c-text); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } }

/* ─── Filters ─── */
.filter-toolbar { padding: 12px; border-bottom: 1px solid var(--c-border); }
.filter-topbar { display: flex; align-items: center; gap: 12px; }
.filter-main-search { position: relative; flex: 1; }
.filter-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); display: grid; color: var(--c-text-muted); pointer-events: none; }
.filter-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-bg);
  color: var(--c-text);
  font: inherit;
  font-size: var(--fs-sm);
}
.filter-main-search .filter-input { padding-left: 36px; }
.filter-input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-ring); }
.filter-toolbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.filter-toolbar-actions .btn { height: 38px; }
.btn-icon { width: 38px; padding: 0; justify-content: center; }
.filter-dropdown { position: relative; }
.filter-dropdown .btn-icon { position: relative; }
.filter-dropdown .btn-icon.is-active { border-color: var(--c-primary); color: var(--c-primary); background: var(--c-primary-soft); }
.filter-badge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px;
  display: grid; place-items: center; border-radius: 9px;
  background: var(--c-primary); color: #fff; font-size: var(--fs-xs); font-weight: var(--fw-semibold);
}
.filters-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30;
  width: 280px; padding: 16px; display: flex; flex-direction: column; gap: 14px;
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.filters-panel[hidden] { display: none; }
.filters-item { display: flex; flex-direction: column; gap: 6px; }
.filters-label { color: var(--c-text-muted); font-size: var(--fs-xs); font-weight: var(--fw-semibold); }
@media (max-width: 600px) { .filter-topbar { flex-wrap: wrap; } }
.empty-state { padding: 40px 20px; text-align: center; color: var(--c-text-muted); }
.empty-state h2 { color: var(--c-text); margin-bottom: 6px; }

/* ─── Tables ─── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.table th { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .4px; color: var(--c-text-muted); font-weight: var(--fw-semibold); white-space: nowrap; }
.table tbody tr:hover { background: var(--c-row-hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.cell-muted { color: var(--c-text-muted); font-size: var(--fs-sm); }
.cell-primary { font-weight: var(--fw-semibold); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--c-primary);
  border-radius: var(--radius);
  background: var(--c-primary);
  color: var(--c-on-primary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1.2;
  cursor: pointer;
}
.btn:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); text-decoration: none; }
.btn--ghost { background: transparent; color: var(--c-text); border-color: var(--c-border); }
.btn--ghost:hover { background: var(--c-primary-soft); border-color: var(--c-primary-ring); }
.btn--danger { background: transparent; color: var(--c-danger); border-color: var(--c-danger); }
.btn--danger:hover { background: var(--c-danger-soft); border-color: var(--c-danger); }
.btn--sm { padding: 6px 11px; }
.btn--block { width: 100%; justify-content: center; }

/* ─── Badges + flash ─── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; }
.badge--success { background: var(--c-success-soft); color: var(--c-success); }
.badge--info { background: var(--c-info-soft); color: var(--c-info); }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); }
.badge--muted { background: var(--c-border); color: var(--c-text-muted); }

.toast-stack { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  border-left-width: 4px;
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  animation: toast-in .2s ease;
}
.toast--notice { border-left-color: var(--c-success); }
.toast--alert { border-left-color: var(--c-danger); }
.toast.is-leaving { opacity: 0; transform: translateX(16px); transition: opacity .2s ease, transform .2s ease; }
.toast-message { flex: 1; min-width: 0; }
.toast-close { border: 0; background: none; color: var(--c-text-muted); font-size: var(--fs-lg); line-height: 1; cursor: pointer; padding: 0; }
.toast-close:hover { color: var(--c-text); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } }

/* ─── Filters ─── */
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.filter-bar .filter-search { flex: 1 1 240px; width: auto; max-width: 360px; }
.filter-bar .filter-select { flex: 0 0 auto; width: auto; min-width: 150px; }
.empty-state { text-align: center; padding: 32px 16px; }

/* ─── Selects: compact custom arrow ─── */
select.input, select.filter-input, .table-pagination-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

/* ─── Pagination ─── */
.table-pagination {
  margin: 12px;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--c-border);
  border-radius: 12px;
  background: var(--c-bg);
}
.table-pagination-meta { margin: 0; color: var(--c-text-muted); font-size: var(--fs-sm); }
.table-pagination-meta strong { color: var(--c-text); font-weight: var(--fw-semibold); }
.table-pagination-right { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-left: auto; }
.table-pagination-controls, .table-pagination-nav, .pagination-pages { display: inline-flex; align-items: center; gap: 8px; }
.pagination-pages { gap: 4px; }
.table-pagination-label { color: var(--c-text-muted); font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; }
.table-pagination-select {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
}
.table-pagination-select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-ring); }
.pagination-ellipsis { color: var(--c-text-muted); font-size: var(--fs-sm); }
.pagination-page-btn, .pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-decoration: none;
}
.pagination-page-btn { min-width: 32px; height: 32px; padding: 0 6px; border-radius: 8px; }
.pagination-btn { min-width: 96px; height: 34px; padding: 0 12px; border-radius: 10px; }
.pagination-page-btn:hover, .pagination-btn:hover { border-color: var(--c-primary); color: var(--c-primary); text-decoration: none; }
.pagination-page-btn.is-active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.pagination-btn.is-disabled { pointer-events: none; opacity: .5; }

/* ─── Forms ─── */
.form { display: flex; flex-direction: column; gap: 16px; max-width: 520px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field-label { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.field-hint { color: var(--c-text-muted); font-size: var(--fs-sm); }
.input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
}
.input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-ring); }
.check { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); }
.check input { width: 16px; height: 16px; accent-color: var(--c-primary); }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.error-box { font-size: var(--fs-sm); padding: 12px 14px; border: 1px solid var(--c-danger); border-radius: var(--radius); background: var(--c-danger-soft); color: var(--c-danger); }
.error-box ul { margin: 6px 0 0; padding-left: 18px; }

/* ─── Permission matrix + history ─── */
.matrix-actions { display: flex; flex-wrap: wrap; gap: 18px; }
.change-list { margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); color: var(--c-text-muted); }

/* ─── Auth screens ─── */
.auth-body { min-height: 100vh; }
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 14px;
  background:
    radial-gradient(1000px 420px at 10% -10%, var(--c-primary-soft) 0%, transparent 70%),
    var(--c-bg);
}
.auth-card { width: min(440px, 100%); padding: 28px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 16px; box-shadow: var(--shadow-lg); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-brand-name { font-weight: var(--fw-semibold); font-size: var(--fs-lg); }
.auth-title { font-size: var(--fs-xl); }
.auth-subtitle { margin: 4px 0 16px; color: var(--c-text-muted); font-size: var(--fs-sm); }
.auth-links { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-sm); }

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; box-shadow: var(--shadow-lg); }
  html.sidebar-open .sidebar { transform: none; }
  .admin-main, html.sidebar-collapsed .admin-main { margin-left: 0; }
  html.sidebar-collapsed .sidebar-label, html.sidebar-collapsed .sidebar-brand-name { display: inline; }
  html.sidebar-collapsed .sidebar-logo { display: block; }
  html.sidebar-collapsed .sidebar-brand { justify-content: flex-start; padding-inline: 18px; }
  html.sidebar-collapsed .sidebar-toggle { margin-left: auto; }
  html.sidebar-collapsed .sidebar-link { justify-content: flex-start; padding-inline: 12px; }
  .icon-btn.topbar-menu { display: inline-grid; }
  html.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(10, 18, 32, .45); z-index: 45; }
  .admin-content { padding: 16px; }
  .topbar { padding: 0 12px; }
  .topbar-actions .btn span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .admin-main, .toast { transition: none; animation: none; }
}

/* ─── Offcanvas (flyout) panel for create / edit forms ─── */
turbo-frame#offcanvas:not(:empty) {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  background: rgba(30, 45, 61, .35);
}
.offcanvas-panel {
  width: min(480px, 100vw);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border-left: 1px solid var(--c-border);
  box-shadow: var(--shadow-lg);
  animation: offcanvas-in .2s ease;
}
.offcanvas-panel--wide { width: min(720px, 100vw); }
@keyframes offcanvas-in { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }
.offcanvas-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--c-border); flex-shrink: 0; }
.offcanvas-title { margin: 0; font-size: var(--fs-lg, 1.125rem); font-weight: var(--fw-semibold); color: var(--c-text); }
.offcanvas-close { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; color: var(--c-text-muted); font-size: 1.5rem; line-height: 1; text-decoration: none; }
.offcanvas-close:hover { background: var(--c-bg); color: var(--c-danger); }
.offcanvas-body { display: flex; flex: 1; flex-direction: column; min-height: 0; overflow-y: auto; padding: 20px; }
.offcanvas-lead { flex-shrink: 0; margin: 0 0 16px; font-size: var(--fs-sm); color: var(--c-text-muted); }
.offcanvas-form { flex: 1 0 auto; max-width: none; }
.offcanvas-form-actions { position: sticky; bottom: -20px; z-index: 1; flex-shrink: 0; margin: auto -20px -20px; padding: 16px 20px; border-top: 1px solid var(--c-border); background: var(--c-surface); }

/* Role permissions */
.role-form { max-width: none; gap: 24px; }
.role-name-field { gap: 8px; }
.role-permissions { display: grid; gap: 12px; }
.role-permissions-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.role-permissions-icon { display: grid; place-items: center; flex: 0 0 40px; height: 40px; border-radius: var(--radius); background: var(--c-primary-soft); color: var(--c-primary); }
.role-permissions-heading h2 { font-size: var(--fs-lg); }
.role-permissions-heading p { margin: 4px 0 0; color: var(--c-text-muted); font-size: var(--fs-sm); }
.role-permissions-empty { padding: 16px; border: 1px solid var(--c-border); border-radius: var(--radius); color: var(--c-text-muted); font-size: var(--fs-sm); }
.permission-group { min-width: 0; margin: 0; padding: 16px; border: 1px solid var(--c-border); border-radius: var(--radius-lg); }
.permission-group-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.permission-group-header h3 { font-size: var(--fs-base); }
.permission-group-count { display: block; margin-top: 2px; color: var(--c-text-muted); font-size: var(--fs-xs); }
.permission-group-count[hidden] { display: none; }
.permission-select-all { display: inline-flex; align-items: center; gap: 8px; color: var(--c-text-muted); font-size: var(--fs-sm); cursor: pointer; }
.permission-select-all[hidden] { display: none; }
.permission-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.permission-option { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-bg); font-size: var(--fs-sm); cursor: pointer; }
.permission-option:only-child { grid-column: 1 / -1; }
.permission-option:hover { border-color: var(--c-primary-ring); }
.permission-option:has(input:checked) { border-color: var(--c-primary-ring); background: var(--c-primary-soft); }
.permission-option input, .permission-select-all input { flex: 0 0 16px; width: 16px; height: 16px; margin: 0; accent-color: var(--c-primary); }

@media (max-width: 480px) {
  .permission-options { grid-template-columns: 1fr; }
}
