/* Sentinel Dashboard — Dark theme, GitHub-inspired
   Premium design system v2.0
   ─────────────────────────────────────────────── */

/* ═══════════════════════════════════════════════
   1. DESIGN TOKENS (CSS Custom Properties)
   ═══════════════════════════════════════════════ */
:root {
  /* Background layers (darkest → lightest) */
  --bg-canvas: #0d1117;
  --bg-default: #161b22;
  --bg-subtle: #1c2128;
  --bg-inset: #010409;
  --bg-overlay: #1c2128;
  --bg-backdrop: rgba(1, 4, 9, 0.7);

  /* Borders */
  --border-default: #30363d;
  --border-muted: #21262d;
  --border-subtle: rgba(240, 246, 252, 0.1);

  /* Foreground / text */
  --fg-default: #e6edf3;
  --fg-muted: #8b949e;
  --fg-subtle: #6e7681;
  --fg-on-emphasis: #ffffff;

  /* Accent (blue) */
  --accent-fg: #58a6ff;
  --accent-emphasis: #1f6feb;
  --accent-muted: rgba(56, 139, 253, 0.4);
  --accent-subtle: rgba(56, 139, 253, 0.15);

  /* Semantic: success (green) */
  --success-fg: #3fb950;
  --success-emphasis: #238636;
  --success-muted: rgba(63, 185, 80, 0.4);
  --success-subtle: rgba(46, 160, 67, 0.15);

  /* Semantic: danger (red) */
  --danger-fg: #f85149;
  --danger-emphasis: #da3633;
  --danger-muted: rgba(248, 81, 73, 0.4);
  --danger-subtle: rgba(248, 81, 73, 0.15);

  /* Semantic: warning (amber) */
  --warning-fg: #d29922;
  --warning-emphasis: #9e6a03;
  --warning-muted: rgba(210, 153, 34, 0.4);
  --warning-subtle: rgba(210, 153, 34, 0.15);

  /* Semantic: info (blue alias) */
  --info-fg: #58a6ff;
  --info-emphasis: #1f6feb;
  --info-muted: rgba(88, 166, 255, 0.4);
  --info-subtle: rgba(56, 139, 253, 0.15);

  /* Semantic: purple */
  --done-fg: #a371f7;
  --done-emphasis: #8957e5;
  --done-muted: rgba(163, 113, 247, 0.4);
  --done-subtle: rgba(163, 113, 247, 0.15);

  /* Layout */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-md: 0 3px 6px rgba(0, 0, 0, 0.15), 0 8px 24px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.25), 0 16px 48px rgba(0, 0, 0, 0.3);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.03);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --text-xs: 0.6875rem;   /* 11px */
  --text-sm: 0.75rem;     /* 12px */
  --text-base: 0.875rem;  /* 14px */
  --text-md: 1rem;        /* 16px */
  --text-lg: 1.25rem;     /* 20px */
  --text-xl: 1.5rem;      /* 24px */
  --text-2xl: 2rem;       /* 32px */
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Spacing scale (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;

  /* Z-index scale */
  --z-dropdown: 50;
  --z-sticky: 60;
  --z-sidebar: 100;
  --z-overlay: 200;
  --z-modal: 300;
  --z-toast: 400;
  --z-progress: 500;

  /* Sidebar width */
  --sidebar-width: 260px;
}


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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-canvas);
  color: var(--fg-default);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}

a {
  color: var(--accent-fg);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { text-decoration: underline; }

img, svg { vertical-align: middle; }

::selection {
  background: var(--accent-muted);
  color: var(--fg-on-emphasis);
}

/* Scrollbar styling (webkit) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-subtle); }

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}


/* ═══════════════════════════════════════════════
   3. TYPOGRAPHY
   ═══════════════════════════════════════════════ */
h1, h2, h3, h4, h5, h6 {
  color: var(--fg-default);
  font-weight: 600;
  line-height: var(--leading-tight);
}

h1 { font-size: var(--text-xl); letter-spacing: -0.025em; }
h2 { font-size: var(--text-md); }
h3 { font-size: var(--text-base); }
h4 { font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.05em; }

p { line-height: var(--leading-relaxed); }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

code {
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--fg-default);
}

pre {
  background: var(--bg-inset);
  padding: var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border-muted);
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
}

small { font-size: var(--text-sm); color: var(--fg-muted); }

hr {
  border: none;
  border-top: 1px solid var(--border-muted);
  margin: var(--space-6) 0;
}


/* ═══════════════════════════════════════════════
   4. LAYOUT — Shell, Sidebar, Main
   ═══════════════════════════════════════════════ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-default);
  border-right: 1px solid var(--border-default);
  padding: var(--space-4) 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: var(--z-sidebar);
  transition: transform var(--transition-slow);
}

.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: var(--space-8);
  max-width: 1200px;
  min-height: 100vh;
}

/* Sidebar Logo */
.sidebar-logo {
  padding: var(--space-2) var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: var(--fg-default);
  border-bottom: 1px solid var(--border-default);
  margin-bottom: var(--space-2);
  letter-spacing: -0.01em;
}
.sidebar-logo svg { flex-shrink: 0; opacity: 0.9; }

