/* ============================================================
   INSURANCE SYSTEM — THEME ENGINE
   All colours, spacing, typography via CSS custom properties.
   Override any variable in Settings → Appearance to retheme.
   ============================================================ */

/* ── Default theme (overridden by user-saved theme in <html> style attr) ── */
:root {
  /* Brand colours */
  --primary:        #1a56db;
  --primary-light:  #e8f0fe;
  --primary-dark:   #1341b0;
  --secondary:      #0e9f6e;
  --secondary-light:#d5f5e3;
  --accent:         #ff5a1f;
  --accent-light:   #fde8e4;

  /* Surfaces */
  --bg-page:        #f0f4f8;
  --bg-card:        #ffffff;
  --bg-sidebar:     #1e2a3b;
  --bg-sidebar-dark:#131e2d;
  --bg-header:      #ffffff;

  /* Text */
  --text-base:      #111928;
  --text-muted:     #6b7280;
  --text-light:     #9ca3af;
  --text-inverse:   #ffffff;
  --text-sidebar:   #d1d5db;
  --text-sidebar-active: #ffffff;

  /* Borders */
  --border:         #e5e7eb;
  --border-strong:  #d1d5db;
  --border-focus:   var(--primary);

  /* Status colours */
  --success:        #0e9f6e;
  --success-bg:     #d5f5e3;
  --warning:        #c27803;
  --warning-bg:     #fef3c7;
  --danger:         #e02424;
  --danger-bg:      #fde8e8;
  --info:           #1c64f2;
  --info-bg:        #e1effe;

  /* Status pills */
  --status-active:       var(--success);
  --status-active-bg:    var(--success-bg);
  --status-pending:      var(--warning);
  --status-pending-bg:   var(--warning-bg);
  --status-cancelled:    var(--danger);
  --status-cancelled-bg: var(--danger-bg);
  --status-draft:        var(--text-muted);
  --status-draft-bg:     #f3f4f6;

  /* Typography */
  --font-body:      'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:      'JetBrains Mono', 'Fira Code', monospace;
  --font-size-xs:   0.75rem;
  --font-size-sm:   0.875rem;
  --font-size-base: 1rem;
  --font-size-lg:   1.125rem;
  --font-size-xl:   1.25rem;
  --font-size-2xl:  1.5rem;
  --font-size-3xl:  1.875rem;

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-sm:  0.25rem;
  --radius:     0.5rem;
  --radius-md:  0.625rem;
  --radius-lg:  0.75rem;
  --radius-xl:  1rem;
  --radius-full:9999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow:     0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg:  0 10px 15px rgba(0,0,0,0.10), 0 4px 6px rgba(0,0,0,0.05);

  /* Sidebar */
  --sidebar-width:        260px;
  --sidebar-collapsed:     64px;

  /* Transitions */
  --transition:     0.15s ease;
  --transition-md:  0.25s ease;
}

/* ── Preset themes ─────────────────────────────────────────── */
[data-theme="ocean"] {
  --primary:       #0077b6;
  --primary-light: #caf0f8;
  --primary-dark:  #005f8e;
  --secondary:     #00b4d8;
  --bg-sidebar:    #03045e;
  --bg-sidebar-dark:#02033d;
}
[data-theme="forest"] {
  --primary:       #2d6a4f;
  --primary-light: #d8f3dc;
  --primary-dark:  #1b4332;
  --secondary:     #52b788;
  --bg-sidebar:    #1b4332;
  --bg-sidebar-dark:#0d2218;
}
[data-theme="sunset"] {
  --primary:       #c1121f;
  --primary-light: #ffdde1;
  --primary-dark:  #8b0000;
  --secondary:     #e76f51;
  --bg-sidebar:    #3d0c11;
  --bg-sidebar-dark:#1f0608;
}
[data-theme="royal"] {
  --primary:       #6a0dad;
  --primary-light: #ede0f7;
  --primary-dark:  #4b0082;
  --secondary:     #9b59b6;
  --bg-sidebar:    #2d0040;
  --bg-sidebar-dark:#1a0026;
}
[data-theme="slate"] {
  --primary:       #334155;
  --primary-light: #e2e8f0;
  --primary-dark:  #1e293b;
  --secondary:     #64748b;
  --bg-sidebar:    #0f172a;
  --bg-sidebar-dark:#080d1a;
}

