/* =====================================================
   DSJ SUPPLEMENT — GLOBAL STYLES & THEMES
   Themes are defined only through the tokens below.
   Components must use tokens, never raw colors, so both
   themes stay consistent. Theme is set on <html data-theme>.
   ===================================================== */

/* ===== DESIGN TOKENS — DARK (default) ===== */
:root {
  color-scheme: dark;

  /* Surfaces (from back to front) */
  --bg-body: #0e0f12;
  --bg-sidebar: #131418;
  --bg-header: rgba(19, 20, 24, 0.82);
  --bg-card: #17181d;
  --bg-elevated: #1d1e24;      /* dropdowns, modals, popovers */
  --bg-subtle: #141519;        /* table headers, section headers, form toolbars */
  --bg-input: #111216;
  --bg-input-focus: #111216;
  --bg-hover: #202128;
  --bg-active: #272830;

  /* Text */
  --text-strong: #f5f5f7;      /* headings, emphasized values */
  --text-primary: #e2e2e7;
  --text-secondary: #a9a9b4;
  --text-muted: #80808c;
  --text-faint: #6c6c78;       /* uppercase labels, table headers */

  /* Lines */
  --border: #25262d;
  --border-light: #33343d;     /* stronger border: inputs, hover */

  /* Brand */
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --accent-text: #8b8ef8;      /* accent used as text/link color */
  --accent-soft: rgba(99, 102, 241, 0.14);
  --accent-border: rgba(99, 102, 241, 0.35);
  --on-accent: #ffffff;

  /* Status: solid / soft background / readable text */
  --success: #22c55e;  --success-soft: rgba(34, 197, 94, 0.14);   --success-text: #4ade80;
  --warning: #eab308;  --warning-soft: rgba(234, 179, 8, 0.14);   --warning-text: #facc15;
  --danger: #ef4444;   --danger-soft: rgba(239, 68, 68, 0.14);    --danger-text: #f87171;
  --info: #3b82f6;     --info-soft: rgba(59, 130, 246, 0.14);     --info-text: #60a5fa;
  --purple: #8b5cf6;   --purple-soft: rgba(139, 92, 246, 0.16);   --purple-text: #a78bfa;
  --teal: #14b8a6;     --teal-soft: rgba(20, 184, 166, 0.14);     --teal-text: #2dd4bf;
  --neutral-soft: rgba(148, 148, 160, 0.14);                      --neutral-text: #a9a9b4;

  /* Depth */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
  --overlay: rgba(6, 7, 9, 0.72);
  --focus-ring: 0 0 0 3px rgba(99, 102, 241, 0.35);
  --scrollbar: #2c2d35;
  --scrollbar-hover: #3b3c46;

  /* Shape & motion */
  --sidebar-width: 256px;
  --header-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.18s ease;

  /* Legacy aliases — used by page-level styles; keep them mapped to the tokens above */
  --text-white: var(--text-strong);
  --text-dark: var(--text-faint);
  --accent-hover: var(--accent-text);
  --accent-glow: var(--accent-soft);
}