/* Sidebar Navigation */
.nav-section {
  padding: var(--space-2) 0;
}
.nav-section-title {
  padding: var(--space-1) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-4);
  color: var(--fg-muted);
  font-size: var(--text-base);
  transition: background var(--transition-fast), color var(--transition-fast);
  cursor: pointer;
  border-radius: 0;
  position: relative;
}
.nav-item:hover {
  background: var(--bg-subtle);
  color: var(--fg-default);
  text-decoration: none;
}
.nav-item.active {
  background: var(--bg-subtle);
  color: var(--fg-default);
  font-weight: 500;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--accent-fg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.nav-item svg { opacity: 0.6; flex-shrink: 0; transition: opacity var(--transition-fast); }
.nav-item:hover svg { opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--danger-fg);
  color: var(--fg-on-emphasis);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  line-height: 1.5;
}

.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-default);
  background: var(--bg-default);
}
.sidebar-footer .org-name {
  font-weight: 500;
  color: var(--fg-default);
  font-size: 13px;
}
.sidebar-footer .org-plan {
  font-size: var(--text-sm);
  color: var(--fg-subtle);
}


/* ═══════════════════════════════════════════════
   5. PAGE HEADER
   ═══════════════════════════════════════════════ */
.page-header {
  margin-bottom: var(--space-6);
}
.page-header h1 {
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: var(--space-1);
  letter-spacing: -0.025em;
}
.page-header p {
  color: var(--fg-muted);
  font-size: var(--text-base);
}


/* ═══════════════════════════════════════════════
   6. CARDS
   ═══════════════════════════════════════════════ */
.card {
  background: var(--bg-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.card-interactive:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-muted);
}
.card-header h2 {
  font-size: var(--text-md);
  font-weight: 600;
}

.card-body {
  padding: var(--space-4);
}

.card-footer {
  padding-top: var(--space-3);
  margin-top: var(--space-3);
  border-top: 1px solid var(--border-muted);
}


/* ═══════════════════════════════════════════════
   7. STAT CARDS
   ═══════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--bg-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-base), transform var(--transition-base), box-shadow var(--transition-base);
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-emphasis), transparent);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.stat-card:hover::after { opacity: 1; }

.stat-card:hover {
  border-color: var(--accent-muted);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.stat-card .stat-label {
  font-size: var(--text-sm);
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
  font-weight: 500;
}

.stat-card .stat-value {
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.025em;
}

.stat-card .stat-sub {
  font-size: var(--text-sm);
  color: var(--fg-subtle);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Colored stat card variants */
.stat-card-success { border-left: 3px solid var(--success-fg); }
.stat-card-danger { border-left: 3px solid var(--danger-fg); }
.stat-card-warning { border-left: 3px solid var(--warning-fg); }
.stat-card-info { border-left: 3px solid var(--accent-fg); }


/* ═══════════════════════════════════════════════
   8. TABLES
   ═══════════════════════════════════════════════ */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
}

thead th {
  text-align: left;
  padding: 10px var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
  background: var(--bg-subtle);
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  z-index: 1;
}

thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

tbody td {
  padding: 10px var(--space-3);
  border-bottom: 1px solid var(--border-muted);
  vertical-align: middle;
  font-size: var(--text-base);
}

tbody tr {
  transition: background var(--transition-fast);
}

tbody tr:hover { background: rgba(177, 186, 196, 0.04); }
tbody tr:last-child td { border-bottom: none; }

/* Striped table variant */
.table-striped tbody tr:nth-child(even) { background: rgba(177, 186, 196, 0.02); }
.table-striped tbody tr:nth-child(even):hover { background: rgba(177, 186, 196, 0.06); }

/* Bordered table variant */
.table-bordered td,
.table-bordered th {
  border: 1px solid var(--border-muted);
}

/* Compact table variant */
.table-compact th,
.table-compact td {
  padding: 6px var(--space-2);
  font-size: var(--text-sm);
}

/* Clickable rows */
.table-clickable tbody tr {
  cursor: pointer;
}
.table-clickable tbody tr:active {
  background: rgba(177, 186, 196, 0.08);
}


/* ═══════════════════════════════════════════════
   9. BADGES / PILLS
   ═══════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
  transition: opacity var(--transition-fast);
}

.badge-success { background: var(--success-subtle); color: var(--success-fg); }
.badge-danger { background: var(--danger-subtle); color: var(--danger-fg); }
.badge-warning { background: var(--warning-subtle); color: var(--warning-fg); }
.badge-info { background: var(--info-subtle); color: var(--info-fg); }
.badge-muted { background: rgba(110, 118, 129, 0.15); color: var(--fg-muted); }
.badge-purple { background: var(--done-subtle); color: var(--done-fg); }

/* Badge with dot indicator */
.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Badge sizes */
.badge-sm { padding: 1px 6px; font-size: var(--text-xs); }
.badge-lg { padding: 4px 12px; font-size: var(--text-base); }

/* Outlined badge */
.badge-outline {
  background: transparent;
  border: 1px solid currentColor;
}