/* ── Dark mode ─────────────────────────────────────────────── */
[data-mode="dark"] {
  --bg-page:      #0f172a;
  --bg-card:      #1e293b;
  --bg-header:    #1e293b;
  --text-base:    #f1f5f9;
  --text-muted:   #94a3b8;
  --text-light:   #64748b;
  --border:       #334155;
  --border-strong:#475569;
  --shadow-sm:    0 1px 2px rgba(0,0,0,0.3);
  --shadow:       0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:    0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg:    0 10px 15px rgba(0,0,0,0.5);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  color: var(--text-base);
  background: var(--bg-page);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; height: auto; }
ul { list-style: none; }

/* ============================================================
   LAYOUT
   ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width var(--transition-md);
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .nav-group-label,
.sidebar.collapsed .nav-badge { display: none; }
.sidebar.collapsed .nav-item-link { justify-content: center; padding: 0.75rem; }
.sidebar.collapsed .sidebar-brand { justify-content: center; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  min-height: 72px;
}
.sidebar-brand-logo {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-weight: 700; color: #fff; font-size: 1rem;
}
.sidebar-brand-text { overflow: hidden; }
.sidebar-brand-name {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--text-inverse);
  white-space: nowrap;
  line-height: 1.2;
}
.sidebar-brand-sub {
  font-size: var(--font-size-xs);
  color: rgba(255,255,255,0.45);
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-4) 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.nav-group { margin-bottom: var(--space-2); }
.nav-group-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.35);
  padding: var(--space-3) var(--space-4) var(--space-1);
}
.nav-item-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.6rem var(--space-4);
  color: var(--text-sidebar);
  font-size: var(--font-size-sm);
  font-weight: 450;
  transition: all var(--transition);
  position: relative;
  white-space: nowrap;
  border-radius: 0;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}
.nav-item-link.active {
  background: rgba(255,255,255,0.10);
  color: var(--text-sidebar-active);
  font-weight: 500;
}
.nav-item-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}
.nav-icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-item-link.active .nav-icon,
.nav-item-link:hover .nav-icon { opacity: 1; }
.nav-badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}

/* Sub-nav (collapsible) */
.nav-has-sub .nav-sub { display: none; }
.nav-has-sub.open .nav-sub { display: block; }
.nav-sub .nav-item-link {
  padding-left: calc(var(--space-4) + 28px);
  font-size: var(--font-size-xs);
}
.nav-chevron {
  margin-left: auto;
  transition: transform var(--transition);
  opacity: 0.5;
  font-size: 12px;
}
.nav-has-sub.open .nav-chevron { transform: rotate(90deg); }

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
}
.sidebar-user:hover { background: rgba(255,255,255,0.06); }
.user-avatar {
  width: 34px; height: 34px;
  border-radius: var(--radius-full);
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: var(--font-size-sm);
  flex-shrink: 0;
}
.user-info { overflow: hidden; }
.user-name {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: var(--font-size-xs);
  color: rgba(255,255,255,0.45);
  white-space: nowrap;
}

/* ── Main content ──────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left var(--transition-md);
}
.main-content.sidebar-collapsed { margin-left: var(--sidebar-collapsed); }

/* ── Top header ────────────────────────────────────────────── */
.top-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-6);
  height: 64px;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.header-toggle {
  background: none; border: none; cursor: pointer;
  padding: var(--space-2);
  color: var(--text-muted);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.header-toggle:hover { background: var(--primary-light); color: var(--primary); }

.header-search {
  flex: 1;
  max-width: 400px;
  position: relative;
}
.header-search input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.5rem;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  color: var(--text-base);
  transition: all var(--transition);
  outline: none;
}
.header-search input:focus {
  border-color: var(--border-focus);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.15);
}
.header-search-icon {
  position: absolute;
  left: 0.75rem; top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}

