/* ===========================================================================
   MailFlow design system
   ---------------------------------------------------------------------------
   No build step, no framework. Everything is driven by the custom properties in
   :root / [data-theme="dark"], so retheming is a matter of changing tokens.

   Sections
     01  Tokens
     02  Reset & base
     03  Layout shell
     04  Sidebar
     05  Topbar
     06  Cards & surfaces
     07  Buttons
     08  Forms
     09  Tables
     10  Badges, chips, avatars, progress
     11  Dropdowns & popovers
     12  Modals & slide-overs
     13  Toasts
     14  Skeletons & empty states
     15  Charts
     16  Grid (Bootstrap-compatible)
     17  Utilities (Bootstrap-compatible)
     18  Motion, focus, accessibility
   ======================================================================== */

/* ---------------------------------------------------------------------------
   01  Tokens
   ------------------------------------------------------------------------ */
:root {
  color-scheme: light;

  /* Brand ---------------------------------------------------------------- */
  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-300: #a5b4fc;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-800: #3730a3;

  /* Neutrals ------------------------------------------------------------- */
  --gray-25:  #fcfcfd;
  --gray-50:  #f9fafb;
  --gray-100: #f2f4f7;
  --gray-200: #e4e7ec;
  --gray-300: #d0d5dd;
  --gray-400: #98a2b3;
  --gray-500: #667085;
  --gray-600: #475467;
  --gray-700: #344054;
  --gray-800: #1d2939;
  --gray-900: #101828;
  --gray-950: #0c111d;

  /* Semantic ------------------------------------------------------------- */
  --success-50:  #ecfdf3;  --success-500: #12b76a;  --success-600: #039855;  --success-700: #027a48;
  --warning-50:  #fffaeb;  --warning-500: #f79009;  --warning-600: #dc6803;  --warning-700: #b54708;
  --danger-50:   #fef3f2;  --danger-500:  #f04438;  --danger-600:  #d92d20;  --danger-700:  #b42318;
  --info-50:     #eff8ff;  --info-500:    #2e90fa;  --info-600:    #1570ef;  --info-700:    #175cd3;

  /* Surfaces ------------------------------------------------------------- */
  --bg:            var(--gray-50);
  --bg-subtle:     var(--gray-100);
  --surface:       #ffffff;
  --surface-2:     var(--gray-25);
  --surface-hover: var(--gray-50);
  --surface-glass: rgba(255, 255, 255, .72);
  --sidebar-bg:    #ffffff;
  --overlay:       rgba(16, 24, 40, .45);

  /* Text ----------------------------------------------------------------- */
  --text:        var(--gray-900);
  --text-muted:  var(--gray-500);
  --text-subtle: var(--gray-400);
  --text-invert: #ffffff;

  /* Lines ---------------------------------------------------------------- */
  --border:        var(--gray-200);
  --border-strong: var(--gray-300);

  /* Accent aliases ------------------------------------------------------- */
  --accent:       var(--brand-600);
  --accent-hover: var(--brand-700);
  --accent-soft:  var(--brand-50);
  --accent-text:  var(--brand-700);
  --ring:         rgba(99, 102, 241, .35);

  /* Radii ---------------------------------------------------------------- */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-full: 999px;

  /* Elevation ------------------------------------------------------------ */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, .08), 0 4px 6px -2px rgba(16, 24, 40, .03);
  --shadow-xl: 0 20px 24px -4px rgba(16, 24, 40, .10), 0 8px 8px -4px rgba(16, 24, 40, .04);
  --shadow-2xl: 0 24px 48px -12px rgba(16, 24, 40, .22);

  /* Type ----------------------------------------------------------------- */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono",
               Menlo, Consolas, monospace;

  --fs-xs:   .75rem;    /* 12 */
  --fs-sm:   .8125rem;  /* 13 */
  --fs-base: .875rem;   /* 14 — the app's default */
  --fs-md:   .9375rem;  /* 15 */
  --fs-lg:   1.0625rem; /* 17 */
  --fs-xl:   1.25rem;   /* 20 */
  --fs-2xl:  1.5rem;    /* 24 */
  --fs-3xl:  1.875rem;  /* 30 */

  /* Space ---------------------------------------------------------------- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;

  /* Motion --------------------------------------------------------------- */
  --ease:      cubic-bezier(.4, 0, .2, 1);
  --ease-out:  cubic-bezier(.16, 1, .3, 1);
  --ease-back: cubic-bezier(.34, 1.4, .64, 1);
  --t-fast: 150ms;
  --t-base: 200ms;
  --t-slow: 250ms;

  /* Chrome dimensions ---------------------------------------------------- */
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 68px;
  --topbar-h: 60px;
  --z-sidebar: 40;
  --z-topbar: 50;
  --z-dropdown: 60;
  --z-overlay: 70;
  --z-modal: 80;
  --z-toast: 90;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0b0e14;
  --bg-subtle:     #0f131b;
  --surface:       #12161f;
  --surface-2:     #161b26;
  --surface-hover: #1a2029;
  --surface-glass: rgba(18, 22, 31, .72);
  --sidebar-bg:    #0e121a;
  --overlay:       rgba(0, 0, 0, .62);

  --text:        #e6e8ee;
  --text-muted:  #98a2b3;
  --text-subtle: #667085;
  --text-invert: #0b0e14;

  --border:        #232936;
  --border-strong: #303846;

  --accent:       var(--brand-500);
  --accent-hover: var(--brand-400);
  --accent-soft:  rgba(99, 102, 241, .14);
  --accent-text:  var(--brand-300);
  --ring:         rgba(129, 140, 248, .40);

  --success-50: rgba(18, 183, 106, .14);
  --warning-50: rgba(247, 144, 9, .14);
  --danger-50:  rgba(240, 68, 56, .14);
  --info-50:    rgba(46, 144, 250, .14);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .40);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .30);
  --shadow-md: 0 4px 10px -2px rgba(0, 0, 0, .50);
  --shadow-lg: 0 12px 20px -6px rgba(0, 0, 0, .55);
  --shadow-xl: 0 20px 30px -8px rgba(0, 0, 0, .60);
  --shadow-2xl: 0 28px 56px -16px rgba(0, 0, 0, .72);
}

/* ---------------------------------------------------------------------------
   02  Reset & base
   ------------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--t-base) var(--ease),
              color var(--t-base) var(--ease);
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--sp-2);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -.015em;
  color: var(--text);
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
h5, h6 { font-size: var(--fs-md); }

p { margin: 0 0 var(--sp-3); }

a { color: var(--accent-text); text-decoration: none; transition: color var(--t-fast) var(--ease); }
a:hover { color: var(--accent-hover); text-decoration: none; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-5) 0; }

code, pre, .mono, .mf-num, .font-monospace {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.mf-num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
/* Numbers and timestamps should never wrap mid-value inside a cell. */
td .mf-num, th .mf-num { white-space: nowrap; }