/* Tier-specific badges (used across the dashboard) */
.tier-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tier-elite { background: rgba(210, 153, 34, 0.15); color: var(--warning-fg); }
.tier-trusted { background: var(--success-subtle); color: var(--success-fg); }
.tier-established { background: var(--info-subtle); color: var(--info-fg); }
.tier-basic { background: rgba(139, 148, 158, 0.15); color: var(--fg-muted); }
.tier-untrusted { background: var(--danger-subtle); color: var(--danger-fg); }

/* Status-specific badges */
.status-active { background: var(--success-subtle); color: var(--success-fg); }
.status-frozen { background: var(--danger-subtle); color: var(--danger-fg); }
.status-pending { background: var(--warning-subtle); color: var(--warning-fg); }
.status-completed { background: var(--success-subtle); color: var(--success-fg); }
.status-rejected { background: var(--danger-subtle); color: var(--danger-fg); }
.status-failed { background: rgba(110, 118, 129, 0.15); color: var(--fg-muted); }


/* ═══════════════════════════════════════════════
   10. BUTTONS
   ═══════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 16px;
  font-size: var(--text-base);
  font-weight: 500;
  font-family: inherit;
  line-height: 20px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--fg-default);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: var(--shadow-inset);
}

.btn:hover {
  background: var(--border-muted);
  text-decoration: none;
}

.btn:active {
  background: var(--bg-canvas);
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-fg);
  outline-offset: 2px;
}

/* Primary button */
.btn-primary {
  background: var(--accent-emphasis);
  border-color: rgba(240, 246, 252, 0.1);
  color: var(--fg-on-emphasis);
  box-shadow: var(--shadow-inset), 0 1px 3px rgba(31, 111, 235, 0.3);
}
.btn-primary:hover {
  background: #388bfd;
  box-shadow: var(--shadow-inset), 0 2px 6px rgba(31, 111, 235, 0.4);
}
.btn-primary:active { background: #1a7af8; }

/* Secondary button — explicit variant of default */
.btn-secondary {
  background: var(--bg-subtle);
  border-color: var(--border-default);
  color: var(--fg-default);
}
.btn-secondary:hover { background: var(--border-muted); }

/* Danger button */
.btn-danger {
  background: transparent;
  border-color: var(--danger-muted);
  color: var(--danger-fg);
}
.btn-danger:hover {
  background: var(--danger-subtle);
  border-color: var(--danger-fg);
}
.btn-danger:active { background: rgba(248, 81, 73, 0.25); }

/* Danger filled */
.btn-danger-filled {
  background: var(--danger-emphasis);
  border-color: rgba(240, 246, 252, 0.1);
  color: var(--fg-on-emphasis);
}
.btn-danger-filled:hover { background: #f44; }

/* Success button */
.btn-success {
  background: transparent;
  border-color: var(--success-muted);
  color: var(--success-fg);
}
.btn-success:hover {
  background: var(--success-subtle);
  border-color: var(--success-fg);
}
.btn-success:active { background: rgba(63, 185, 80, 0.25); }

/* Ghost button (no border) */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fg-muted);
}
.btn-ghost:hover {
  background: var(--bg-subtle);
  color: var(--fg-default);
}

/* Link button */
.btn-link {
  background: transparent;
  border-color: transparent;
  color: var(--accent-fg);
  padding: 0;
  box-shadow: none;
}
.btn-link:hover { text-decoration: underline; }

/* Button sizes */
.btn-sm { padding: 3px 12px; font-size: var(--text-sm); line-height: 18px; }
.btn-lg { padding: 10px 24px; font-size: var(--text-md); line-height: 24px; }
.btn-icon { padding: 5px 8px; }
.btn-icon.btn-sm { padding: 3px 6px; }

/* Full width */
.btn-block { width: 100%; justify-content: center; }

/* Disabled */
.btn:disabled,
.btn[disabled],
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Loading state */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: calc(50% - 8px);
  left: calc(50% - 8px);
  border: 2px solid var(--border-default);
  border-top-color: var(--fg-on-emphasis);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn-primary.btn-loading::after {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
}

/* Button group */
.btn-group {
  display: flex;
  gap: var(--space-2);
}

.btn-group-attached {
  display: inline-flex;
  gap: 0;
}
.btn-group-attached .btn { border-radius: 0; margin-left: -1px; }
.btn-group-attached .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group-attached .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }


/* ═══════════════════════════════════════════════
   11. FORMS
   ═══════════════════════════════════════════════ */
.form-group {
  margin-bottom: var(--space-4);
}

.form-group label {
  display: block;
  font-size: var(--text-base);
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--fg-default);
}

.form-group .hint {
  font-size: var(--text-sm);
  color: var(--fg-subtle);
  margin-top: var(--space-1);
}

.form-group .error-msg {
  font-size: var(--text-sm);
  color: var(--danger-fg);
  margin-top: var(--space-1);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 6px 12px;
  font-size: var(--text-base);
  font-family: inherit;
  line-height: 20px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  color: var(--fg-default);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--fg-subtle);
  opacity: 1;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-fg);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

/* Error state */
input.input-error,
select.input-error,
textarea.input-error {
  border-color: var(--danger-fg);
}
input.input-error:focus,
select.input-error:focus,
textarea.input-error:focus {
  box-shadow: 0 0 0 3px var(--danger-muted);
}