/* ===== DESIGN TOKENS — LIGHT ===== */
:root[data-theme="light"] {
  color-scheme: light;

  --bg-body: #f4f5f7;
  --bg-sidebar: #fbfbfc;
  --bg-header: rgba(251, 251, 252, 0.85);
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-subtle: #f7f8fa;
  --bg-input: #f8f9fb;          /* also used by pages as a recessed panel, so not pure white */
  --bg-input-focus: #ffffff;
  --bg-hover: #f0f1f4;
  --bg-active: #e8e9ee;

  --text-strong: #1d1d1f;
  --text-primary: #2c2c31;
  --text-secondary: #53535b;
  --text-muted: #6b6b74;
  --text-faint: #75757f;

  --border: #e4e5ea;
  --border-light: #d2d3da;

  --accent: #5b5ef0;
  --accent-strong: #4f46e5;
  --accent-text: #4a44d6;
  --accent-soft: rgba(91, 94, 240, 0.10);
  --accent-border: rgba(91, 94, 240, 0.35);
  --on-accent: #ffffff;

  --success: #16a34a;  --success-soft: rgba(22, 163, 74, 0.10);   --success-text: #15803d;
  --warning: #d97706;  --warning-soft: rgba(217, 119, 6, 0.12);   --warning-text: #a15c07;
  --danger: #dc2626;   --danger-soft: rgba(220, 38, 38, 0.09);    --danger-text: #c01f1f;
  --info: #2563eb;     --info-soft: rgba(37, 99, 235, 0.09);      --info-text: #1d4ed8;
  --purple: #7c3aed;   --purple-soft: rgba(124, 58, 237, 0.09);   --purple-text: #6d28d9;
  --teal: #0d9488;     --teal-soft: rgba(13, 148, 136, 0.10);     --teal-text: #0f766e;
  --neutral-soft: rgba(83, 83, 91, 0.08);                         --neutral-text: #53535b;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 48px rgba(16, 24, 40, 0.16);
  --overlay: rgba(24, 25, 32, 0.38);
  --focus-ring: 0 0 0 3px rgba(91, 94, 240, 0.25);
  --scrollbar: #d3d4da;
  --scrollbar-hover: #b9bac2;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { color: var(--text-strong); letter-spacing: -0.01em; }
a { color: var(--accent-text); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; background: var(--bg-hover); padding: 1px 5px; border-radius: 4px; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 6px; }

/* ===== LAYOUT ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; top: 0; left: 0; width: var(--sidebar-width); height: 100vh;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 1000; transition: transform 0.3s ease;
}
.main {
  flex: 1; margin-left: var(--sidebar-width);
  display: flex; flex-direction: column; min-height: 100vh; transition: margin-left 0.3s ease;
  min-width: 0; /* let wide tables scroll inside .table-responsive instead of stretching the page */
}
.header {
  position: sticky; top: 0; height: var(--header-height);
  background: var(--bg-header);
  -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 12px; z-index: 100;
}
.content { flex: 1; padding: 28px; max-width: 1480px; width: 100%; }

/* ===== SIDEBAR ===== */
.sidebar-header {
  height: var(--header-height); padding: 0 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; min-width: 0; color: inherit; }
.sidebar-brand:hover { color: inherit; }
.sidebar-brand-text { min-width: 0; }
.sidebar-brand-text .sidebar-title, .sidebar-brand-text .sidebar-subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Configured logo: keeps proportions, never stretched; size capped per context */
.brand-logo { display: block; width: auto; height: auto; object-fit: contain; flex-shrink: 0; }
.brand-logo-sidebar { max-height: 38px; max-width: 176px; }
.brand-logo-login { max-height: 76px; max-width: 240px; margin: 0 auto 18px; }
.brand-logo-dark { display: none; }
:root:not([data-theme="light"]) .brand-logo-light.has-dark-variant { display: none; }
:root:not([data-theme="light"]) .brand-logo-dark { display: block; }
.sidebar-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 17px; box-shadow: var(--shadow-sm); flex-shrink: 0;
}
.sidebar-title { font-size: 16px; font-weight: 700; color: var(--text-strong); line-height: 1.15; letter-spacing: -0.01em; }
.sidebar-subtitle { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1.2px; }
.sidebar-close {
  width: 32px; height: 32px; background: var(--bg-hover); border: none;
  border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 15px;
  cursor: pointer; display: none; align-items: center; justify-content: center;
}
.sidebar-close:hover { background: var(--bg-active); color: var(--text-strong); }
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-label {
  font-size: 10.5px; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: 1.1px; padding: 18px 12px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  color: var(--text-secondary); border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; transition: background var(--transition), color var(--transition);
  margin-bottom: 1px; position: relative;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text-strong); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-text); }