::selection { background: var(--brand-200); color: var(--gray-900); }
[data-theme="dark"] ::selection { background: rgba(99, 102, 241, .40); color: #fff; }

/* Scrollbars ------------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: var(--r-full);
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--gray-400); background-clip: content-box; }

/* ---------------------------------------------------------------------------
   03  Layout shell
   ------------------------------------------------------------------------ */
.app {
  --shell-offset: var(--sidebar-w);
  min-height: 100vh;
}
.app[data-sidebar="collapsed"] { --shell-offset: var(--sidebar-w-collapsed); }

.app-main {
  margin-left: var(--shell-offset);
  padding: var(--sp-6) var(--sp-8) var(--sp-12);
  transition: margin-left var(--t-slow) var(--ease-out);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.page-title { font-size: var(--fs-2xl); margin: 0; }
.page-sub { color: var(--text-muted); font-size: var(--fs-base); margin: 2px 0 0; }
.page-actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------------------
   04  Sidebar
   ------------------------------------------------------------------------ */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--shell-offset, var(--sidebar-w));
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  transition: width var(--t-slow) var(--ease-out),
              transform var(--t-slow) var(--ease-out);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  overflow: hidden;
}
.brand-mark {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, .35);
}
.brand-mark svg { width: 17px; height: 17px; }
.brand-name {
  font-weight: 650;
  font-size: var(--fs-md);
  letter-spacing: -.02em;
  white-space: nowrap;
  color: var(--text);
}

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-3) var(--sp-3) var(--sp-4);
}
.nav-section {
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-subtle);
  white-space: nowrap;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: 2px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: var(--fs-base);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: calc(var(--sp-3) * -1 + 2px);
  top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: var(--r-full);
  background: var(--accent);
}
.nav-icon { flex: 0 0 auto; width: 18px; height: 18px; display: grid; place-items: center; }
.nav-icon svg { width: 18px; height: 18px; stroke-width: 1.75; }
.nav-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.nav-count {
  flex: 0 0 auto;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--r-full);
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.sidebar-foot {
  flex: 0 0 auto;
  padding: var(--sp-3);
  border-top: 1px solid var(--border);
}

/* Collapsed state --------------------------------------------------------- */
.app[data-sidebar="collapsed"] .brand-name,
.app[data-sidebar="collapsed"] .nav-label,
.app[data-sidebar="collapsed"] .nav-count,
.app[data-sidebar="collapsed"] .nav-section { display: none; }
.app[data-sidebar="collapsed"] .nav-item { justify-content: center; padding-inline: 0; }
.app[data-sidebar="collapsed"] .nav-item.active::before { display: none; }
.app[data-sidebar="collapsed"] .sidebar-brand { justify-content: center; padding-inline: 0; }

/* Tooltip for collapsed nav items ---------------------------------------- */
.app[data-sidebar="collapsed"] .nav-item::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) scale(.94);
  padding: 5px 9px;
  border-radius: var(--r-xs);
  background: var(--gray-900);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease-out);
  z-index: var(--z-dropdown);
}
[data-theme="dark"] .app[data-sidebar="collapsed"] .nav-item::after {
  background: var(--gray-200); color: var(--gray-900);
}
.app[data-sidebar="collapsed"] .nav-item:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }

/* ---------------------------------------------------------------------------
   05  Topbar
   ------------------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  margin: calc(var(--sp-6) * -1) calc(var(--sp-8) * -1) var(--sp-6);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-8);
  background: var(--surface-glass);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; stroke-width: 1.75; }
.icon-btn.has-dot { position: relative; }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px;
  min-width: 15px; height: 15px;
  padding: 0 4px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--danger-500);
  color: #fff;
  font-size: 9px; font-weight: 700; line-height: 1;
  border: 2px solid var(--surface);
  animation: pop var(--t-slow) var(--ease-back);
}

/* Search ------------------------------------------------------------------ */
.search {
  position: relative;
  flex: 1 1 420px;
  max-width: 480px;
}
.search svg.search-icon {
  position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-subtle);
  pointer-events: none;
}
/* The attribute selector keeps these ahead of the generic input rules in §08,
   which would otherwise reset the padding that makes room for the icon. */
.search input[type="search"],
.search input[type="text"] {
  width: 100%;
  height: 36px;
  min-height: 36px;
  padding: 0 68px 0 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  appearance: none;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search input::placeholder { color: var(--text-subtle); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }

/* Table toolbars reuse .search but have no ⌘K hint, so they need less room. */
.table-toolbar .search input[type="search"] {
  height: 32px;
  min-height: 32px;
  padding-right: 12px;
}
.search kbd {
  position: absolute; right: 8px; top: 50%;
  transform: translateY(-50%);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--bg-subtle);
  color: var(--text-subtle);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  pointer-events: none;
  transition: opacity var(--t-fast) var(--ease);
}
/* The hint has done its job once the field is in use — and it would otherwise
   sit under the browser's own clear button. */
.search input:focus ~ kbd,
.search input:not(:placeholder-shown) ~ kbd { opacity: 0; }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  max-height: 380px;
  overflow-y: auto;
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
}
.search-results .group-label {
  padding: var(--sp-2) var(--sp-2) var(--sp-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-subtle);
}
.search-hit {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text);
}
.search-hit:hover, .search-hit.is-active { background: var(--surface-hover); }
.search-hit .hit-meta { margin-left: auto; font-size: var(--fs-xs); color: var(--text-subtle); }

/* ---------------------------------------------------------------------------
   06  Cards & surfaces
   ------------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t-base) var(--ease),
              border-color var(--t-base) var(--ease),
              transform var(--t-base) var(--ease);
}
.card-hover:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-1px); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: var(--fs-md); font-weight: 600; margin: 0; }
.card-body { padding: var(--sp-5); }
.card-body.p-0 { padding: 0; }
.card-foot {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* Stat widget ------------------------------------------------------------- */
.stat {
  position: relative;
  display: flex; flex-direction: column; gap: var(--sp-1);
  padding: var(--sp-4) var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: box-shadow var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.stat-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.stat-icon {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.stat-icon svg { width: 15px; height: 15px; }
.stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-2xl);
  font-weight: 650;
  letter-spacing: -.03em;
  line-height: 1.15;
  color: var(--text);
}
.stat-foot {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-xs); color: var(--text-muted);
  min-width: 0;
}
/* Keep the text above the sparkline at every width. */
.stat-top, .stat-value, .stat-foot { position: relative; z-index: 1; }
.stat-delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.stat-delta.up { color: var(--success-600); }
.stat-delta.down { color: var(--danger-600); }
.stat-delta.flat { color: var(--text-subtle); }
.stat-delta svg { width: 12px; height: 12px; }
/* Decorative trend line: right-aligned and recessive, so it can never compete
   with the number or collide with the caption. */