/* Success state */
input.input-success:focus {
  border-color: var(--success-fg);
  box-shadow: 0 0 0 3px var(--success-muted);
}

/* Disabled */
input:disabled, select:disabled, textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-subtle);
}

/* Select dropdown arrow */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='%238b949e'%3E%3Cpath d='M6 8.825a.5.5 0 01-.354-.146l-3.5-3.5a.5.5 0 11.708-.708L6 7.617l3.146-3.146a.5.5 0 01.708.708l-3.5 3.5A.5.5 0 016 8.825z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

/* Textarea */
textarea {
  resize: vertical;
  min-height: 60px;
}

/* Checkbox / radio base */
input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  padding: 0;
  vertical-align: middle;
  accent-color: var(--accent-emphasis);
}

/* Form row (inline fields) */
.form-row {
  display: flex;
  gap: var(--space-4);
}
.form-row .form-group { flex: 1; }

/* Input with icon/addon */
.input-group {
  position: relative;
  display: flex;
}
.input-group input { flex: 1; }
.input-group-addon {
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--bg-subtle);
  border: 1px solid var(--border-default);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--fg-muted);
  font-size: var(--text-sm);
}
.input-group-addon + input {
  border-radius: 0 var(--radius) var(--radius) 0;
}


/* ═══════════════════════════════════════════════
   12. SCORE BAR
   ═══════════════════════════════════════════════ */
.score-bar {
  height: 8px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: var(--space-1);
}

.score-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  background: var(--accent-emphasis);
}

/* Thin variant */
.score-bar-thin { height: 4px; }

/* Progress bar with animation */
.progress-bar-animated .score-bar-fill {
  background-image: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.1) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.1) 75%,
    transparent 75%,
    transparent
  );
  background-size: 1rem 1rem;
  animation: progress-stripe 1s linear infinite;
}

@keyframes progress-stripe {
  from { background-position: 1rem 0; }
  to { background-position: 0 0; }
}


/* ═══════════════════════════════════════════════
   13. EMPTY STATE
   ═══════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--fg-muted);
}

.empty-state svg,
.empty-state .empty-state-icon {
  opacity: 0.3;
  margin-bottom: var(--space-4);
}

.empty-state h3 {
  font-size: var(--text-md);
  margin-bottom: var(--space-1);
  color: var(--fg-default);
  font-weight: 500;
}

.empty-state p {
  color: var(--fg-muted);
  font-size: var(--text-base);
  max-width: 360px;
  margin: 0 auto;
  line-height: var(--leading-relaxed);
}

.empty-state .btn {
  margin-top: var(--space-5);
}


/* ═══════════════════════════════════════════════
   14. FLASH MESSAGES
   ═══════════════════════════════════════════════ */
.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  font-size: var(--text-base);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  animation: flash-in 0.3s ease;
}

.flash-success {
  background: var(--success-subtle);
  color: var(--success-fg);
  border: 1px solid var(--success-muted);
}

.flash-error {
  background: var(--danger-subtle);
  color: var(--danger-fg);
  border: 1px solid var(--danger-muted);
}

.flash-info {
  background: var(--info-subtle);
  color: var(--info-fg);
  border: 1px solid var(--info-muted);
}

.flash-warning {
  background: var(--warning-subtle);
  color: var(--warning-fg);
  border: 1px solid var(--warning-muted);
}

@keyframes flash-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Dismissible flash */
.flash-dismissible {
  position: relative;
  padding-right: 40px;
}
.flash-dismiss {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  padding: 4px;
  font-size: 18px;
  line-height: 1;
}
.flash-dismiss:hover { opacity: 1; }


/* ═══════════════════════════════════════════════
   15. TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 280px;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 0.3s ease forwards;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  color: var(--fg-default);
}

.toast-success {
  border-color: var(--success-muted);
  background: linear-gradient(135deg, var(--bg-overlay), rgba(46, 160, 67, 0.08));
}
.toast-success::before {
  content: '';
  width: 3px;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  background: var(--success-fg);
}

.toast-error {
  border-color: var(--danger-muted);
  background: linear-gradient(135deg, var(--bg-overlay), rgba(248, 81, 73, 0.08));
}
.toast-error::before {
  content: '';
  width: 3px;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  background: var(--danger-fg);
}

.toast-info {
  border-color: var(--info-muted);
  background: linear-gradient(135deg, var(--bg-overlay), rgba(56, 139, 253, 0.08));
}

.toast-warning {
  border-color: var(--warning-muted);
  background: linear-gradient(135deg, var(--bg-overlay), rgba(210, 153, 34, 0.08));
}

.toast { position: relative; overflow: hidden; }

.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 16px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}
.toast-close:hover { opacity: 1; }

/* Toast progress bar (auto-dismiss countdown) */
.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: currentColor;
  opacity: 0.3;
  animation: toast-progress 4s linear forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100%); }
}

@keyframes toast-progress {
  from { width: 100%; }
  to { width: 0%; }
}

.toast.toast-exit {
  animation: toast-out 0.3s ease forwards;
}