.header-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.header-btn {
  background: none; border: none; cursor: pointer;
  padding: var(--space-2);
  color: var(--text-muted);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: all var(--transition);
}
.header-btn:hover { background: var(--primary-light); color: var(--primary); }
.header-notification-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 8px; height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg-header);
}
.header-divider {
  width: 1px; height: 28px;
  background: var(--border);
}

/* Page content area */
.page-content {
  flex: 1;
  padding: var(--space-6);
}

/* ── Page header ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.page-title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-base);
  line-height: 1.2;
}
.page-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.breadcrumb-sep { opacity: 0.4; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  gap: var(--space-4);
  flex-wrap: wrap;
}
.card-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-base);
}
.card-subtitle {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.card-body { padding: var(--space-6); }
.card-body-sm { padding: var(--space-4); }
.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-page);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Stat cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 1.25rem;
}
.stat-icon.primary   { background: var(--primary-light); color: var(--primary); }
.stat-icon.success   { background: var(--success-bg); color: var(--success); }
.stat-icon.warning   { background: var(--warning-bg); color: var(--warning); }
.stat-icon.danger    { background: var(--danger-bg); color: var(--danger); }
.stat-icon.info      { background: var(--info-bg); color: var(--info); }
.stat-info { min-width: 0; }
.stat-label {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}
.stat-value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-base);
  line-height: 1.2;
  margin-top: var(--space-1);
  font-variant-numeric: tabular-nums;
}
.stat-change {
  font-size: var(--font-size-xs);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ============================================================
   GRID SYSTEM
   ============================================================ */
.grid { display: grid; gap: var(--space-6); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-cols-7-5 { grid-template-columns: 7fr 5fr; }
.grid-cols-2-1 { grid-template-columns: 2fr 1fr; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: var(--space-5); }
.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-base);
  margin-bottom: var(--space-2);
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-hint {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}
.form-error {
  font-size: var(--font-size-xs);
  color: var(--danger);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.625rem var(--space-3);
  font-size: var(--font-size-sm);
  font-family: var(--font-body);
  color: var(--text-base);
  background: var(--bg-card);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  transition: all var(--transition);
  outline: none;
  line-height: 1.5;
}
.form-control:hover { border-color: var(--primary); }
.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.15);
}
.form-control:disabled {
  background: var(--bg-page);
  cursor: not-allowed;
  opacity: 0.6;
}
.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(224,36,36,0.15); }
.form-control.is-valid { border-color: var(--success); }

.form-control-sm { padding: 0.4rem var(--space-3); font-size: var(--font-size-xs); }
.form-control-lg { padding: 0.75rem var(--space-4); font-size: var(--font-size-base); }

textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.5rem center; background-size: 1.25rem; padding-right: 2.5rem; }

/* Input group */
.input-group {
  display: flex;
  align-items: stretch;
}
.input-group .form-control {
  border-radius: 0;
  flex: 1;
}
.input-group .form-control:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .form-control:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.input-group-text {
  display: flex;
  align-items: center;
  padding: 0.625rem var(--space-3);
  background: var(--bg-page);
  border: 1.5px solid var(--border-strong);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  white-space: nowrap;
}
.input-group-text:first-child { border-right: none; border-radius: var(--radius) 0 0 var(--radius); }
.input-group-text:last-child  { border-left: none;  border-radius: 0 var(--radius) var(--radius) 0; }

/* Checkbox & Radio */
.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}
.form-check-label {
  font-size: var(--font-size-sm);
  color: var(--text-base);
}