.stat-spark {
  position: absolute;
  right: 0; bottom: 0;
  z-index: 0;
  width: 52%;
  max-width: 190px;
  height: 32px;
  opacity: .32;
  pointer-events: none;
}

.stat.tone-success .stat-icon { background: var(--success-50); color: var(--success-700); }
.stat.tone-warning .stat-icon { background: var(--warning-50); color: var(--warning-700); }
.stat.tone-danger  .stat-icon { background: var(--danger-50);  color: var(--danger-700); }
.stat.tone-info    .stat-icon { background: var(--info-50);    color: var(--info-700); }

/* ---------------------------------------------------------------------------
   07  Buttons
   ------------------------------------------------------------------------ */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border);
  --btn-bg-hover: var(--surface-hover);

  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: background-color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); }
.btn:active { transform: translateY(.5px); box-shadow: none; }
.btn svg { width: 16px; height: 16px; stroke-width: 1.85; flex: 0 0 auto; }

.btn:disabled, .btn.is-disabled, .btn[aria-disabled="true"] {
  opacity: .55; cursor: not-allowed; pointer-events: none; box-shadow: none;
}

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: #fff;
  --btn-bd: var(--accent);
  --btn-bg-hover: var(--accent-hover);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .08), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn-primary:hover { border-color: var(--accent-hover); }

.btn-danger {
  --btn-bg: var(--danger-600);
  --btn-fg: #fff;
  --btn-bd: var(--danger-600);
  --btn-bg-hover: var(--danger-700);
}
.btn-success {
  --btn-bg: var(--success-600);
  --btn-fg: #fff;
  --btn-bd: var(--success-600);
  --btn-bg-hover: var(--success-700);
}
.btn-ghost {
  --btn-bg: transparent;
  --btn-bd: transparent;
  --btn-fg: var(--text-muted);
  box-shadow: none;
}
.btn-ghost:hover { color: var(--text); }
.btn-soft {
  --btn-bg: var(--accent-soft);
  --btn-bd: transparent;
  --btn-fg: var(--accent-text);
  box-shadow: none;
}
.btn-danger-soft {
  --btn-bg: var(--danger-50);
  --btn-bd: transparent;
  --btn-fg: var(--danger-700);
  box-shadow: none;
}

.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: var(--fs-md); }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }

/* Loading state ----------------------------------------------------------- */
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--btn-fg);
  animation: spin .6s linear infinite;
}
.btn-primary.is-loading::after, .btn-danger.is-loading::after, .btn-success.is-loading::after { color: #fff; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; box-shadow: none; }
.btn-group .btn:first-child { border-radius: var(--r-md) 0 0 var(--r-md); margin-left: 0; }
.btn-group .btn:last-child  { border-radius: 0 var(--r-md) var(--r-md) 0; }
.btn-group .btn:hover { z-index: 1; }

/* ---------------------------------------------------------------------------
   08  Forms
   ------------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field-label, .form-label {
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text);
}
.field-label .req, .form-label .req { color: var(--danger-500); margin-left: 2px; }
.field-hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger-600); font-weight: 500; display: none; }
.field.has-error .field-error { display: block; animation: shake 300ms var(--ease); }

.input, .form-control, .form-select, textarea, select,
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], input[type="tel"], input[type="date"],
input[type="datetime-local"], input[type="time"] {
  width: 100%;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-base);
  line-height: 1.45;
  transition: border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              background-color var(--t-fast) var(--ease);
}
textarea { min-height: 90px; resize: vertical; }

.input::placeholder, .form-control::placeholder, textarea::placeholder { color: var(--text-subtle); }

.input:hover, .form-control:hover, .form-select:hover, textarea:hover, select:hover { border-color: var(--border-strong); }

.input:focus, .form-control:focus, .form-select:focus, textarea:focus, select:focus,
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.input:disabled, .form-control:disabled, textarea:disabled, select:disabled,
.input[readonly], .form-control[readonly] {
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: not-allowed;
}

.field.has-error .input, .field.has-error .form-control,
.field.has-error textarea, .field.has-error select,
.is-invalid {
  border-color: var(--danger-500);
}
.field.has-error .input:focus, .is-invalid:focus { box-shadow: 0 0 0 3px rgba(240, 68, 56, .28); }
.is-valid { border-color: var(--success-500); }

select, .form-select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select[multiple], .form-select[multiple] { background-image: none; padding-right: 11px; }

.input-sm, .form-control-sm, .form-select-sm { min-height: 30px; padding: 4px 9px; font-size: var(--fs-sm); }
.form-select-sm { padding-right: 28px; }

/* Checkbox / radio -------------------------------------------------------- */
input[type="checkbox"], input[type="radio"] {
  appearance: none;
  width: 16px; height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease);
}
input[type="checkbox"] { border-radius: 5px; }
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:hover, input[type="radio"]:hover { border-color: var(--accent); }
input[type="checkbox"]:checked, input[type="radio"]:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  background-size: 11px;
  background-position: center;
  background-repeat: no-repeat;
}
input[type="checkbox"]:indeterminate {
  background-color: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round'%3E%3Cline x1='5' y1='12' x2='19' y2='12'/%3E%3C/svg%3E");
  background-size: 11px; background-position: center; background-repeat: no-repeat;
}
input[type="radio"]:checked {
  background-image: radial-gradient(circle, #fff 0 3px, transparent 3.5px);
}
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--ring);
}

.check-row { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-base); cursor: pointer; }

/* Switch ------------------------------------------------------------------ */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 36px; height: 20px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  transition: background-color var(--t-base) var(--ease);
}
.switch .thumb {
  position: absolute; left: 2px; top: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-base) var(--ease-out);
}
.switch input:checked ~ .track { background: var(--accent); }
.switch input:checked ~ .thumb { transform: translateX(16px); }
.switch input:focus-visible ~ .track { box-shadow: 0 0 0 3px var(--ring); }

/* File drop --------------------------------------------------------------- */
.dropzone {
  display: grid; place-items: center; gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-5);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--t-base) var(--ease),
              background-color var(--t-base) var(--ease);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.dropzone svg { width: 26px; height: 26px; }

/* ---------------------------------------------------------------------------
   09  Tables
   ------------------------------------------------------------------------ */
.table-wrap {
  position: relative;
  overflow: auto;
  border-radius: var(--r-lg);
  max-height: var(--table-max-h, none);
}

table, .table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-base);
}