/* ═══════════════════════════════════════════════
   16. MODALS
   ═══════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-backdrop);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: modal-overlay-in 0.2s ease;
}

.modal {
  background: var(--bg-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-sm { width: 360px; }
.modal-lg { width: 640px; }
.modal-xl { width: 800px; }

.modal-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg-default);
  z-index: 1;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.modal-header h3 {
  font-size: var(--text-md);
  font-weight: 600;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 18px;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.modal-close:hover {
  background: var(--bg-subtle);
  color: var(--fg-default);
}

.modal-body { padding: var(--space-4); }

.modal-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-muted);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  position: sticky;
  bottom: 0;
  background: var(--bg-default);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

@keyframes modal-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Alpine.js x-cloak */
[x-cloak] { display: none !important; }


/* ═══════════════════════════════════════════════
   17. TABS
   ═══════════════════════════════════════════════ */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: var(--space-4);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-base);
  color: var(--fg-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}
.tab:hover { color: var(--fg-default); }
.tab.active {
  color: var(--fg-default);
  border-bottom-color: var(--accent-fg);
  font-weight: 500;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }


/* ═══════════════════════════════════════════════
   18. POLICY CHAIN
   ═══════════════════════════════════════════════ */
.policy-chain {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.policy-rule {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-subtle);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  transition: border-color var(--transition-base), background var(--transition-base);
}

.policy-rule:hover {
  border-color: var(--border-default);
  background: rgba(28, 33, 40, 0.8);
}

.policy-rule .rule-order {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-canvas);
  border-radius: 50%;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--fg-muted);
  flex-shrink: 0;
}

.policy-rule .rule-name { font-weight: 500; flex: 1; }
.policy-rule .rule-params {
  color: var(--fg-muted);
  font-size: 13px;
  font-family: var(--font-mono);
}
.policy-rule .rule-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }


/* ═══════════════════════════════════════════════
   19. LOADING & SPINNERS
   ═══════════════════════════════════════════════ */

/* HTMX loading indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-fg);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
.spinner-sm { width: 12px; height: 12px; border-width: 1.5px; }
.spinner-lg { width: 24px; height: 24px; border-width: 3px; }
.spinner-xl { width: 32px; height: 32px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Loading overlay for cards/sections */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  z-index: 10;
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-subtle) 25%,
    rgba(48, 54, 61, 0.5) 50%,
    var(--bg-subtle) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease infinite;
  border-radius: var(--radius-sm);
}

.skeleton-text {
  height: 14px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
}
.skeleton-text:last-child { width: 60%; }

.skeleton-heading {
  height: 24px;
  width: 40%;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-sm);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skeleton-card {
  height: 120px;
  border-radius: var(--radius-md);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Pulse animation (for generic loading indicators) */
.pulse {
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* HTMX top progress bar — width-based, driven by JS in shell.html */
.htmx-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--accent-fg);
  z-index: var(--z-progress);
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 0 8px var(--accent-muted);
}


/* ═══════════════════════════════════════════════
   20. LOGIN PAGE
   ═══════════════════════════════════════════════ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-canvas);
  background-image: radial-gradient(ellipse at 50% 0%, rgba(31, 111, 235, 0.08) 0%, transparent 60%);
}


/* ═══════════════════════════════════════════════
   21. CHARTS
   ═══════════════════════════════════════════════ */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--space-4);
}

.chart-card {
  background: var(--bg-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.chart-card-sm { min-width: 0; }

.chart-container {
  position: relative;
  height: 280px;
}
.chart-container-sm { height: 260px; }


/* ═══════════════════════════════════════════════
   22. DIRECTORY PAGE (public)
   ═══════════════════════════════════════════════ */
.directory-page { min-height: 100vh; background: var(--bg-inset); }
.directory-header {
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-muted);
  padding: var(--space-4) var(--space-6);
}
.directory-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.directory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-4);
}
.directory-card {
  padding: var(--space-5);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
.directory-card:hover {
  border-color: var(--accent-fg);
  box-shadow: var(--shadow-md);
}


/* ═══════════════════════════════════════════════
   23. DROPDOWNS
   ═══════════════════════════════════════════════ */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: var(--space-1);
  min-width: 180px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  padding: var(--space-1) 0;
  animation: dropdown-in 0.15s ease;
}

.dropdown-menu-right { left: auto; right: 0; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  font-size: var(--text-base);
  color: var(--fg-default);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.dropdown-item:hover {
  background: var(--bg-subtle);
  text-decoration: none;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-muted);
  margin: var(--space-1) 0;
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}


/* ═══════════════════════════════════════════════
   24. TOOLTIPS
   ═══════════════════════════════════════════════ */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--fg-on-emphasis);
  background: var(--fg-subtle);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: var(--z-dropdown);
}

[data-tooltip]:hover::after { opacity: 1; }


/* ═══════════════════════════════════════════════
   25. DIVIDERS & SEPARATORS
   ═══════════════════════════════════════════════ */
.divider {
  border: none;
  border-top: 1px solid var(--border-muted);
  margin: var(--space-4) 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--fg-subtle);
  font-size: var(--text-sm);
}
.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-muted);
}