/* Form row */
.form-row { display: grid; gap: var(--space-4); }
.form-row-2 { grid-template-columns: repeat(2, 1fr); }
.form-row-3 { grid-template-columns: repeat(3, 1fr); }
.form-row-4 { grid-template-columns: repeat(4, 1fr); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.575rem var(--space-4);
  font-size: var(--font-size-sm);
  font-family: var(--font-body);
  font-weight: 500;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
  line-height: 1.5;
}
.btn:disabled, .btn.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: #fff; border-color: var(--secondary); }
.btn-secondary:hover { filter: brightness(0.9); }
.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { filter: brightness(0.9); }
.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(0.9); }
.btn-warning   { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover { filter: brightness(0.9); }
.btn-info      { background: var(--info); color: #fff; border-color: var(--info); }

.btn-outline-primary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: #fff; }
.btn-outline-secondary { background: transparent; color: var(--text-muted); border-color: var(--border-strong); }
.btn-outline-secondary:hover { background: var(--bg-page); color: var(--text-base); }
.btn-outline-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); color: #fff; }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--primary-light); color: var(--primary); }

.btn-sm { padding: 0.35rem var(--space-3); font-size: var(--font-size-xs); }
.btn-lg { padding: 0.75rem var(--space-6); font-size: var(--font-size-base); }
.btn-block { width: 100%; }
.btn-icon { padding: 0.5rem; }

/* Button group */
.btn-group { display: flex; }
.btn-group .btn { border-radius: 0; border-right-width: 0; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.btn-group .btn:last-child  { border-radius: 0 var(--radius) var(--radius) 0; border-right-width: 1.5px; }

/* ============================================================
   TABLES
   ============================================================ */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}
.table th {
  background: var(--bg-page);
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-base);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--primary-light); }
.table-sm th, .table-sm td { padding: var(--space-2) var(--space-3); }

/* ============================================================
   BADGES & STATUS PILLS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 500;
  white-space: nowrap;
}
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-primary   { background: var(--primary-light); color: var(--primary); }
.badge-success   { background: var(--success-bg); color: var(--success); }
.badge-warning   { background: var(--warning-bg); color: var(--warning); }
.badge-danger    { background: var(--danger-bg); color: var(--danger); }
.badge-info      { background: var(--info-bg); color: var(--info); }
.badge-secondary { background: #f3f4f6; color: var(--text-muted); }

/* Policy/claim status */
.status-active      { background: var(--status-active-bg);    color: var(--status-active); }
.status-pending     { background: var(--status-pending-bg);   color: var(--status-pending); }
.status-cancelled   { background: var(--status-cancelled-bg); color: var(--status-cancelled); }
.status-draft       { background: var(--status-draft-bg);     color: var(--status-draft); }
.status-lapsed      { background: #fef3c7; color: #92400e; }
.status-expired     { background: #f3f4f6; color: #6b7280; }
.status-reinstated  { background: #e0e7ff; color: #4338ca; }
.status-approved    { background: var(--success-bg); color: var(--success); }
.status-rejected    { background: var(--danger-bg); color: var(--danger); }
.status-paid        { background: var(--success-bg); color: var(--success); }
.status-closed      { background: #f3f4f6; color: #6b7280; }

/* ============================================================
   TABS
   ============================================================ */
.tabs { border-bottom: 1px solid var(--border); margin-bottom: var(--space-6); display: flex; gap: 0; }
.tab-item {
  padding: var(--space-3) var(--space-5);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.tab-item:hover { color: var(--primary); }
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
}
.pagination-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-base);
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
}
.pagination-btn:hover { border-color: var(--primary); color: var(--primary); }
.pagination-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #fcd34d; }
.alert-danger  { background: var(--danger-bg);  color: var(--danger);  border-color: #fca5a5; }
.alert-info    { background: var(--info-bg);    color: var(--info);    border-color: #93c5fd; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0; visibility: hidden;
  transition: all var(--transition-md);
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95) translateY(8px);
  transition: transform var(--transition-md);
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal-sm  { max-width: 420px; }
.modal-md  { max-width: 600px; }
.modal-lg  { max-width: 800px; }
.modal-xl  { max-width: 1100px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: var(--font-size-lg); font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  display: flex;
}
.modal-close:hover { background: var(--danger-bg); color: var(--danger); }
.modal-body { padding: var(--space-6); overflow-y: auto; flex: 1; }
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ============================================================
   DROPDOWNS
   ============================================================ */
.dropdown { position: relative; display: inline-flex; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  z-index: 150;
  opacity: 0; visibility: hidden;
  transform: translateY(-4px);
  transition: all var(--transition);
  padding: var(--space-1) 0;
}
.dropdown.open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--text-base);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.dropdown-item:hover { background: var(--primary-light); color: var(--primary); }
.dropdown-item.danger:hover { background: var(--danger-bg); color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: var(--space-1) 0; }

/* ============================================================
   TOASTS / NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
  min-width: 280px;
  max-width: 380px;
  pointer-events: all;
  animation: slideInToast 0.3s ease forwards;
}
@keyframes slideInToast {
  from { opacity: 0; transform: translateX(100%); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast-success { border-left: 4px solid var(--success); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-danger  { border-left: 4px solid var(--danger); }
.toast-info    { border-left: 4px solid var(--info); }

/* ============================================================
   FILTERS / TOOLBAR
   ============================================================ */
.table-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar-search {
  flex: 1;
  min-width: 200px;
  max-width: 320px;
  position: relative;
}
.toolbar-search input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.25rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
  background: var(--bg-page);
  color: var(--text-base);
  outline: none;
  transition: all var(--transition);
}
.toolbar-search input:focus { border-color: var(--border-focus); background: var(--bg-card); }
.toolbar-search-icon {
  position: absolute;
  left: 0.625rem; top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}
.toolbar-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }

/* ============================================================
   MISC UTILITIES
   ============================================================ */
.d-flex  { display: flex; }
.d-grid  { display: grid; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fs-xs  { font-size: var(--font-size-xs); }
.fs-sm  { font-size: var(--font-size-sm); }
.fs-lg  { font-size: var(--font-size-lg); }
.mt-4   { margin-top: var(--space-4); }
.mb-4   { margin-bottom: var(--space-4); }
.mb-6   { margin-bottom: var(--space-6); }
.p-4    { padding: var(--space-4); }
.mono   { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.separator {
  height: 1px;
  background: var(--border);
  margin: var(--space-6) 0;
}
.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: var(--space-4); opacity: 0.3; }
.empty-state-title { font-size: var(--font-size-lg); font-weight: 600; color: var(--text-base); margin-bottom: var(--space-2); }

/* Loading spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   THEME PICKER (Settings Page)
   ============================================================ */
.theme-swatches {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.theme-swatch {
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  cursor: pointer;
  border: 3px solid transparent;
  transition: all var(--transition);
  position: relative;
}
.theme-swatch:hover, .theme-swatch.active {
  border-color: var(--text-base);
  transform: scale(1.1);
}
.theme-swatch.active::after {
  content: '✓';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* Custom colour sliders */
.color-picker-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.color-picker-row label {
  width: 130px;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  flex-shrink: 0;
}
.color-picker-row input[type="color"] {
  width: 44px; height: 34px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: var(--bg-card);
}
.color-picker-row .color-hex {
  font-size: var(--font-size-sm);
  font-family: var(--font-mono);
  color: var(--text-muted);
  width: 80px;
}

/* Font size control */
.font-size-control {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.font-size-preview {
  flex: 1;
  font-size: var(--font-size-base);
  color: var(--text-muted);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-5 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 992px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-7-5 { grid-template-columns: 1fr; }
  .grid-cols-2-1 { grid-template-columns: 1fr; }
  .form-row-4 { grid-template-columns: repeat(2, 1fr); }
  .form-row-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition-md), width var(--transition-md);
  }
  .sidebar.mobile-open { transform: translateX(0); width: var(--sidebar-width); }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }
  .sidebar-overlay.active { display: block; }
  .main-content { margin-left: 0 !important; }
  .page-content { padding: var(--space-4); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-row-2, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-search { max-width: 100%; }
  .toolbar-actions { margin-left: 0; }
  .stat-card { padding: var(--space-4); }
  .card-header { padding: var(--space-4); }
  .card-body  { padding: var(--space-4); }
  .modal { margin: 0; max-height: 100vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .toast-container { left: var(--space-4); right: var(--space-4); top: auto; bottom: var(--space-6); }
  .toast { min-width: auto; max-width: 100%; }
}
@media (max-width: 480px) {
  .btn-group { flex-direction: column; }
  .btn-group .btn { border-radius: var(--radius); border: 1.5px solid transparent; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .sidebar, .top-header, .btn, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page-content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