thead th, .table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px var(--sp-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
  user-select: none;
}
thead th.sortable, .table thead th.sortable { cursor: pointer; transition: color var(--t-fast) var(--ease); }
thead th.sortable:hover { color: var(--text); }
th .sort-ind {
  display: inline-flex;
  margin-left: 5px;
  vertical-align: -2px;
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
th .sort-ind svg { width: 12px; height: 12px; }
th.sortable:hover .sort-ind { opacity: .45; }
th[aria-sort="ascending"] .sort-ind  { opacity: 1; color: var(--accent-text); }
th[aria-sort="descending"] .sort-ind { opacity: 1; color: var(--accent-text); transform: rotate(180deg); }
th .sort-rank {
  margin-left: 3px;
  font-size: 9px;
  font-weight: 700;
  color: var(--accent-text);
  vertical-align: super;
}

tbody td, .table tbody td {
  padding: 11px var(--sp-4);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tbody tr, .table tbody tr { transition: background-color var(--t-fast) var(--ease); }
tbody tr:hover, .table tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.is-selected { background: var(--accent-soft); }

tr.row-leaving {
  animation: rowOut var(--t-slow) var(--ease) forwards;
}
tr.row-entering {
  animation: rowIn var(--t-slow) var(--ease-out);
}

.td-num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.td-actions { text-align: right; white-space: nowrap; }
.td-actions .btn + .btn { margin-left: var(--sp-1); }

/* Table chrome ------------------------------------------------------------ */
.table-toolbar {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.table-toolbar .grow { flex: 1 1 200px; }
.table-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.pagination { display: inline-flex; align-items: center; gap: 2px; }
.pagination .page {
  min-width: 30px; height: 30px;
  display: inline-grid; place-items: center;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 550;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.pagination .page:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.pagination .page[aria-current="page"] { background: var(--accent); color: #fff; }
.pagination .page:disabled { opacity: .4; cursor: not-allowed; }
.pagination .ellipsis { padding: 0 4px; color: var(--text-subtle); }

/* Bulk action bar --------------------------------------------------------- */
.bulk-bar {
  position: sticky;
  bottom: var(--sp-5);
  z-index: 5;
  display: flex; align-items: center; gap: var(--sp-3);
  width: max-content;
  max-width: 100%;
  margin: var(--sp-4) auto 0;
  padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-glass);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  box-shadow: var(--shadow-xl);
  animation: slideUp var(--t-slow) var(--ease-out);
}
.bulk-bar .count { font-weight: 600; white-space: nowrap; }

/* Inline editable cell ---------------------------------------------------- */
td.editable { cursor: text; position: relative; }
td.editable:hover::after {
  content: "";
  position: absolute; inset: 4px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-xs);
  pointer-events: none;
}
td.editing { padding: 4px var(--sp-2); }
td.editing input { min-height: 30px; }

/* Virtualized body -------------------------------------------------------- */
.vscroll { position: relative; }
.vscroll .vpad { display: block; }

/* Dense tables embedded in a dashboard card ------------------------------- */
#smtp-table table { font-size: var(--fs-sm); }
#smtp-table thead th { padding: 9px var(--sp-3); }
#smtp-table tbody td { padding: 10px var(--sp-3); white-space: nowrap; }
#smtp-table tbody td:first-child {
  white-space: normal;
  min-width: 150px;
  max-width: 230px;
}
#smtp-table tbody td:first-child > .d-flex { flex-wrap: wrap; row-gap: 4px; }

/* ---------------------------------------------------------------------------
   10  Badges, chips, avatars, progress
   ------------------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: var(--r-full);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.badge.no-dot::before { display: none; }

.badge-success, .badge.bg-success { background: var(--success-50); color: var(--success-700); }
.badge-warning, .badge.bg-warning, .badge.bg-sending { background: var(--warning-50); color: var(--warning-700); }
.badge-danger,  .badge.bg-danger  { background: var(--danger-50);  color: var(--danger-700); }
.badge-info,    .badge.bg-info    { background: var(--info-50);    color: var(--info-700); }
.badge-neutral, .badge.bg-secondary, .badge.bg-dark { background: var(--bg-subtle); color: var(--text-muted); }
.badge-accent, .badge.bg-primary { background: var(--accent-soft); color: var(--accent-text); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 500;
}
.chip .x { cursor: pointer; opacity: .6; transition: opacity var(--t-fast) var(--ease); }
.chip .x:hover { opacity: 1; }

.avatar {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: .02em;
  text-transform: uppercase;
  user-select: none;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 38px; height: 38px; font-size: var(--fs-base); }

.progress {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--bg-subtle);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--accent);
  transition: width var(--t-slow) var(--ease-out);
}
.progress-bar.success { background: var(--success-500); }
.progress-bar.warning { background: var(--warning-500); }
.progress-bar.danger  { background: var(--danger-500); }
.progress-bar.striped {
  background-image: linear-gradient(45deg, rgba(255,255,255,.22) 25%, transparent 25%,
    transparent 50%, rgba(255,255,255,.22) 50%, rgba(255,255,255,.22) 75%, transparent 75%);
  background-size: 12px 12px;
  animation: stripes 800ms linear infinite;
}

.health-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gray-300);
  flex: 0 0 auto;
}
.health-dot.ok   { background: var(--success-500); box-shadow: 0 0 0 3px var(--success-50); }
.health-dot.warn { background: var(--warning-500); box-shadow: 0 0 0 3px var(--warning-50); }
.health-dot.bad  { background: var(--danger-500);  box-shadow: 0 0 0 3px var(--danger-50); }
.health-dot.live { animation: pulse 2s var(--ease) infinite; }

/* ---------------------------------------------------------------------------
   11  Dropdowns & popovers
   ------------------------------------------------------------------------ */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  max-height: min(60vh, 460px);
  overflow-y: auto;
  padding: var(--sp-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
  transform-origin: top right;
  animation: menuIn var(--t-fast) var(--ease-out);
}
.dropdown-menu.left { right: auto; left: 0; transform-origin: top left; }
.dropdown-menu.wide { min-width: 340px; }

.dropdown-item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%;
  padding: 7px var(--sp-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-base);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.dropdown-item:hover, .dropdown-item.is-active { background: var(--surface-hover); }
.dropdown-item svg { width: 16px; height: 16px; color: var(--text-muted); flex: 0 0 auto; }
.dropdown-item.danger { color: var(--danger-600); }
.dropdown-item.danger svg { color: var(--danger-500); }
.dropdown-item.danger:hover { background: var(--danger-50); }
.dropdown-item .shortcut { margin-left: auto; font-size: var(--fs-xs); color: var(--text-subtle); }
.dropdown-sep { height: 1px; margin: var(--sp-1) 0; background: var(--border); }
.dropdown-head {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-subtle);
}

/* Notification centre ----------------------------------------------------- */
.notif {
  display: flex; gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease);
}
.notif:hover { background: var(--surface-hover); }
.notif.unread { background: var(--accent-soft); }
.notif-icon {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--bg-subtle);
  color: var(--text-muted);
}
.notif-icon svg { width: 15px; height: 15px; }
.notif.level-success .notif-icon { background: var(--success-50); color: var(--success-700); }
.notif.level-warning .notif-icon { background: var(--warning-50); color: var(--warning-700); }
.notif.level-error   .notif-icon { background: var(--danger-50);  color: var(--danger-700); }
.notif.level-info    .notif-icon { background: var(--info-50);    color: var(--info-700); }
.notif-body { min-width: 0; }
.notif-title { font-weight: 550; font-size: var(--fs-sm); }
.notif-text { font-size: var(--fs-xs); color: var(--text-muted); overflow-wrap: anywhere; }
.notif-time { font-size: var(--fs-xs); color: var(--text-subtle); margin-top: 2px; }