/* ═══════════════════════════════════════════════
   26. AVATAR / ICON CIRCLE
   ═══════════════════════════════════════════════ */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--fg-muted);
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-sm { width: 24px; height: 24px; font-size: var(--text-xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-md); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }


/* ═══════════════════════════════════════════════
   27. UTILITY CLASSES
   ═══════════════════════════════════════════════ */

/* Text colors */
.text-default { color: var(--fg-default); }
.text-muted { color: var(--fg-muted); }
.text-subtle { color: var(--fg-subtle); }
.text-success { color: var(--success-fg); }
.text-danger { color: var(--danger-fg); }
.text-warning { color: var(--warning-fg); }
.text-info { color: var(--accent-fg); }
.text-purple { color: var(--done-fg); }

/* Text size */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }

/* Text style */
.text-mono { font-family: var(--font-mono); }
.text-bold { font-weight: 600; }
.text-medium { font-weight: 500; }
.text-normal { font-weight: 400; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-uppercase { text-transform: uppercase; letter-spacing: 0.05em; }
.text-nowrap { white-space: nowrap; }
.text-break { word-break: break-all; }

/* Truncate */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Flexbox */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.self-center { align-self: center; }

/* Gap */
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* Grid */
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

/* Margin — using 4px base */
.m-0 { margin: 0; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.ml-1 { margin-left: var(--space-1); }
.ml-2 { margin-left: var(--space-2); }
.ml-3 { margin-left: var(--space-3); }
.ml-4 { margin-left: var(--space-4); }
.mr-1 { margin-right: var(--space-1); }
.mr-2 { margin-right: var(--space-2); }
.mr-3 { margin-right: var(--space-3); }
.mr-4 { margin-right: var(--space-4); }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Padding */
.p-0 { padding: 0; }
.p-1 { padding: var(--space-1); }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }
.px-2 { padding-left: var(--space-2); padding-right: var(--space-2); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* Width / Height */
.w-full { width: 100%; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100vh; }

/* Display */
.block { display: block; }
.inline-block { display: inline-block; }
.hidden { display: none; }

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.sticky { position: sticky; }
.inset-0 { inset: 0; }

/* Overflow */
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-x-auto { overflow-x: auto; }

/* Border */
.border { border: 1px solid var(--border-default); }
.border-t { border-top: 1px solid var(--border-default); }
.border-b { border-bottom: 1px solid var(--border-default); }
.border-l { border-left: 1px solid var(--border-default); }
.border-none { border: none; }
.rounded { border-radius: var(--radius); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

/* Background */
.bg-canvas { background: var(--bg-canvas); }
.bg-default { background: var(--bg-default); }
.bg-subtle { background: var(--bg-subtle); }

/* Opacity */
.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }

/* Cursor */
.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }

/* Selection */
.select-none { user-select: none; }
.select-all { user-select: all; }

/* Visibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Transition helpers */
.transition { transition: all var(--transition-base); }
.transition-fast { transition: all var(--transition-fast); }
.transition-slow { transition: all var(--transition-slow); }


/* ═══════════════════════════════════════════════
   28. RESPONSIVE / MOBILE
   ═══════════════════════════════════════════════ */

/* Tablet (max-width: 1024px) */
@media (max-width: 1024px) {
  .main {
    padding: var(--space-6);
  }

  .charts-row {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .directory-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }

  /* Responsive grid utilities */
  .md\:grid-cols-1 { grid-template-columns: 1fr; }
  .md\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
  /* Sidebar collapse */
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    padding: var(--space-4);
    max-width: 100%;
  }

  /* Mobile menu toggle (add to shell.html) */
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    border: 1px solid var(--border-default);
    background: var(--bg-default);
    color: var(--fg-default);
    cursor: pointer;
    position: fixed;
    top: var(--space-3);
    left: var(--space-3);
    z-index: calc(var(--z-sidebar) + 1);
  }

  /* Sidebar backdrop on mobile */
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: var(--bg-backdrop);
    z-index: calc(var(--z-sidebar) - 1);
  }

  /* Stats grid: stack on mobile */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }

  .stat-card { padding: var(--space-3); }
  .stat-card .stat-value { font-size: var(--text-xl); }

  /* Tables: horizontal scroll with shadow hint */
  .table-wrap {
    position: relative;
  }
  .table-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--bg-default));
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-base);
  }
  .table-wrap.has-scroll::after { opacity: 1; }

  table { min-width: 600px; }

  /* Modals: full-width on mobile */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: modal-in-mobile 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .modal-sm, .modal-lg, .modal-xl { width: 100%; }

  @keyframes modal-in-mobile {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Charts */
  .charts-row { grid-template-columns: 1fr; }
  .chart-container { height: 220px; }
  .chart-container-sm { height: 200px; }

  /* Forms stack */
  .form-row { flex-direction: column; gap: 0; }

  /* Page header */
  .page-header h1 { font-size: var(--text-lg); }

  /* Policy chain */
  .policy-rule {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .policy-rule .rule-actions {
    width: 100%;
    justify-content: flex-end;
  }

  /* Toast: full-width on mobile */
  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
  }
  .toast { min-width: auto; max-width: 100%; }

  /* Directory grid */
  .directory-grid { grid-template-columns: 1fr; }

  /* Login */
  .login-card { width: calc(100% - var(--space-8)); padding: var(--space-6); }

  /* Grid utilities */
  .sm\:grid-cols-1 { grid-template-columns: 1fr; }
}

