/* =========================================================================
 * DevSync UI — shared design system (modern refresh)
 *
 * SCOPING STRATEGY (important for incremental rollout):
 *   - :root tokens + global widgets (toasts, loading overlay, confirm dialog,
 *     .ui-btn) are UNSCOPED and safe on every page (no class collisions).
 *   - All page-component styles (.btn, .card, .table, .modal, .badge,
 *     .status-*, forms, etc.) are scoped under `body.ui-base`, which only
 *     MIGRATED pages set. Un-migrated pages are therefore unaffected, so we
 *     can deploy the design system in waves without breaking old pages.
 * ========================================================================= */

/* ---- Tokens (global) ------------------------------------------------- */
:root {
  /* Sync.al brand: Primary Blue + Sync Teal (see brand guidelines). */
  --brand: #2A6FE0; --brand-600: #245fc4; --brand-700: #1e4fa3;
  --brand-soft: #dbe7fb; --brand-tint: #eff4fd;
  --navy: #14171F; --navy-700: #232733; --navy-600: #333947;
  --bg: #f1f5f9; --surface: #ffffff; --surface-2: #f8fafc;
  --border: #e2e8f0; --border-strong: #cbd5e1;
  --text: #0f172a; --text-2: #475569; --text-3: #94a3b8;
  --success: #1C93A8; --success-bg: #d6eef2;
  --error: #dc2626; --error-bg: #fee2e2;
  --warning: #d97706; --warning-bg: #fef3c7;
  --info: #2A6FE0; --info-bg: #dbe7fb;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-full: 999px;
  --sh-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.10);
  --sh-md: 0 4px 6px -1px rgba(15,23,42,.08), 0 2px 4px -2px rgba(15,23,42,.06);
  --sh-lg: 0 10px 25px -5px rgba(15,23,42,.15), 0 8px 10px -6px rgba(15,23,42,.10);
  --font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Manrope', 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px;
  --ring: 0 0 0 3px rgba(42,111,224,.25);
}

/* ---- Dark theme (set data-theme="dark" on <html>) ------------------- */
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #1e293b; --surface-2: #263449;
  --border: #334155; --border-strong: #475569;
  --text: #e2e8f0; --text-2: #94a3b8; --text-3: #64748b;
  --brand-700: #6aa3f0; --brand-soft: rgba(42,111,224,.30); --brand-tint: rgba(42,111,224,.14);
  --success: #34b3c6; --success-bg: rgba(28,147,168,.20);
  --error: #f87171; --error-bg: rgba(248,113,113,.16);
  --warning: #fbbf24; --warning-bg: rgba(251,191,36,.16);
  --info: #6aa3f0; --info-bg: rgba(42,111,224,.16);
  --sh-sm: 0 1px 2px rgba(0,0,0,.4);
  --sh-md: 0 4px 6px -1px rgba(0,0,0,.5), 0 2px 4px -2px rgba(0,0,0,.4);
  --sh-lg: 0 10px 25px -5px rgba(0,0,0,.6), 0 8px 10px -6px rgba(0,0,0,.5);
  --ring: 0 0 0 3px rgba(42,111,224,.35);
}

/* =========================================================================
 * GLOBAL widgets — safe on every page (no collisions)
 * ========================================================================= */