/* ---------------------------------------------------------------------------
   12  Modals & slide-overs
   ------------------------------------------------------------------------ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fadeIn var(--t-base) var(--ease);
}
.overlay.is-closing { animation: fadeOut var(--t-fast) var(--ease) forwards; }

.modal {
  position: relative;
  z-index: var(--z-modal);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - var(--sp-10));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-2xl);
  animation: modalIn var(--t-slow) var(--ease-out);
}
.overlay.is-closing .modal { animation: modalOut var(--t-fast) var(--ease) forwards; }

.modal.size-sm { max-width: 420px; }
.modal.size-md { max-width: 620px; }
.modal.size-lg { max-width: 860px; }
.modal.size-xl { max-width: 1120px; }

.modal-head {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: var(--fs-lg); font-weight: 600; margin: 0; }
.modal-sub { font-size: var(--fs-sm); color: var(--text-muted); margin: 3px 0 0; }
.modal-close { margin-left: auto; margin-top: -4px; margin-right: -4px; }

.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}
.modal-foot .spread { margin-right: auto; }

.modal-icon {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.modal-icon svg { width: 20px; height: 20px; }
.modal-icon.danger  { background: var(--danger-50);  color: var(--danger-600); }
.modal-icon.warning { background: var(--warning-50); color: var(--warning-700); }
.modal-icon.success { background: var(--success-50); color: var(--success-700); }

/* Slide-over -------------------------------------------------------------- */
.overlay.slideover { place-items: stretch; justify-content: flex-end; padding: 0; }
.overlay.slideover .modal {
  max-width: 560px;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  border-right: 0; border-top: 0; border-bottom: 0;
  animation: slideInRight var(--t-slow) var(--ease-out);
}
.overlay.slideover .modal-foot { border-radius: 0; }
.overlay.slideover.is-closing .modal { animation: slideOutRight var(--t-base) var(--ease) forwards; }
.overlay.slideover .modal.size-lg { max-width: 780px; }

/* Success / error flourish ------------------------------------------------ */
.result-anim { display: grid; place-items: center; padding: var(--sp-8) 0 var(--sp-4); }
.result-anim .ring {
  width: 60px; height: 60px;
  border-radius: 50%;
  display: grid; place-items: center;
  animation: pop var(--t-slow) var(--ease-back);
}
.result-anim.ok .ring    { background: var(--success-50); color: var(--success-600); }
.result-anim.err .ring   { background: var(--danger-50);  color: var(--danger-600); animation: shake 400ms var(--ease); }
.result-anim svg { width: 30px; height: 30px; stroke-width: 2.5; }
.result-anim.ok svg path, .result-anim.ok svg polyline {
  stroke-dasharray: 40; stroke-dashoffset: 40;
  animation: draw 400ms var(--ease-out) 120ms forwards;
}
.result-anim .msg { margin-top: var(--sp-3); font-weight: 550; }

/* ---------------------------------------------------------------------------
   13  Toasts
   ------------------------------------------------------------------------ */
.toast-host {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(380px, calc(100vw - var(--sp-8)));
  pointer-events: none;
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4) var(--sp-3) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  cursor: pointer;
  pointer-events: auto;
  animation: toastIn var(--t-slow) var(--ease-out);
}
.toast.is-closing { animation: toastOut var(--t-base) var(--ease) forwards; }

.toast-icon {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--bg-subtle);
  color: var(--text-muted);
}
.toast-icon svg { width: 15px; height: 15px; stroke-width: 2.2; }
.toast-body { flex: 1 1 auto; min-width: 0; }
.toast-title { font-size: var(--fs-base); font-weight: 550; line-height: 1.4; }
.toast-text { font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.toast-action {
  margin-top: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent-text);
  background: none; border: 0; padding: 0; cursor: pointer;
}
.toast-x { flex: 0 0 auto; margin: -2px -6px 0 0; }

.toast-progress {
  position: absolute;
  left: 0; bottom: 0;
  height: 2px;
  width: 100%;
  transform-origin: left;
  background: var(--accent);
  animation: drain linear forwards;
}
.toast:hover .toast-progress { animation-play-state: paused; }

.toast.success .toast-icon { background: var(--success-50); color: var(--success-600); }
.toast.success .toast-progress { background: var(--success-500); }
.toast.error   .toast-icon { background: var(--danger-50);  color: var(--danger-600); }
.toast.error   .toast-progress { background: var(--danger-500); }
.toast.warning .toast-icon { background: var(--warning-50); color: var(--warning-700); }
.toast.warning .toast-progress { background: var(--warning-500); }
.toast.info    .toast-icon { background: var(--info-50);    color: var(--info-700); }
.toast.info    .toast-progress { background: var(--info-500); }

/* ---------------------------------------------------------------------------
   14  Skeletons & empty states
   ------------------------------------------------------------------------ */
.sk {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-xs);
  background: var(--bg-subtle);
}
.sk::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .55), transparent);
  animation: shimmer 1.4s var(--ease) infinite;
}
[data-theme="dark"] .sk::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .06), transparent);
}
.sk-line { height: 10px; margin-bottom: 8px; }
.sk-line:last-child { margin-bottom: 0; }
.sk-title { height: 15px; width: 42%; margin-bottom: 12px; }
.sk-value { height: 26px; width: 58%; border-radius: var(--r-sm); }
.sk-chart { height: 240px; border-radius: var(--r-md); }
.sk-avatar { width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto; }
.sk-btn { height: 30px; width: 84px; border-radius: var(--r-sm); }
.sk-w-25 { width: 25%; } .sk-w-40 { width: 40%; } .sk-w-60 { width: 60%; }
.sk-w-75 { width: 75%; } .sk-w-90 { width: 90%; } .sk-w-100 { width: 100%; }