/* Very small screens */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }

  .btn-group {
    flex-direction: column;
  }
  .btn-group .btn { width: 100%; }

  .tabs { gap: 0; }
  .tab { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 769px) {
  .mobile-menu-btn { display: none; }
  .sidebar-backdrop { display: none; }
  .mobile-only { display: none; }
}

/* Print */
@media print {
  .sidebar,
  .toast-container,
  .htmx-progress { display: none; }
  .main { margin-left: 0; padding: 0; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ddd; box-shadow: none; }
}


/* ═══════════════════════════════════════════════
   29. ANIMATIONS (reusable)
   ═══════════════════════════════════════════════ */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slide-in-left {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Animation utility classes */
.animate-fade-in { animation: fade-in 0.3s ease; }
.animate-fade-in-up { animation: fade-in-up 0.3s ease; }
.animate-fade-in-down { animation: fade-in-down 0.3s ease; }
.animate-scale-in { animation: scale-in 0.2s ease; }
.animate-slide-in-right { animation: slide-in-right 0.3s ease; }

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ═══════════════════════════════════════════════
   30. LOGIN PAGE — Premium SaaS Design
   ═══════════════════════════════════════════════ */

/* Background dot grid pattern */
.login-bg-pattern {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 1px 1px, var(--border-muted) 1px, transparent 0);
  background-size: 40px 40px;
  opacity: 0.3;
  pointer-events: none;
}

.login-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  padding: 0 var(--space-5);
}

/* Brand header above login card */
.login-brand {
  text-align: center;
  margin-bottom: var(--space-6);
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--bg-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow);
}

.login-title {
  font-size: 28px;
  font-weight: 600;
  color: var(--fg-default);
  margin-bottom: var(--space-1);
  letter-spacing: -0.03em;
}

.login-subtitle {
  font-size: var(--text-base);
  color: var(--fg-muted);
}

/* Login card */
.login-card {
  background: var(--bg-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}

/* Login error banner */
.login-error {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 14px;
  background: var(--danger-subtle);
  border: 1px solid var(--danger-muted);
  border-radius: var(--radius);
  color: var(--danger-fg);
  font-size: 13px;
  margin-bottom: var(--space-4);
  animation: flash-in 0.3s ease;
}
.login-error svg { flex-shrink: 0; }

/* Login tabs — pill-style switcher */
.login-tabs {
  display: flex;
  position: relative;
  background: var(--bg-canvas);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: var(--space-6);
}

.login-tab {
  flex: 1;
  padding: 7px var(--space-4);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  position: relative;
  z-index: 1;
  transition: color var(--transition-base);
  font-family: inherit;
}
.login-tab:hover { color: var(--fg-default); }
.login-tab.active {
  color: var(--fg-default);
  background: var(--bg-subtle);
}

.login-tab-indicator {
  position: absolute;
  top: 3px;
  bottom: 3px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
}

/* Login form button — full width */
.btn-login {
  width: 100%;
  justify-content: center;
  padding: 8px var(--space-4);
  margin-top: var(--space-1);
  font-size: var(--text-base);
}

.login-footer {
  text-align: center;
  margin-top: var(--space-6);
  font-size: var(--text-sm);
  color: var(--fg-subtle);
}

/* Alpine tab transitions */
.tab-enter { transition: opacity 0.2s ease, transform 0.2s ease; }
.tab-enter-start { opacity: 0; transform: translateY(4px); }
.tab-enter-end { opacity: 1; transform: translateY(0); }

/* Login responsive */
@media (max-width: 480px) {
  .login-container { padding: 0 var(--space-4); }
  .login-card { padding: var(--space-5); }
  .login-logo { width: 48px; height: 48px; }
  .login-title { font-size: var(--text-xl); }
}


/* ═══════════════════════════════════════════════
   31. FORM ENHANCEMENTS — Icons & Validation
   ═══════════════════════════════════════════════ */

/* Input with icon wrapper */
.input-wrap {
  position: relative;
}
.input-wrap input {
  padding-left: 36px;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-subtle);
  pointer-events: none;
  transition: color var(--transition-fast);
}

/* Brighten icon on focus */
.input-wrap:focus-within .input-icon {
  color: var(--fg-muted);
}

.input-check {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* Inline validation error state */
.form-group.has-error input {
  border-color: var(--danger-fg);
}
.form-group.has-error input:focus {
  box-shadow: 0 0 0 3px var(--danger-muted);
}
.form-group.has-error .input-icon {
  color: var(--danger-fg);
}

.field-error {
  display: block;
  font-size: var(--text-sm);
  color: var(--danger-fg);
  margin-top: var(--space-1);
  animation: fade-in-up 0.2s ease;
}

/* Password strength indicator */
.password-strength {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: 6px;
}
.password-strength-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.password-strength-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s ease, background 0.3s ease;
}
.password-strength-fill.strength-weak { background: var(--danger-fg); }
.password-strength-fill.strength-fair { background: var(--warning-fg); }
.password-strength-fill.strength-strong { background: var(--success-fg); }