/* Toasts */
#ui-toast-container { position: fixed; top: 18px; right: 18px; z-index: 100000; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 36px)); pointer-events: none; }
.ui-toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; background: var(--surface); color: var(--text); border-left: 5px solid var(--info); border-radius: var(--r); box-shadow: var(--sh-lg); padding: 13px 14px; font-size: 14px; line-height: 1.4; opacity: 0; transform: translateX(20px); transition: opacity .22s ease, transform .22s ease; word-break: break-word; font-family: var(--font); }
.ui-toast.ui-show { opacity: 1; transform: translateX(0); }
.ui-toast.ui-success { border-left-color: var(--success); }
.ui-toast.ui-error { border-left-color: var(--error); }
.ui-toast.ui-warning { border-left-color: var(--warning); }
.ui-toast.ui-info { border-left-color: var(--info); }
.ui-toast__icon { font-size: 16px; line-height: 1.4; flex: 0 0 auto; }
.ui-toast.ui-success .ui-toast__icon { color: var(--success); }
.ui-toast.ui-error .ui-toast__icon { color: var(--error); }
.ui-toast.ui-warning .ui-toast__icon { color: var(--warning); }
.ui-toast.ui-info .ui-toast__icon { color: var(--info); }
.ui-toast__msg { flex: 1 1 auto; }
.ui-toast__close { flex: 0 0 auto; background: none; border: none; cursor: pointer; color: #94a3b8; font-size: 16px; line-height: 1; padding: 0 2px; }
.ui-toast__close:hover { color: #475569; }

/* Loading overlay + spinner */
#ui-loading-overlay { position: fixed; inset: 0; z-index: 99999; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 14px; background: rgba(15,23,42,.45); backdrop-filter: blur(1.5px); }
#ui-loading-overlay.ui-show { display: flex; }
.ui-spinner { width: 46px; height: 46px; border: 4px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: ui-spin .8s linear infinite; }
#ui-loading-overlay .ui-loading-text { color: #fff; font-size: 15px; font-weight: 500; font-family: var(--font); }
.ui-spinner-sm { display: inline-block; width: 16px; height: 16px; border: 2.5px solid rgba(0,0,0,.15); border-top-color: currentColor; border-radius: 50%; animation: ui-spin .8s linear infinite; vertical-align: -3px; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* Confirm dialog (uses its own .ui-btn so it works on any page) */
#ui-confirm-backdrop { position: fixed; inset: 0; z-index: 100001; display: none; align-items: center; justify-content: center; background: rgba(15,23,42,.5); padding: 20px; }
#ui-confirm-backdrop.ui-show { display: flex; }
.ui-confirm { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-lg); width: min(440px, 100%); padding: 22px 22px 18px; animation: ui-pop .15s ease; font-family: var(--font); }
@keyframes ui-pop { from { transform: scale(.96); opacity: .6; } to { transform: scale(1); opacity: 1; } }
.ui-confirm__title { font-size: 17px; font-weight: 700; color: var(--text); margin: 0 0 8px; }
.ui-confirm__msg { font-size: 14px; color: #475569; line-height: 1.5; margin: 0 0 18px; }
.ui-confirm__actions { display: flex; gap: 10px; justify-content: flex-end; }
.ui-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; cursor: pointer; border-radius: var(--r-sm); padding: 9px 16px; font-family: var(--font); font-size: 14px; font-weight: 600; line-height: 1; transition: filter .15s, background .15s, transform .04s; }
.ui-btn:active { transform: translateY(1px); }
.ui-btn-primary { background: var(--brand); color: #fff; }
.ui-btn-primary:hover { background: var(--brand-600); }
.ui-btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.ui-btn-secondary:hover { background: var(--surface-2); }
.ui-btn-danger { background: var(--error); color: #fff; }
.ui-btn-danger:hover { filter: brightness(1.07); }

/* =========================================================================
 * DESIGN SYSTEM — scoped under body.ui-base (migrated pages only)
 * ========================================================================= */
body.ui-base { margin: 0; font-family: var(--font); font-size: var(--fs-base); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; line-height: 1.5; }
body.ui-base h1, body.ui-base h2, body.ui-base h3, body.ui-base h4 { margin: 0 0 var(--sp-3); color: var(--text); font-family: var(--font-display); font-weight: 800; letter-spacing: -0.01em; line-height: 1.25; }
body.ui-base h1 { font-size: var(--fs-2xl); }
body.ui-base h2 { font-size: var(--fs-xl); }
body.ui-base h3 { font-size: var(--fs-lg); }
body.ui-base a { color: var(--brand-600); text-decoration: none; }
body.ui-base a:hover { text-decoration: underline; }
.ui-base .ui-muted { color: var(--text-2); }
.ui-base .ui-small { font-size: var(--fs-sm); color: var(--text-2); }

/* App shell — fixed left sidebar + top bar; content offset via body padding. */
body.ui-base.has-sidebar { --sb-w: 240px; --sb-rail: 66px; --tb-h: 60px; padding-left: var(--sb-w); padding-top: var(--tb-h); transition: padding-left .18s ease; }
body.ui-base.sidebar-collapsed { --sb-w: var(--sb-rail); }

/* Sidebar */
.ui-base .app-sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sb-w); z-index: 1100; display: flex; flex-direction: column; background: var(--navy); color: #fff; box-shadow: var(--sh-md); overflow-x: hidden; overflow-y: auto; transition: width .18s ease, transform .18s ease; }
.ui-base .app-sidebar__brand { display: flex; align-items: center; gap: var(--sp-3); height: var(--tb-h); padding: 0 18px; font-family: var(--font-display); font-weight: 800; font-size: var(--fs-md); letter-spacing: -0.01em; color: #fff; white-space: nowrap; flex: 0 0 auto; }
.ui-base .app-sidebar__brand:hover { text-decoration: none; }
.ui-base .app-sidebar__brand img { height: 26px; width: auto; flex: 0 0 auto; }
.ui-base .app-sidebar__nav { flex: 1 1 auto; padding: var(--sp-3) 0; display: flex; flex-direction: column; gap: 2px; }
.ui-base .app-sidebar__section { padding: 14px 18px 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #64748b; white-space: nowrap; }
.ui-base .app-sidebar__link { display: flex; align-items: center; gap: 12px; margin: 0 8px; padding: 9px 10px; border-radius: var(--r-sm); color: #cbd5e1; font-size: var(--fs-base); font-weight: 500; white-space: nowrap; transition: background .15s, color .15s; }
.ui-base .app-sidebar__link:hover { background: rgba(255,255,255,.10); color: #fff; text-decoration: none; }
.ui-base .app-sidebar__link.is-active { background: var(--brand); color: #fff; }
.ui-base .app-sidebar__icon { flex: 0 0 auto; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; }
.ui-base .app-sidebar__icon svg { width: 19px; height: 19px; display: block; }
.ui-base .app-sidebar__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ui-base .app-sidebar__toggle { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; margin: 8px; padding: 9px 10px; border: none; background: transparent; color: #94a3b8; font-family: var(--font); font-size: var(--fs-base); cursor: pointer; border-radius: var(--r-sm); }
.ui-base .app-sidebar__toggle:hover { background: rgba(255,255,255,.10); color: #fff; }

/* Collapsed icon-rail: hide text, center icons */
body.sidebar-collapsed .app-sidebar__brand-text,
body.sidebar-collapsed .app-sidebar__label,
body.sidebar-collapsed .app-sidebar__section { display: none; }
body.sidebar-collapsed .app-sidebar__link,
body.sidebar-collapsed .app-sidebar__toggle { justify-content: center; margin-left: 6px; margin-right: 6px; }
body.sidebar-collapsed .app-sidebar__brand { justify-content: center; padding: 0; }
body.sidebar-collapsed .app-sidebar__toggle svg { transform: rotate(180deg); }

/* Topbar */
.ui-base .app-topbar { position: fixed; top: 0; right: 0; left: var(--sb-w); height: var(--tb-h); z-index: 1000; display: flex; align-items: center; gap: var(--sp-4); background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 var(--sp-5); transition: left .18s ease; }
.ui-base .app-topbar__burger { display: none; border: none; background: transparent; line-height: 1; color: var(--text); cursor: pointer; padding: 6px 8px; border-radius: var(--r-sm); }
.ui-base .app-topbar__burger:hover { background: var(--surface-2); }
.ui-base .app-topbar__burger svg { width: 22px; height: 22px; display: block; }
.ui-base .app-topbar__icon-btn { padding: 7px; line-height: 0; }
.ui-base .app-topbar__icon-btn svg { width: 18px; height: 18px; display: block; }
.ui-base .app-topbar__spacer { flex: 1 1 auto; }
.ui-base .app-main { max-width: none; margin: 0; padding: var(--sp-5) var(--sp-6); }
.ui-base .app-page-title { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; }

/* User box (topbar, light background) */
.ui-base .app-user { display: flex; align-items: center; gap: var(--sp-3); flex: 0 0 auto; }
.ui-base .app-user__info { text-align: right; line-height: 1.2; }
.ui-base .app-user__name { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.ui-base .app-user__role { font-size: var(--fs-xs); color: var(--text-2); text-transform: capitalize; }

/* Overlay for the mobile off-canvas drawer */
.ui-base .app-overlay { display: none; position: fixed; inset: 0; z-index: 1050; background: rgba(15,23,42,.5); }

/* Global active-company switcher (topbar, light background) */
.ui-base .app-company { display: flex; align-items: center; gap: var(--sp-2); position: relative; flex: 0 1 auto; min-width: 0; }
.ui-base .app-company__avatar { width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .3px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.ui-base .app-company .company-combo { width: 260px; max-width: 34vw; min-width: 130px; }
.ui-base .app-company__input { width: 100%; min-width: 0; height: 36px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: var(--fs-base); font-family: var(--font); text-overflow: ellipsis; }
.ui-base .app-company__input::placeholder { color: var(--text-3); }
.ui-base .app-company__input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.ui-base .app-company__avatar.has-logo { box-shadow: inset 0 0 0 1px var(--border); overflow: hidden; }
.ui-base .app-company__avatar img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; display: block; box-sizing: border-box; padding: 3px; }
.ui-base .app-company__dot { width: 10px; height: 10px; border-radius: var(--r-full); flex: 0 0 auto; }
.ui-base .app-company__dot.has-logo { width: 18px; height: 18px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); border-radius: 4px; background: #fff; }
.ui-base .app-company__dot img { width: 100%; height: 100%; object-fit: contain; display: block; box-sizing: border-box; padding: 1px; }
/* Company-logo preview used in the edit-company modal. */
.ui-base .company-logo-preview { width: 48px; height: 48px; border-radius: 10px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; background: var(--brand); color: #fff; font-size: 16px; font-weight: 700; overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); }
.ui-base .company-logo-preview.has-logo { background: #fff; }
.ui-base .company-logo-preview img { width: 100%; height: 100%; object-fit: contain; display: block; box-sizing: border-box; padding: 4px; }

/* Searchable combobox dropdown (shell switcher + any page combos) */
.ui-base .company-combo { position: relative; }
.ui-base .company-combo__list { display: none; position: absolute; z-index: 1100; left: 0; right: 0; top: 100%; max-height: 340px; overflow-y: auto; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r); margin-top: 4px; box-shadow: var(--sh-lg); }
.ui-base .company-combo__list.is-open { display: block; }
.ui-base .company-combo__item { display: flex; align-items: center; gap: var(--sp-2); padding: 8px 12px; cursor: pointer; font-size: var(--fs-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-base .company-combo__item:hover { background: var(--brand-tint); }
.ui-base .company-combo__item.is-selected { background: var(--brand); color: #fff; }
.ui-base .company-combo__empty { padding: 8px 12px; color: var(--text-3); font-size: var(--fs-base); }

@media (max-width: 900px) {
  /* Sidebar becomes an off-canvas drawer; content spans full width. */
  body.ui-base.has-sidebar { padding-left: 0; }
  .ui-base .app-topbar { left: 0; }
  .ui-base .app-topbar__burger { display: inline-flex; align-items: center; }
  .ui-base .app-sidebar { transform: translateX(-100%); width: 240px; }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open .app-overlay { display: block; }
  /* Desktop collapse is irrelevant on mobile: always show full labels. */
  .ui-base .app-sidebar__toggle { display: none; }
  body.sidebar-collapsed .app-sidebar__label,
  body.sidebar-collapsed .app-sidebar__brand-text { display: inline; }
  body.sidebar-collapsed .app-sidebar__section { display: block; }
  body.sidebar-collapsed .app-sidebar__link { justify-content: flex-start; margin-left: 8px; margin-right: 8px; }
  .ui-base .app-company .company-combo { min-width: 0; width: 200px; }
  .ui-base .app-main { padding: var(--sp-4); }
}

/* Buttons */
.ui-base .btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); border: 1px solid transparent; cursor: pointer; border-radius: var(--r-sm); padding: 9px 16px; font-family: var(--font); font-size: var(--fs-base); font-weight: 600; line-height: 1; transition: filter .15s, box-shadow .15s, transform .04s, background .15s; text-decoration: none; white-space: nowrap; }
.ui-base .btn:active { transform: translateY(1px); }
.ui-base .btn:disabled, .ui-base .btn[disabled] { opacity: .55; cursor: not-allowed; }
.ui-base .btn:hover { text-decoration: none; }
.ui-base .btn-primary, .ui-base .btn-success { background: var(--brand); color: #fff; }
.ui-base .btn-primary:hover, .ui-base .btn-success:hover { background: var(--brand-600); }
.ui-base .btn-danger { background: var(--error); color: #fff; }
.ui-base .btn-danger:hover { filter: brightness(1.07); }
.ui-base .btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.ui-base .btn-secondary:hover { background: var(--surface-2); }
.ui-base .btn-ghost { background: transparent; color: var(--text-2); }
.ui-base .btn-ghost:hover { background: rgba(255,255,255,.12); }
.ui-base .btn-warning { background: var(--warning); color: #fff; }
.ui-base .btn-sm { padding: 6px 10px; font-size: var(--fs-sm); }
.ui-base .btn-lg { padding: 12px 22px; font-size: var(--fs-md); }
.ui-base .btn-block { width: 100%; }
.ui-base .btn:focus-visible { outline: none; box-shadow: var(--ring); }

/* Cards / stats */
.ui-base .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--sh-sm); padding: var(--sp-6); margin-bottom: var(--sp-5); }
.ui-base .card__title { font-size: var(--fs-lg); font-weight: 700; margin: 0 0 var(--sp-4); }
.ui-base .card-grid { display: grid; gap: var(--sp-5); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.ui-base .stat-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.ui-base .stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-5); box-shadow: var(--sh-sm); }
.ui-base .stat__value { font-size: var(--fs-2xl); font-weight: 800; color: var(--brand-600); line-height: 1.1; }
.ui-base .stat__label { font-size: var(--fs-sm); color: var(--text-2); margin-top: var(--sp-1); }

/* Forms */
.ui-base .field { margin-bottom: var(--sp-4); }
.ui-base .label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--text); margin-bottom: var(--sp-2); }
.ui-base .input, .ui-base .select, .ui-base .textarea { width: 100%; box-sizing: border-box; border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 10px 12px; font-family: var(--font); font-size: var(--fs-base); color: var(--text); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.ui-base .input:focus, .ui-base .select:focus, .ui-base .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.ui-base .input:disabled, .ui-base .input[readonly] { background: var(--surface-2); color: var(--text-2); cursor: not-allowed; }
.ui-base .field-hint { font-size: var(--fs-xs); color: var(--text-2); margin-top: var(--sp-1); }

/* Tables */
.ui-base .table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow: auto; box-shadow: var(--sh-sm); }
.ui-base .table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.ui-base .table thead th { text-align: left; background: var(--brand-tint); color: var(--brand-700); font-weight: 600; font-size: var(--fs-sm); padding: 12px 14px; border-bottom: 2px solid var(--brand-soft); white-space: nowrap; }
.ui-base .table tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
.ui-base .table tbody tr:last-child td { border-bottom: none; }
.ui-base .table tbody tr:hover { background: var(--surface-2); }
.ui-base .table .actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* Compact icon action buttons (table rows) */
.ui-base .act-btns { display: inline-flex; align-items: center; gap: 4px; }
.ui-base .act-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); border-radius: var(--r-sm); cursor: pointer; font-size: 13px; line-height: 1; transition: background .12s, color .12s, border-color .12s; }
.ui-base .act-btn:hover { background: var(--surface-2); color: var(--text); }
.ui-base .act-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.ui-base .act-btn--primary:hover { color: var(--brand-600); border-color: var(--brand); background: var(--brand-tint); }
.ui-base .act-btn--warn { color: var(--warning); }
.ui-base .act-btn--warn:hover { color: var(--warning); border-color: var(--warning); background: var(--warning-bg); }
.ui-base .act-btn--ok { color: var(--success); }
.ui-base .act-btn--ok:hover { color: var(--success); border-color: var(--success); background: var(--success-bg); }
.ui-base .act-btn--danger { color: var(--error); }
.ui-base .act-btn--danger:hover { color: var(--error); border-color: var(--error); background: var(--error-bg); }
.ui-base .act-btn:disabled { opacity: .4; cursor: not-allowed; }
.ui-base .act-btn:disabled:hover { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.ui-base .act-sep { width: 1px; height: 20px; background: var(--border-strong); margin: 0 4px; flex: 0 0 auto; }

/* Export dropdown (CSV / Excel / PDF) */
.ui-base .export-menu { position: relative; display: inline-block; }
.ui-base .export-menu__list { display: none; position: absolute; right: 0; top: calc(100% + 4px); z-index: 1200; min-width: 190px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r); box-shadow: var(--sh-lg); padding: 6px; }
.ui-base .export-menu__list.is-open { display: block; }
.ui-base .export-menu__item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: none; background: transparent; color: var(--text); font-family: var(--font); font-size: var(--fs-base); text-align: left; cursor: pointer; border-radius: var(--r-sm); }
.ui-base .export-menu__item:hover { background: var(--brand-tint); color: var(--brand-700); }
.ui-base .export-menu__item i { width: 16px; text-align: center; color: var(--text-2); }
.ui-base .export-menu__item:hover i { color: var(--brand-600); }

/* Per-column header filters (data-grid style) */
.ui-base .table thead .th-cell { display: flex; flex-direction: column; gap: 6px; min-width: 90px; }
.ui-base .table thead .th-label { font-weight: 600; }
.ui-base .th-input { width: 100%; box-sizing: border-box; height: 30px; padding: 4px 8px; font-size: var(--fs-sm); font-weight: 400; font-family: var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); }
.ui-base .th-input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.ui-base .th-search { display: inline-flex; align-items: center; gap: 6px; }
.ui-base .th-search-btn { border: none; background: transparent; cursor: pointer; color: var(--text-2); padding: 2px 4px; font-size: 13px; line-height: 1; border-radius: var(--r-sm); }
.ui-base .th-search-btn:hover, .ui-base .th-search-btn.is-active { color: var(--brand-600); }
.ui-base .th-sortable { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.ui-base .th-sort-icon { font-size: 12px; color: var(--text-3); }
.ui-base .th-sortable:hover .th-sort-icon, .ui-base .th-sortable.is-sorted .th-sort-icon { color: var(--brand-600); }

/* Badges / status pills */
.ui-base .badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 600; line-height: 1.4; }
.ui-base .badge-active, .ui-base .badge-completed, .ui-base .badge-connected, .ui-base .status-active, .ui-base .status-completed { background: var(--success-bg); color: var(--success); }
.ui-base .badge-inactive, .ui-base .badge-failed, .ui-base .badge-disconnected, .ui-base .status-inactive, .ui-base .status-failed { background: var(--error-bg); color: var(--error); }
.ui-base .badge-pending, .ui-base .status-pending { background: var(--warning-bg); color: var(--warning); }
.ui-base .badge-running, .ui-base .status-running { background: var(--info-bg); color: var(--info); }
.ui-base .badge-neutral { background: var(--surface-2); color: var(--text-2); }

/* Tabs */
.ui-base .tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); }
.ui-base .tabs button { background: none; border: none; cursor: pointer; padding: 10px 16px; font-size: var(--fs-base); font-weight: 600; color: var(--text-2); border-bottom: 2px solid transparent; }
.ui-base .tabs button.is-active { color: var(--brand-600); border-bottom-color: var(--brand); }

/* Pagination */
.ui-base .pagination { display: flex; align-items: center; gap: var(--sp-3); justify-content: center; margin-top: var(--sp-5); }
.ui-base .pagination button { border: 1px solid var(--brand); background: var(--surface); color: var(--brand-600); padding: 8px 16px; border-radius: var(--r-sm); cursor: pointer; font-weight: 600; }
.ui-base .pagination button:hover:not(:disabled) { background: var(--brand); color: #fff; }
.ui-base .pagination button:disabled { opacity: .5; cursor: not-allowed; border-color: var(--border-strong); color: var(--text-3); }

/* Empty / skeleton / progress */
.ui-base .empty-state { text-align: center; padding: var(--sp-10) var(--sp-5); color: var(--text-2); }
.ui-base .empty-state__icon { font-size: 40px; color: var(--text-3); margin-bottom: var(--sp-3); }

/* Icon colour utilities — tint Font Awesome icons with system tokens.
   Use instead of emoji so glyphs stay on-brand and theme-aware. */
.ui-base .ic-brand   { color: var(--brand); }
.ui-base .ic-success { color: var(--success); }
.ui-base .ic-danger  { color: var(--error); }
.ui-base .ic-warn    { color: var(--warning); }
.ui-base .ic-info    { color: var(--info); }
.ui-base .ic-muted   { color: var(--text-3); }
.ui-base .empty-state__title { font-size: var(--fs-md); font-weight: 600; color: var(--text); margin-bottom: var(--sp-2); }
.ui-base .skeleton { background: linear-gradient(90deg, #eef2f6 25%, #e2e8f0 37%, #eef2f6 63%); background-size: 400% 100%; animation: ui-shimmer 1.3s ease infinite; border-radius: var(--r-sm); height: 14px; }
@keyframes ui-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.ui-base .progress { height: 8px; background: var(--border); border-radius: var(--r-full); overflow: hidden; }
.ui-base .progress__bar { height: 100%; background: var(--brand); border-radius: var(--r-full); transition: width .4s ease; }

/* Page modals */
.ui-base .modal-backdrop { position: fixed; inset: 0; z-index: 5000; display: none; align-items: center; justify-content: center; background: rgba(15,23,42,.5); padding: var(--sp-5); }
.ui-base .modal-backdrop.is-open { display: flex; }
.ui-base .modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-lg); width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: var(--sp-6); animation: ui-pop .15s ease; }
.ui-base .modal__title { font-size: var(--fs-lg); font-family: var(--font-display); font-weight: 800; margin: 0 0 var(--sp-4); }
.ui-base .modal__actions { display: flex; gap: var(--sp-3); justify-content: flex-end; margin-top: var(--sp-5); }

.ui-base button:focus-visible, .ui-base a:focus-visible, .ui-base input:focus-visible, .ui-base select:focus-visible, .ui-base textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* Auth pages (login / register / password recovery) — body.ui-base.auth */
body.ui-base.auth { background: linear-gradient(135deg, var(--brand) 0%, var(--navy) 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp-5); }
.ui-base .auth-card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-lg); padding: 40px; width: 100%; max-width: 440px; }
.ui-base .auth-logo { text-align: center; margin-bottom: var(--sp-6); }
.ui-base .auth-logo img { height: 64px; width: auto; margin-bottom: var(--sp-3); }
.ui-base .auth-title { text-align: center; font-size: var(--fs-2xl); margin: 0 0 var(--sp-2); }
.ui-base .auth-subtitle { text-align: center; color: var(--text-2); font-size: var(--fs-base); margin: 0 0 var(--sp-6); }
.ui-base .auth-footer { text-align: center; margin-top: var(--sp-5); padding-top: var(--sp-5); border-top: 1px solid var(--border); }
.ui-base .auth-footer a { display: inline-block; margin: 4px 0; font-size: var(--fs-base); }
.ui-base .auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--text-3); font-size: var(--fs-sm); }
.ui-base .auth-divider::before, .ui-base .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.ui-base .social-btn { justify-content: center; }
.ui-base .social-btn i { margin-right: 8px; }

/* =========================================================================
 * PAGE HELPERS — utilities + components used by migrated pages
 * (scoped under .ui-base so un-migrated pages are unaffected)
 * ========================================================================= */

/* Utilities */
.ui-base .hidden { display: none !important; }
.ui-base .muted, .ui-base .text-muted { color: var(--text-2); }
.ui-base .mono { font-family: 'Courier New', monospace; }
.ui-base .grid { display: grid; gap: var(--sp-4); }
.ui-base .grid-cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.ui-base .stats-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.ui-base .table-container { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow: auto; box-shadow: var(--sh-sm); }
.ui-base .actions-cell { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.ui-base .tab-content { display: none; }
.ui-base .tab-content.is-active, .ui-base .tab-content.active { display: block; }
.ui-base .btn-info { background: var(--info); color: #fff; }
.ui-base .btn-info:hover { filter: brightness(1.07); }
.ui-base .btn-test { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.ui-base .btn-test:hover { background: var(--surface-2); }

/* Toolbars / filters / forms */
.ui-base .filters { display: flex; gap: var(--sp-4); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--sp-5); }
.ui-base .form-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.ui-base .form-row { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.ui-base .form-row > * { flex: 1 1 220px; }
.ui-base .form-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-5); flex-wrap: wrap; }

/* Dashboard company cards + sync history */
.ui-base .company-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.ui-base .company-name { font-size: var(--fs-lg); font-weight: 700; color: var(--text); }
.ui-base .sync-form { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: flex-end; margin-bottom: var(--sp-4); }
.ui-base .job-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.ui-base .job-list__title { font-size: var(--fs-sm); font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; margin: var(--sp-3) 0 var(--sp-2); }
.ui-base .job-item { border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--sp-3) var(--sp-4); background: var(--surface-2); }
.ui-base .job-item-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.ui-base .job-item-details { font-size: var(--fs-sm); color: var(--text-2); margin-top: var(--sp-1); }
.ui-base .results-pre { background: var(--navy); color: #e2e8f0; border-radius: var(--r-sm); padding: var(--sp-3); font-family: 'Courier New', monospace; font-size: var(--fs-sm); overflow: auto; white-space: pre-wrap; }
.ui-base .results-pre--error { background: #450a0a; color: #fecaca; }

/* Email provider cards */
.ui-base .provider-grid, .ui-base .provider-selection { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.ui-base .provider-card { border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-5); background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.ui-base .provider-card:hover { border-color: var(--brand); box-shadow: var(--sh-md); }
.ui-base .provider-card.is-selected, .ui-base .provider-card.selected { border-color: var(--brand); box-shadow: var(--ring); }

/* OTP / verification code inputs */
.ui-base .verification-code { display: flex; gap: var(--sp-3); justify-content: center; }
.ui-base .code-input { width: 52px; height: 56px; text-align: center; font-size: var(--fs-xl); font-weight: 700; border: 1px solid var(--border-strong); border-radius: var(--r-sm); }
.ui-base .code-input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }

/* Audit timeline */
.ui-base .timeline { position: relative; padding-left: 40px; }
.ui-base .timeline::before { content: ''; position: absolute; left: 15px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.ui-base .timeline-item { position: relative; padding: var(--sp-4); margin-bottom: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); border-left: 4px solid var(--brand); }
.ui-base .timeline-item::before { content: ''; position: absolute; left: -28px; top: 20px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); border: 3px solid #fff; }
.ui-base .timeline-item.type-error::before { background: var(--error); }
.ui-base .timeline-item.type-warning::before { background: var(--warning); }
.ui-base .timeline-item.type-success::before { background: var(--success); }
.ui-base .timeline-header { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.ui-base .timeline-title { font-weight: 600; color: var(--text); }
.ui-base .timeline-time { color: var(--text-2); font-size: var(--fs-xs); }
.ui-base .timeline-details { color: var(--text-2); font-size: var(--fs-base); }
.ui-base .timeline-meta { display: flex; gap: var(--sp-4); margin-top: var(--sp-2); font-size: var(--fs-xs); color: var(--text-3); flex-wrap: wrap; }
.ui-base .action-badge { display: inline-block; padding: 4px 12px; border-radius: var(--r-full); font-size: 11px; font-weight: 600; margin-right: 5px; background: var(--surface-2); color: var(--text-2); }
.ui-base .action-login, .ui-base .action-create { background: var(--success-bg); color: var(--success); }
.ui-base .action-logout, .ui-base .action-delete { background: var(--error-bg); color: var(--error); }
.ui-base .action-sync { background: var(--info-bg); color: var(--info); }
.ui-base .action-update { background: var(--warning-bg); color: var(--warning); }

/* Compact audit list — one row per event, details behind the "i" toggle */
.ui-base .audit-list { display: flex; flex-direction: column; }
.ui-base .audit-item { border-bottom: 1px solid var(--border); }
.ui-base .audit-item:first-child { border-top: 1px solid var(--border); }
.ui-base .audit-row { display: flex; align-items: center; gap: var(--sp-2); padding: 7px var(--sp-2); font-size: var(--fs-sm); }
.ui-base .audit-item.open .audit-row { background: var(--surface-2); }
.ui-base .audit-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.ui-base .audit-item.type-error .audit-dot { background: var(--error); }
.ui-base .audit-item.type-warning .audit-dot { background: var(--warning); }
.ui-base .audit-item.type-success .audit-dot { background: var(--success); }
.ui-base .audit-row .action-badge { flex: none; margin-right: 0; padding: 2px 9px; }
.ui-base .audit-user { flex: none; font-weight: 600; color: var(--text); white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.ui-base .audit-summary { flex: 1 1 auto; min-width: 0; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-base .audit-time { flex: none; color: var(--text-3); font-size: var(--fs-xs); white-space: nowrap; }
.ui-base .audit-info { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); color: var(--text-3); cursor: pointer; transition: color .12s, border-color .12s, background .12s; }
.ui-base .audit-info:hover { color: var(--brand); border-color: var(--brand); }
.ui-base .audit-item.open .audit-info { color: var(--brand); border-color: var(--brand); background: var(--brand-bg, var(--surface-2)); }
.ui-base .audit-detail { padding: var(--sp-3) var(--sp-3) var(--sp-3) 34px; background: var(--surface-2); font-size: var(--fs-sm); }
.ui-base .audit-detail-row { display: flex; gap: var(--sp-3); padding: 3px 0; align-items: baseline; }
.ui-base .audit-detail-label { flex: none; width: 120px; color: var(--text-3); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .03em; }
.ui-base .audit-detail-value { flex: 1 1 auto; min-width: 0; color: var(--text); word-break: break-word; }
.ui-base .audit-detail-raw { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: var(--fs-xs); color: var(--text-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--sp-2); max-height: 220px; overflow: auto; }
@media (max-width: 640px) {
    .ui-base .audit-user { max-width: 120px; }
    .ui-base .audit-detail-row { flex-direction: column; gap: 2px; }
    .ui-base .audit-detail-label { width: auto; }
}

/* Generic single-word helpers (kept minimal + scoped) */
.ui-base .loading { text-align: center; color: var(--text-2); padding: var(--sp-5); }
.ui-base .description, .ui-base .instructions { color: var(--text-2); font-size: var(--fs-sm); margin: var(--sp-2) 0; }
.ui-base .instructions { background: var(--info-bg); border-radius: var(--r-sm); padding: var(--sp-3) var(--sp-4); }
.ui-base .icon { display: inline-flex; align-items: center; color: var(--brand); }
.ui-base .name { font-weight: 600; color: var(--text); }
.ui-base .value { font-weight: 600; color: var(--text); }