.empty {
  display: grid;
  place-items: center;
  gap: var(--sp-2);
  padding: var(--sp-12) var(--sp-5);
  text-align: center;
  color: var(--text-muted);
}
.empty-icon {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--bg-subtle);
  color: var(--text-subtle);
  margin-bottom: var(--sp-1);
}
.empty-icon svg { width: 22px; height: 22px; }
.empty-title { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.empty-text { font-size: var(--fs-base); max-width: 380px; }

/* Section-scoped spinner -------------------------------------------------- */
.is-busy { position: relative; }
.is-busy > .busy-veil {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--surface) 62%, transparent);
  backdrop-filter: blur(1px);
  border-radius: inherit;
  z-index: 4;
  animation: fadeIn var(--t-fast) var(--ease);
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }

/* Global top progress bar ------------------------------------------------- */
#nprogress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0;
  z-index: 100;
  background: linear-gradient(90deg, var(--brand-400), var(--brand-600));
  box-shadow: 0 0 8px var(--brand-500);
  transition: width 200ms var(--ease), opacity 300ms var(--ease) 150ms;
  opacity: 0;
}
#nprogress.on { opacity: 1; }

/* ---------------------------------------------------------------------------
   15  Charts
   ------------------------------------------------------------------------ */
.chart { width: 100%; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: var(--sp-3);
  margin-top: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }

.apexcharts-tooltip {
  border: 1px solid var(--border) !important;
  background: var(--surface) !important;
  box-shadow: var(--shadow-lg) !important;
  border-radius: var(--r-md) !important;
  color: var(--text) !important;
}
.apexcharts-tooltip-title {
  background: var(--surface-2) !important;
  border-bottom: 1px solid var(--border) !important;
  font-weight: 600 !important;
}
.apexcharts-menu {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--r-md) !important;
}
.apexcharts-menu-item:hover { background: var(--surface-hover) !important; }
.apexcharts-xaxistooltip, .apexcharts-yaxistooltip {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}

/* ---------------------------------------------------------------------------
   16  Grid — Bootstrap-compatible class names, new visual language
   ------------------------------------------------------------------------ */
.container, .container-fluid { width: 100%; margin: 0 auto; padding: 0 var(--sp-4); }
.container { max-width: 1280px; }

.row {
  display: flex;
  flex-wrap: wrap;
  margin: calc(var(--gx, 24px) / -2);
}
.row > * { padding: calc(var(--gx, 24px) / 2); width: 100%; max-width: 100%; }

.g-0 { --gx: 0px; }   .g-1 { --gx: 4px; }   .g-2 { --gx: 8px; }
.g-3 { --gx: 16px; }  .g-4 { --gx: 24px; }  .g-5 { --gx: 32px; }

.col      { flex: 1 0 0%; }
.col-auto { flex: 0 0 auto; width: auto; }
.col-1  { flex: 0 0 auto; width: 8.3333%; }
.col-2  { flex: 0 0 auto; width: 16.6667%; }
.col-3  { flex: 0 0 auto; width: 25%; }
.col-4  { flex: 0 0 auto; width: 33.3333%; }
.col-5  { flex: 0 0 auto; width: 41.6667%; }
.col-6  { flex: 0 0 auto; width: 50%; }
.col-7  { flex: 0 0 auto; width: 58.3333%; }
.col-8  { flex: 0 0 auto; width: 66.6667%; }
.col-9  { flex: 0 0 auto; width: 75%; }
.col-10 { flex: 0 0 auto; width: 83.3333%; }
.col-11 { flex: 0 0 auto; width: 91.6667%; }
.col-12 { flex: 0 0 auto; width: 100%; }

@media (min-width: 576px) {
  .col-sm-auto { flex: 0 0 auto; width: auto; }
  .col-sm-1{width:8.3333%}.col-sm-2{width:16.6667%}.col-sm-3{width:25%}.col-sm-4{width:33.3333%}
  .col-sm-5{width:41.6667%}.col-sm-6{width:50%}.col-sm-7{width:58.3333%}.col-sm-8{width:66.6667%}
  .col-sm-9{width:75%}.col-sm-10{width:83.3333%}.col-sm-11{width:91.6667%}.col-sm-12{width:100%}
  [class*="col-sm-"] { flex: 0 0 auto; }
}
@media (min-width: 768px) {
  .col-md-auto { flex: 0 0 auto; width: auto; }
  .col-md-1{width:8.3333%}.col-md-2{width:16.6667%}.col-md-3{width:25%}.col-md-4{width:33.3333%}
  .col-md-5{width:41.6667%}.col-md-6{width:50%}.col-md-7{width:58.3333%}.col-md-8{width:66.6667%}
  .col-md-9{width:75%}.col-md-10{width:83.3333%}.col-md-11{width:91.6667%}.col-md-12{width:100%}
  [class*="col-md-"] { flex: 0 0 auto; }
}
@media (min-width: 992px) {
  .col-lg-auto { flex: 0 0 auto; width: auto; }
  .col-lg-1{width:8.3333%}.col-lg-2{width:16.6667%}.col-lg-3{width:25%}.col-lg-4{width:33.3333%}
  .col-lg-5{width:41.6667%}.col-lg-6{width:50%}.col-lg-7{width:58.3333%}.col-lg-8{width:66.6667%}
  .col-lg-9{width:75%}.col-lg-10{width:83.3333%}.col-lg-11{width:91.6667%}.col-lg-12{width:100%}
  [class*="col-lg-"] { flex: 0 0 auto; }
}
@media (min-width: 1200px) {
  .col-xl-auto { flex: 0 0 auto; width: auto; }
  .col-xl-1{width:8.3333%}.col-xl-2{width:16.6667%}.col-xl-3{width:25%}.col-xl-4{width:33.3333%}
  .col-xl-5{width:41.6667%}.col-xl-6{width:50%}.col-xl-7{width:58.3333%}.col-xl-8{width:66.6667%}
  .col-xl-9{width:75%}.col-xl-10{width:83.3333%}.col-xl-11{width:91.6667%}.col-xl-12{width:100%}
  [class*="col-xl-"] { flex: 0 0 auto; }
}

/* Auto-fit widget grid (used by the dashboard) ---------------------------- */
.grid-auto {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fill, minmax(var(--min, 210px), 1fr));
}

/* ---------------------------------------------------------------------------
   17  Utilities — Bootstrap-compatible subset
   ------------------------------------------------------------------------ */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.d-flex { display: flex !important; }
.d-inline-flex { display: inline-flex !important; }
.d-grid { display: grid !important; }

.flex-wrap { flex-wrap: wrap !important; }
.flex-column { flex-direction: column !important; }
.flex-grow-1 { flex-grow: 1 !important; }
.align-items-start { align-items: flex-start !important; }
.align-items-center { align-items: center !important; }
.align-items-end { align-items: flex-end !important; }
.align-middle { vertical-align: middle !important; }
.justify-content-start { justify-content: flex-start !important; }
.justify-content-center { justify-content: center !important; }
.justify-content-end { justify-content: flex-end !important; }
.justify-content-between { justify-content: space-between !important; }
.gap-1 { gap: var(--sp-1) !important; }
.gap-2 { gap: var(--sp-2) !important; }
.gap-3 { gap: var(--sp-3) !important; }
.gap-4 { gap: var(--sp-4) !important; }