.password-strength-label {
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}
.password-strength-label.strength-weak { color: var(--danger-fg); }
.password-strength-label.strength-fair { color: var(--warning-fg); }
.password-strength-label.strength-strong { color: var(--success-fg); }


/* ═══════════════════════════════════════════════
   32. SHELL ENHANCEMENTS — Mobile, Footer, Progress
   ═══════════════════════════════════════════════ */

/* Sidebar logo close button (mobile) */
.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius);
  line-height: 0;
  margin-left: auto;
  transition: all var(--transition-fast);
}
.sidebar-close:hover {
  color: var(--fg-default);
  background: var(--bg-subtle);
}

.sidebar-logo span { flex: 1; }

/* Sidebar footer — org avatar + logout */
.sidebar-footer-org {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-2);
}

.org-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--accent-emphasis);
  color: var(--fg-on-emphasis);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-base);
  font-weight: 600;
  flex-shrink: 0;
}
.org-avatar-sm {
  width: 26px;
  height: 26px;
  font-size: var(--text-sm);
}

.org-info {
  min-width: 0;
  flex: 1;
}
.org-info .org-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar logout button */
.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px var(--space-2);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-size: var(--text-sm);
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.sidebar-logout:hover {
  background: var(--danger-subtle);
  color: var(--danger-fg);
  border-color: var(--danger-muted);
}
.sidebar-logout svg { flex-shrink: 0; }

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
}

/* Mobile topbar (hidden on desktop) */
.mobile-topbar {
  display: none;
}

/* Warning subtle button */
.btn-warning-subtle {
  background: var(--warning-subtle);
  border-color: var(--warning-muted);
  color: var(--warning-fg);
}
.btn-warning-subtle:hover {
  background: rgba(210, 153, 34, 0.25);
}

/* Mobile responsive overrides for shell */
@media (max-width: 768px) {
  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .sidebar-close {
    display: block;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--bg-backdrop);
    z-index: calc(var(--z-sidebar) - 1);
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) 0;
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-muted);
  }
  .mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--fg-default);
  }
  .mobile-topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }

  .hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius);
    color: var(--fg-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
  }
  .hamburger-btn:hover {
    background: var(--bg-subtle);
    color: var(--fg-default);
  }
}


/* ═══════════════════════════════════════════════
   33. OVERVIEW PAGE ENHANCEMENTS
   ═══════════════════════════════════════════════ */

/* Page header row layout */
.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.page-header-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Stat card top row — icon + label */
.stat-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-3);
}

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon-blue { background: var(--info-subtle); color: var(--info-fg); }
.stat-icon-green { background: var(--success-subtle); color: var(--success-fg); }
.stat-icon-purple { background: var(--done-subtle); color: var(--done-fg); }
.stat-icon-amber { background: var(--warning-subtle); color: var(--warning-fg); }

/* Stat sub-text with status dot */
.stat-sub-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stat-sub-dot-green { background: var(--success-fg); }
.stat-sub-dot-red { background: var(--danger-fg); }

/* Overview two-column grid */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

@media (max-width: 1024px) {
  .overview-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .page-header-row {
    flex-direction: column;
    gap: var(--space-3);
  }
  .page-header-actions {
    width: 100%;
  }
  .page-header-actions .btn {
    flex: 1;
    justify-content: center;
  }
}

/* Skeleton loading variants for overview */
.skeleton-text-sm {
  height: 12px;
  width: 60%;
  margin-bottom: var(--space-2);
}
.skeleton-text-lg {
  height: 28px;
  width: 40%;
  margin-bottom: var(--space-2);
}
.skeleton-line {
  height: 14px;
  width: 100%;
}
.skeleton-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-muted);
}
.skeleton-row:last-child { border-bottom: none; }

.table-skeleton {
  padding: var(--space-2) var(--space-3);
}

.stat-card-loading {
  min-height: 120px;
}

/* Quick actions panel */
.quick-actions {
  background: var(--bg-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.quick-actions-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}

.quick-action-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--fg-default);
}
.quick-action-card:hover {
  border-color: var(--border-default);
  background: var(--bg-subtle);
  text-decoration: none;
}

.quick-action-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.quick-action-icon-blue { background: var(--info-subtle); color: var(--info-fg); }
.quick-action-icon-green { background: var(--success-subtle); color: var(--success-fg); }
.quick-action-icon-purple { background: var(--done-subtle); color: var(--done-fg); }
.quick-action-icon-amber { background: var(--warning-subtle); color: var(--warning-fg); }

.quick-action-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.quick-action-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-default);
}
.quick-action-desc {
  font-size: var(--text-sm);
  color: var(--fg-subtle);
}

@media (max-width: 768px) {
  .quick-actions-grid {
    grid-template-columns: 1fr;
  }
}

/* Opacity transition helpers for Alpine */
.opacity-0 { opacity: 0; }
.opacity-100 { opacity: 1; }
.fade-in { transition: opacity var(--transition-base); }
.fade-out { transition: opacity var(--transition-fast); }