.nav-link.active::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}
.nav-icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-text { flex: 1; }
.nav-badge {
  background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 600;
  padding: 1px 7px; border-radius: 10px; min-width: 20px; text-align: center;
}
.nav-badge-unread { background: var(--warning); color: #1a1a1a; animation: pulse-badge 2s infinite; }
@keyframes pulse-badge { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
.nav-dropdown-toggle { cursor: pointer; }
.nav-dropdown-toggle::after { content: '›'; font-size: 16px; color: var(--text-muted); transition: transform var(--transition); }
.nav-dropdown.open .nav-dropdown-toggle::after { transform: rotate(90deg); }
.nav-dropdown-menu { display: none; padding: 2px 0 6px 33px; }
.nav-dropdown.open .nav-dropdown-menu { display: block; }
.nav-dropdown-item {
  display: block; padding: 7px 12px; color: var(--text-muted);
  font-size: 13px; border-radius: var(--radius-sm); transition: background var(--transition), color var(--transition);
}
.nav-dropdown-item:hover { background: var(--bg-hover); color: var(--text-strong); }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid var(--border); }
.sidebar-version { font-size: 11px; color: var(--text-faint); text-align: center; }

/* ===== HEADER ===== */
.menu-toggle, .theme-toggle, .header-icon-btn {
  width: 36px; height: 36px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary); font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), border-color var(--transition); flex-shrink: 0;
}
.menu-toggle:hover, .theme-toggle:hover, .header-icon-btn:hover { background: var(--bg-hover); border-color: var(--border-light); }
.theme-toggle, .header-icon-btn { border-radius: 50%; font-size: 15px; }
.header-icon-btn { font-weight: 700; color: var(--text-secondary); text-decoration: none; }
.header-icon-btn:hover { color: var(--text-strong); }
.theme-toggle .theme-icon-light { display: none; }
:root[data-theme="light"] .theme-toggle .theme-icon-light { display: inline; }
:root[data-theme="light"] .theme-toggle .theme-icon-dark { display: none; }
.header-title { font-size: 16px; font-weight: 600; color: var(--text-strong); letter-spacing: -0.01em; }
.header-spacer { flex: 1; }
.header-datetime { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.header-datetime .header-date { font-size: 11.5px; color: var(--text-muted); font-weight: 500; }
.header-datetime .header-time { font-size: 13px; color: var(--text-strong); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Notification badges */
.header-notifications { display: flex; align-items: center; gap: 6px; }
.notif-badge {
  display: flex; align-items: center; gap: 6px; padding: 6px 11px; height: 36px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; font-size: 12px; color: var(--text-secondary);
  text-decoration: none; transition: background var(--transition), border-color var(--transition); position: relative;
}
.notif-badge:hover { background: var(--bg-hover); border-color: var(--border-light); color: var(--text-strong); }
.notif-badge .notif-icon { font-size: 14px; }
.notif-badge .notif-count {
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 10px; min-width: 18px; text-align: center;
}
.notif-badge.has-new { border-color: var(--accent-border); }
.notif-badge.has-new .notif-count { background: var(--accent); color: var(--on-accent); }

/* Notification dropdown */
.notif-wrapper { position: relative; }
.notif-trigger { cursor: pointer; }
.notif-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 8px;
  width: 340px; max-height: 420px; overflow-y: auto;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 1000; display: none;
}
.notif-dropdown.open { display: block; animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.notif-dropdown-header {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.notif-dropdown-title { font-size: 13.5px; font-weight: 600; color: var(--text-strong); }
.notif-dropdown-clear { font-size: 11.5px; color: var(--accent-text); cursor: pointer; text-decoration: none; padding: 4px 8px; border-radius: 6px; }
.notif-dropdown-clear:hover { background: var(--accent-soft); }
.notif-list { padding: 4px 0; }
.notif-item {
  display: flex; gap: 12px; padding: 11px 16px;
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background var(--transition); text-decoration: none;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-hover); }
.notif-item-icon {
  width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0;
}
.notif-item-icon.note { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.notif-item-icon.status { background: linear-gradient(135deg, #f59e0b, #d97706); }
.notif-item-icon.activity { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.notif-item-content { flex: 1; min-width: 0; }
.notif-item-title { font-size: 13px; font-weight: 500; color: var(--text-strong); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-item-desc { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-item-time { font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.notif-empty { padding: 30px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.notif-empty-icon { font-size: 30px; margin-bottom: 8px; opacity: 0.5; }
.notif-dropdown-footer { padding: 11px 16px; border-top: 1px solid var(--border); text-align: center; }
.notif-dropdown-footer a { font-size: 12px; color: var(--accent-text); font-weight: 500; }
.notif-dropdown-footer a:hover { text-decoration: underline; }

/* User & logout */
.header-user {
  display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 4px; height: 36px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 50px; transition: border-color var(--transition), background var(--transition);
}
.header-user:hover { border-color: var(--border-light); background: var(--bg-hover); }
.header-avatar {
  width: 28px; height: 28px; background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 600;
}
.header-user-info { line-height: 1.25; }
.header-user-name { font-size: 12.5px; font-weight: 600; color: var(--text-strong); }
.header-user-role { font-size: 10.5px; color: var(--text-muted); }
.btn-logout {
  height: 36px; padding: 0 14px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px;
  cursor: pointer; display: flex; align-items: center; gap: 7px;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  text-decoration: none; font-weight: 500;
}
.btn-logout:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger-text); }
.btn-logout-icon { font-size: 15px; }

/* ===== PAGE ===== */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 14px;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text-strong); letter-spacing: -0.02em; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 15px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.card-title { font-size: 14.5px; font-weight: 600; color: var(--text-strong); }
.card-body { padding: 20px; }

/* ===== STATS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; transition: border-color var(--transition), transform var(--transition);
  position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
}
.stat-card:hover { border-color: var(--accent-border); transform: translateY(-1px); }
.stat-icon {
  width: 42px; height: 42px; background: var(--accent-soft);
  border-radius: var(--radius-sm); display: flex; align-items: center;
  justify-content: center; font-size: 20px; margin-bottom: 14px;
}
.stat-value { font-size: 26px; font-weight: 700; color: var(--text-strong); line-height: 1; margin-bottom: 6px; }
.stat-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 16px; font-size: 13.5px; font-weight: 600; border-radius: var(--radius-sm);
  border: 1px solid var(--border-light); background: var(--bg-card); color: var(--text-primary);
  cursor: pointer; white-space: nowrap; text-decoration: none; line-height: 1;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), filter var(--transition);
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-light); color: var(--text-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); filter: brightness(1.08); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: var(--success); border-color: var(--success); color: #fff; filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; filter: brightness(1.08); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block; font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 7px;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 12px; background: var(--bg-input);
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 14px; line-height: 1.4;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.form-input:hover, .form-select:hover, .form-textarea:hover { border-color: var(--text-faint); }
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-faint); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); background: var(--bg-input-focus);
}
.form-input:disabled, .form-input[readonly] { background: var(--bg-hover); color: var(--text-muted); cursor: not-allowed; }
.form-textarea, textarea.form-input { min-height: 96px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.is-invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-soft) !important; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* ===== TABLES ===== */
.table-responsive { overflow-x: auto; }
/* .data-table is the class used by the reports module */
.table, .data-table { width: 100%; border-collapse: collapse; }
.table th, .data-table th {
  padding: 11px 16px; text-align: left; font-size: 11px; font-weight: 600;
  color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.6px;
  background: var(--bg-subtle); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td, .data-table td {
  padding: 13px 16px; font-size: 13.5px; color: var(--text-primary);
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
.table tbody tr:last-child td, .data-table tbody tr:last-child td { border-bottom: none; }
.table tbody tr, .data-table tbody tr { transition: background var(--transition); }
.table tbody tr:hover, .data-table tbody tr:hover { background: var(--bg-hover); }

/* Lists marked .table-cards turn each row into a card on phones (td needs data-label) */
@media (max-width: 640px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table-cards tbody tr:last-child { border-bottom: none; }
  .table-cards td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 5px 0 !important; border-bottom: none; text-align: right;
  }
  .table-cards td::before {
    content: attr(data-label); flex-shrink: 0; text-align: left;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted);
  }
  .table-cards td:not([data-label])::before, .table-cards td[data-label=""]::before { content: none; }
  .table-cards td.cell-actions { justify-content: flex-end; padding-top: 10px !important; }
}

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; padding: 3px 9px;
  font-size: 10.5px; font-weight: 600; border-radius: 20px;
  text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap;
}
.badge-primary { background: var(--accent-soft); color: var(--accent-text); }
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-purple { background: var(--purple-soft); color: var(--purple-text); }
.badge-secondary { background: var(--neutral-soft); color: var(--neutral-text); }

/* ===== TABS ===== */
.tabs {
  display: flex; gap: 4px; padding: 5px; background: var(--bg-subtle); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 20px; overflow-x: auto;
}
.tab {
  padding: 8px 16px; font-size: 13.5px; font-weight: 500; color: var(--text-secondary);
  background: transparent; border: none; border-radius: 6px;
  cursor: pointer; transition: background var(--transition), color var(--transition); white-space: nowrap;
}
.tab:hover { color: var(--text-strong); }
.tab.active { background: var(--bg-card); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== ALERTS ===== */
.alert {
  padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 20px;
  font-size: 13.5px; display: flex; align-items: center; gap: 12px; border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); border-color: var(--success-soft); color: var(--success-text); }
.alert-danger, .alert-error { background: var(--danger-soft); border-color: var(--danger-soft); color: var(--danger-text); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-soft); color: var(--warning-text); }
.alert-info { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-text); }

.flash {
  position: fixed; top: 18px; right: 18px; padding: 13px 20px;
  border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500;
  z-index: 9999; animation: slideIn 0.3s ease; box-shadow: var(--shadow-lg); max-width: 400px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(80px); } to { opacity: 1; transform: translateX(0); } }
.flash-success { background: var(--success); color: #fff; }
.flash-error { background: var(--danger); color: #fff; }
.flash-warning { background: var(--warning); color: #1a1a1a; }
.flash-info { background: var(--info); color: #fff; }

/* ===== SETTINGS & ADMIN FORMS ===== */
.settings-tabs {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; margin-bottom: 22px;
  background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 10px;
}
.settings-tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; white-space: nowrap;
  font-size: 13.5px; font-weight: 500; color: var(--text-secondary); border-radius: 7px;
  transition: background var(--transition), color var(--transition);
}
.settings-tab:hover { color: var(--text-strong); background: var(--bg-hover); }
.settings-tab.active { background: var(--bg-card); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.settings-grid-wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.settings-grid > .card, .settings-grid > div > .card { margin-bottom: 0; }
.settings-breadcrumb { margin-bottom: 10px; font-size: 13px; }
.page-subheader { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.section-heading { font-size: 18px; font-weight: 700; margin-bottom: 2px; }
.form-hint { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.45; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.form-input-sm { padding: 6px 8px; font-size: 13px; width: auto; min-width: 76px; }
.check-row { display: flex; align-items: flex-start; gap: 10px; font-size: 13.5px; color: var(--text-primary); cursor: pointer; line-height: 1.4; }
.check-row input { width: 16px; height: 16px; margin-top: 2px; flex-shrink: 0; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 16px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { margin: 0; }
.btn-ghost-danger { color: var(--danger-text); }
.btn-ghost-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger-text); }
.border-top { border-top: 1px solid var(--border); }
.filter-bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filter-bar .form-group { margin-bottom: 0; min-width: 160px; flex: 1; }
.filter-actions { display: flex; gap: 8px; }
.pagination-bar { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 14px; border-top: 1px solid var(--border); font-size: 13px; }

/* On/off switch (a submit button) */
.switch {
  display: inline-flex; align-items: center; gap: 8px; background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 12.5px; font-weight: 600; padding: 2px 0;
}
.switch-knob {
  position: relative; width: 36px; height: 20px; border-radius: 20px; background: var(--border-light);
  transition: background var(--transition); flex-shrink: 0;
}
.switch-knob::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--transition);
}
.switch.on { color: var(--success-text); }
.switch.on .switch-knob { background: var(--success); }
.switch.on .switch-knob::after { transform: translateX(16px); }

/* Logo previews: fixed light and dark backgrounds on purpose, to show both contexts */
.logo-previews { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.logo-preview {
  position: relative; height: 110px; border-radius: 10px; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; padding: 16px 16px 26px; font-size: 12.5px;
}
.logo-preview img { max-height: 56px; max-width: 100%; width: auto; height: auto; object-fit: contain; }
.logo-preview-light { background: #ffffff; color: #6b6b74; }
.logo-preview-dark { background: #17181d; color: #a9a9b4; }
.logo-preview-label { position: absolute; bottom: 6px; left: 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; opacity: 0.7; }
.logo-upload-form { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.logo-upload-form .form-input { flex: 1; min-width: 200px; }

/* Recipients & template variables */
.recipient-list { display: flex; flex-direction: column; }
.recipient-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
}
.recipient-item:last-child { border-bottom: none; }
.recipient-item.is-inactive .recipient-cell { opacity: 0.55; }
.recipient-cell, .resource-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.recipient-cell > div, .resource-cell > div { min-width: 0; overflow-wrap: break-word; }
.recipient-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--bg-subtle); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.recipient-name { font-size: 13.5px; font-weight: 600; color: var(--text-strong); line-height: 1.3; }
.recipient-sub { font-size: 12px; color: var(--text-muted); line-height: 1.35; margin-top: 2px; }
.row-actions-nowrap { flex-wrap: nowrap; }
.btn-icon { width: 32px; padding: 0; }
.subsection-heading { font-size: 13.5px; font-weight: 600; color: var(--text-strong); margin-bottom: 4px; }
.subsection-hint { margin-top: 0; margin-bottom: 16px; }
.card-footer-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 16px; padding-bottom: 16px; }
.card-footer-bar .form-hint { margin: 0; }

/* "Who receives what" matrix */
.matrix-table th, .matrix-table td { vertical-align: middle; }
.matrix-table th:first-child, .matrix-table td:first-child { min-width: 260px; }
.matrix-table th:nth-child(2), .matrix-table td:nth-child(2) { width: 120px; }
.matrix-table th.text-center { white-space: normal; min-width: 96px; line-height: 1.3; }
.matrix-table input[type="checkbox"] { width: 17px; height: 17px; cursor: pointer; }
.matrix-table .form-input-sm { width: 90px; }
.resource-icon { font-size: 20px; width: 28px; text-align: center; flex-shrink: 0; }
.resource-url { font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.var-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.var-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px;
  padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border-light);
  background: var(--bg-subtle); color: var(--accent-text); cursor: pointer;
}
.var-chip:hover { background: var(--accent-soft); border-color: var(--accent-border); }
.email-preview { display: block; width: 100%; height: 520px; border: 0; background: #f4f5f7; }
.log-recipients { font-size: 12.5px; overflow-wrap: anywhere; }
.log-error { margin-top: 4px; font-size: 11.5px; color: var(--danger-text); max-width: 260px; }

/* Help page */
.help-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.help-card {
  display: flex; gap: 14px; align-items: flex-start; padding: 18px; color: inherit;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}
.help-card:hover { color: inherit; border-color: var(--accent-border); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.help-card-featured { border-color: var(--accent-border); background: linear-gradient(0deg, var(--accent-soft), var(--accent-soft)), var(--bg-card); }
.help-card-icon { font-size: 26px; line-height: 1; flex-shrink: 0; }
.help-card-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.help-card-title { font-size: 15px; font-weight: 600; color: var(--text-strong); }
.help-card-desc { font-size: 13px; color: var(--text-secondary); }
.help-card-type { font-size: 11.5px; color: var(--accent-text); font-weight: 500; margin-top: 4px; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 56px 20px; }
.empty-state-icon { font-size: 48px; opacity: 0.35; margin-bottom: 14px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.empty-state-text { font-size: 13.5px; color: var(--text-muted); margin-bottom: 18px; }

/* ===== FILE UPLOAD ===== */
.file-upload {
  border: 2px dashed var(--border-light); border-radius: var(--radius); padding: 36px 20px;
  text-align: center; cursor: pointer; transition: border-color var(--transition), background var(--transition); background: var(--bg-input);
}
.file-upload:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ===== UTILITIES ===== */
.text-white { color: var(--text-strong); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success-text); }
.text-danger { color: var(--danger-text); }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

/* ===== SPINNER ===== */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35); border-radius: 50%;
  border-top-color: #fff; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SIDEBAR COLLAPSED / OVERLAY ===== */
.sidebar-collapsed .sidebar { width: 0; overflow: hidden; border-right: none; }
.sidebar-collapsed .main { margin-left: 0; }
.overlay {
  position: fixed; inset: 0; background: var(--overlay);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  z-index: 999; opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
}
.overlay.active { opacity: 1; visibility: visible; }

/* ===== MOBILE FLOATING SAVE BAR ===== */
.mobile-save-bar { display: none; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 10px; border: 2px solid var(--bg-body); }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }
* { scrollbar-color: var(--scrollbar) transparent; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .main { margin-left: 0; }
  .sidebar-collapsed .sidebar { width: var(--sidebar-width); }
  .sidebar-collapsed .main { margin-left: 0; }
  .content { padding: 22px; }
  .settings-grid, .settings-grid-wide { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 768px) {
  .content { padding: 16px; padding-bottom: 40px; }
  .header { padding: 0 12px; gap: 8px; }
  .header-title { font-size: 14px; }
  .page-header { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 20px; }
  .page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .page-actions .btn { flex: 1 1 calc(50% - 4px); min-width: calc(50% - 4px); }
  .form-row, .grid-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .header-datetime { display: none; }
  .header-user-info { display: none; }
  .header-user { padding: 4px; }
  .card { margin-bottom: 16px; border-radius: 10px; }
  .card-header { padding: 12px 16px; }
  .card-body { padding: 16px; }
  .table th, .table td, .data-table th, .data-table td { padding: 10px 12px; font-size: 13px; }
  .btn { height: 42px; padding: 0 16px; font-size: 14px; }
  .btn-sm { height: 36px; }
  .notif-dropdown { width: 300px; right: -50px; }
  .tabs-grid { grid-template-columns: repeat(4, 1fr) !important; gap: 6px !important; padding: 10px !important; }
  .tab-item { padding: 8px 4px !important; }
  .tab-text { font-size: 9px !important; }
  .mobile-save-bar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg-elevated); padding: 12px 16px; gap: 10px;
    border-top: 1px solid var(--border); box-shadow: var(--shadow-lg); z-index: 999;
  }
  .mobile-save-bar .btn { flex: 1; height: 46px; font-size: 15px; }
  .content { padding-bottom: 84px !important; }
}
@media (max-width: 480px) {
  .content { padding: 12px; padding-bottom: 30px; }
  .header { padding: 0 8px; gap: 6px; }
  .header-title { font-size: 13px; min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-spacer { display: none; }
  .header-notifications { gap: 4px; }
  .notif-badge { padding: 5px 8px; height: 34px; }
  .notif-badge .notif-icon { font-size: 12px; }
  .notif-badge .notif-count { font-size: 9px; padding: 1px 4px; min-width: 14px; }
  .menu-toggle, .theme-toggle, .header-icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .header-icon-btn { display: none; } /* Help stays reachable from the menu on phones */
  .recipient-item { grid-template-columns: minmax(0, 1fr); padding: 12px 14px; }
  .recipient-item .row-actions { justify-content: flex-start; }
  .logo-previews { grid-template-columns: 1fr; }
  .header-avatar { width: 26px; height: 26px; font-size: 11px; }
  .btn-logout { padding: 0 10px; height: 34px; }
  .btn-logout span:not(.btn-logout-icon) { display: none; }
  .tabs { flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab { padding: 8px 12px; font-size: 12px; }
  .page-title { font-size: 19px; }
  .page-actions { gap: 6px; }
  .page-actions .btn { min-width: calc(50% - 3px); font-size: 13px; }
  .card { border-radius: 10px; }
  .card-header { padding: 11px 13px; }
  .card-body { padding: 13px; }
  .card-title { font-size: 14px; }
  .form-group { margin-bottom: 14px; }
  .form-input, .form-select, .form-textarea { padding: 11px 12px; font-size: 16px; } /* 16px avoids iOS zoom */
  .badge { font-size: 10px; padding: 3px 8px; }
  .notif-dropdown { width: 270px; right: -100px; max-height: 350px; }
  .notif-item { padding: 10px 12px; gap: 10px; }
  .table th, .table td, .data-table th, .data-table td { padding: 8px 10px; }
  .tabs-grid { grid-template-columns: repeat(4, 1fr) !important; gap: 4px !important; padding: 8px !important; }
  .tab-item { padding: 6px 2px !important; }
  .tab-icon { font-size: 16px !important; }
  .tab-text { display: none !important; }
}