.text-start { text-align: left !important; }
.text-center { text-align: center !important; }
.text-end { text-align: right !important; }
.text-muted { color: var(--text-muted) !important; }
.text-subtle { color: var(--text-subtle) !important; }
.text-danger { color: var(--danger-600) !important; }
.text-success { color: var(--success-600) !important; }
.text-warning { color: var(--warning-700) !important; }
.text-accent { color: var(--accent-text) !important; }
.text-nowrap { white-space: nowrap !important; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-uppercase { text-transform: uppercase !important; }

.small { font-size: var(--fs-sm) !important; }
.fs-6 { font-size: var(--fs-base) !important; }
.fs-5 { font-size: var(--fs-md) !important; }
.fs-4 { font-size: var(--fs-xl) !important; }
.fs-3 { font-size: var(--fs-2xl) !important; }
.fw-500 { font-weight: 500 !important; }
.fw-600, .fw-bold { font-weight: 600 !important; }

.w-100 { width: 100% !important; }
.h-100 { height: 100% !important; }
.mw-100 { max-width: 100% !important; }

.m-0 { margin: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--sp-1) !important; }
.mb-2 { margin-bottom: var(--sp-2) !important; }
.mb-3 { margin-bottom: var(--sp-4) !important; }
.mb-4 { margin-bottom: var(--sp-6) !important; }
.mb-5 { margin-bottom: var(--sp-8) !important; }
.mt-1 { margin-top: var(--sp-1) !important; }
.mt-2 { margin-top: var(--sp-2) !important; }
.mt-3 { margin-top: var(--sp-4) !important; }
.mt-4 { margin-top: var(--sp-6) !important; }
.ms-auto { margin-left: auto !important; }
.me-auto { margin-right: auto !important; }
.mx-auto { margin-left: auto !important; margin-right: auto !important; }

.p-0 { padding: 0 !important; }
.p-2 { padding: var(--sp-2) !important; }
.p-3 { padding: var(--sp-4) !important; }
.p-4 { padding: var(--sp-6) !important; }
.py-2 { padding-top: var(--sp-2) !important; padding-bottom: var(--sp-2) !important; }
.py-3 { padding-top: var(--sp-4) !important; padding-bottom: var(--sp-4) !important; }
.py-4 { padding-top: var(--sp-6) !important; padding-bottom: var(--sp-6) !important; }
.py-5 { padding-top: var(--sp-10) !important; padding-bottom: var(--sp-10) !important; }

.rounded { border-radius: var(--r-md) !important; }
.rounded-lg { border-radius: var(--r-lg) !important; }
.border { border: 1px solid var(--border) !important; }
.border-0 { border: 0 !important; }
.border-top { border-top: 1px solid var(--border) !important; }
.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.bg-surface { background: var(--surface) !important; }
.bg-subtle { background: var(--bg-subtle) !important; }

.vr { width: 1px; align-self: stretch; min-height: 20px; background: var(--border); flex: 0 0 auto; }

.visually-hidden, .sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Legacy Bootstrap leftovers ---------------------------------------------- */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-4);
  font-size: var(--fs-base);
}
.alert-success { background: var(--success-50); border-color: transparent; color: var(--success-700); }
.alert-danger  { background: var(--danger-50);  border-color: transparent; color: var(--danger-700); }
.alert-warning { background: var(--warning-50); border-color: transparent; color: var(--warning-700); }
.alert-info    { background: var(--info-50);    border-color: transparent; color: var(--info-700); }

.btn-outline-secondary { }
.btn-outline-primary { --btn-fg: var(--accent-text); --btn-bd: var(--border); --btn-bg-hover: var(--accent-soft); }
.btn-outline-danger  { --btn-fg: var(--danger-600);  --btn-bd: var(--border); --btn-bg-hover: var(--danger-50); }
.btn-outline-success { --btn-fg: var(--success-600); --btn-bd: var(--border); --btn-bg-hover: var(--success-50); }
.btn-outline-warning { --btn-fg: var(--warning-700); --btn-bd: var(--border); --btn-bg-hover: var(--warning-50); }
.btn-link { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--accent-text); box-shadow: none; }
.btn-secondary { --btn-bg: var(--bg-subtle); --btn-bd: var(--border); }

.table-sm tbody td, .table-sm thead th { padding: 7px var(--sp-3); }
.table-hover tbody tr:hover { background: var(--surface-hover); }
.collapse:not(.show) { display: none; }

/* ---------------------------------------------------------------------------
   18  Motion, focus, accessibility
   ------------------------------------------------------------------------ */
@keyframes spin      { to { transform: rotate(360deg); } }
@keyframes fadeIn    { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut   { from { opacity: 1; } to { opacity: 0; } }
@keyframes pop       { 0% { transform: scale(.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes shimmer   { 100% { transform: translateX(100%); } }
@keyframes stripes   { to { background-position: 12px 0; } }
@keyframes drain     { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes draw      { to { stroke-dashoffset: 0; } }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  50%      { box-shadow: 0 0 0 4px transparent; opacity: .75; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-5px); }
  40%      { transform: translateX(5px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(3px); }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.975); }
  to   { opacity: 1; transform: none; }
}
@keyframes modalOut {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(6px) scale(.985); }
}
@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
  from { opacity: 1; transform: none; max-height: 200px; }
  to   { opacity: 0; transform: translateX(24px); max-height: 0; margin-bottom: -8px; }
}
@keyframes slideInRight  { from { transform: translateX(100%); } to { transform: none; } }
@keyframes slideOutRight { from { transform: none; } to { transform: translateX(100%); } }
@keyframes slideUp       { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes rowIn         { from { opacity: 0; background: var(--accent-soft); } to { opacity: 1; } }
@keyframes rowOut {
  to { opacity: 0; transform: translateX(-16px); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.animate-in { animation: fadeUp var(--t-slow) var(--ease-out) both; }

/* Focus ------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
.btn:focus-visible, .icon-btn:focus-visible, .nav-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

.skip-link {
  position: absolute;
  left: var(--sp-3);
  top: -60px;
  z-index: 200;
  padding: 10px 16px;
  border-radius: var(--r-md);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: top var(--t-base) var(--ease-out);
}
.skip-link:focus { top: var(--sp-3); color: #fff; }

/* Keyboard-shortcut help -------------------------------------------------- */
.kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

/* Reduced motion ---------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* High contrast ----------------------------------------------------------- */
@media (prefers-contrast: more) {
  :root {
    --border: var(--gray-400);
    --border-strong: var(--gray-600);
    --text-muted: var(--gray-700);
  }
  [data-theme="dark"] {
    --border: #4a5464;
    --border-strong: #6b7688;
    --text-muted: #c3c9d4;
  }
  .btn, .card, .input, .form-control { border-width: 1.5px; }
}
@media (forced-colors: active) {
  .btn, .card, .modal, .toast, .dropdown-menu { border: 1px solid CanvasText; }
  .sk::after { display: none; }
}

/* ---------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------ */
@media (max-width: 1200px) {
  .app-main { padding: var(--sp-5) var(--sp-5) var(--sp-10); }
  .topbar { margin: calc(var(--sp-5) * -1) calc(var(--sp-5) * -1) var(--sp-5); padding: 0 var(--sp-5); }
}

@media (max-width: 992px) {
  .app { --shell-offset: 0px; }
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w);
    box-shadow: var(--shadow-2xl);
  }
  .app[data-sidebar="open"] .sidebar { transform: none; }
  .app[data-sidebar="open"] .sidebar-scrim {
    position: fixed; inset: 0;
    z-index: calc(var(--z-sidebar) - 1);
    background: var(--overlay);
    animation: fadeIn var(--t-base) var(--ease);
  }
  /* Never collapse to icons on small screens — it becomes a drawer instead. */
  .app[data-sidebar="collapsed"] .brand-name,
  .app[data-sidebar="collapsed"] .nav-label,
  .app[data-sidebar="collapsed"] .nav-section { display: revert; }
  .app[data-sidebar="collapsed"] .nav-item { justify-content: flex-start; padding-inline: var(--sp-3); }
  .app[data-sidebar="collapsed"] .sidebar-brand { justify-content: flex-start; padding-inline: var(--sp-4); }
  .app[data-sidebar="collapsed"] .nav-item::after { display: none; }
}

@media (max-width: 768px) {
  .app-main { padding: var(--sp-4) var(--sp-4) var(--sp-10); }
  .topbar { margin: calc(var(--sp-4) * -1) calc(var(--sp-4) * -1) var(--sp-4); padding: 0 var(--sp-4); gap: var(--sp-2); }
  .search { flex: 1 1 auto; max-width: none; }
  .search kbd { display: none; }
  .grid-auto { --min: 150px; gap: var(--sp-3); }
  .stat { padding: var(--sp-3) var(--sp-4); }
  .stat-value { font-size: var(--fs-xl); }
  .modal { max-width: none; }
  .overlay { padding: 0; place-items: end stretch; }
  .overlay .modal {
    max-height: 92vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation: slideUpSheet var(--t-slow) var(--ease-out);
  }
  .overlay.slideover .modal { border-radius: 0; max-width: none; }
  .modal-foot { border-radius: 0; }
  .modal-foot .btn { flex: 1 1 auto; }
  .toast-host { top: auto; bottom: var(--sp-3); left: var(--sp-3); right: var(--sp-3); width: auto; }
  .table-foot { justify-content: center; }
  .page-head { gap: var(--sp-3); }
}

@keyframes slideUpSheet {
  from { transform: translateY(100%); }
  to   { transform: none; }
}

@media (max-width: 560px) {
  .grid-auto { --min: 100%; }
  .hide-xs { display: none !important; }
  .btn { height: 38px; }
  .btn-sm { height: 32px; }
}

@media print {
  .sidebar, .topbar, .toast-host, .bulk-bar, .page-actions, #nprogress { display: none !important; }
  .app-main { margin: 0; padding: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}

/* =============================================================================
   Contacts — guided import modal
   ========================================================================== */
.mf-imp-drop {
  position: relative;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  padding: 28px 20px;
  text-align: center;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.mf-imp-drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.mf-imp-drop.has-file { border-style: solid; border-color: var(--accent); }
.mf-imp-file {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.mf-imp-drop-icon {
  width: 44px; height: 44px; margin: 0 auto 10px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--accent);
}
.mf-imp-drop-text { font-size: var(--fs-md); color: var(--text); }
.mf-imp-drop-text strong { color: var(--accent-text); }
.mf-imp-drop-hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 4px; }
.mf-imp-file-name {
  margin-top: 10px; font-size: var(--fs-sm); font-weight: 600; color: var(--text);
  font-family: var(--font-mono);
}
.mf-imp-row { margin-top: 18px; }
.mf-imp-row .form-label { display: block; margin-bottom: 6px; }

/* --- mapping step --- */
.mf-imp-map-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 12px; flex-wrap: wrap;
}
.mf-imp-check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text); cursor: pointer; }
.mf-imp-count {
  font-size: var(--fs-xs); font-weight: 600;
  color: var(--accent-text); background: var(--accent-soft);
  padding: 3px 10px; border-radius: var(--r-full);
}
.mf-imp-grid {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(150px, 1.5fr) minmax(160px, 1.1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.mf-imp-gh {
  background: var(--surface-2);
  font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; color: var(--text-muted);
  padding: 8px 12px;
}
.mf-imp-src, .mf-imp-samp, .mf-imp-pick {
  background: var(--surface);
  padding: 10px 12px;
  display: flex; align-items: center;
  min-width: 0;
}
.mf-imp-src-name {
  font-size: var(--fs-sm); font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mf-imp-samp { flex-direction: column; align-items: flex-start; gap: 2px; }
.mf-imp-samp span {
  font-size: var(--fs-xs); color: var(--text-muted);
  font-family: var(--font-mono);
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mf-imp-samp .mf-imp-empty { font-style: italic; opacity: .7; font-family: var(--font); }
.mf-imp-pick { padding: 8px 10px; }
.mf-imp-sel { width: 100%; }
.mf-imp-note {
  margin-top: 14px; font-size: var(--fs-xs); color: var(--text-muted);
  line-height: 1.6;
}

/* --- result step --- */
.mf-imp-result { text-align: center; padding: 12px 0 4px; }
.mf-imp-result-ring {
  width: 60px; height: 60px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--success-50); color: var(--success-600);
}
.mf-imp-result-head { font-size: var(--fs-lg); font-weight: 700; color: var(--text); margin-bottom: 12px; }
.mf-imp-result-list {
  list-style: none; margin: 0 auto; padding: 0; max-width: 320px;
  text-align: left; font-size: var(--fs-sm); color: var(--text-muted);
}
.mf-imp-result-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.mf-imp-result-list li:last-child { border-bottom: 0; }
.mf-imp-result-list strong { color: var(--text); }

@media (max-width: 560px) {
  .mf-imp-grid { grid-template-columns: 1fr 1fr; }
  .mf-imp-gh:nth-child(2), .mf-imp-samp { display: none; }
}
