/* ==========================================================================
   PurpleSec AI Security Framework — design system
   Hand-written replacement for Tailwind + shadcn/ui. Tokens first, then a
   small utility set (Tailwind-inspired names), then components.
   ========================================================================== */

:root {
  --purple: rgb(151, 79, 244);
  --purple-light: rgb(177, 117, 255);
  --purple-50: #f9f5ff;
  --purple-100: #f3e8ff;
  --purple-200: #e9d5ff;
  --purple-600: #9333ea;
  --purple-700: #7e22ce;

  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-300: #93c5fd;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;

  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-300: #86efac;
  --green-600: #16a34a;
  --green-700: #15803d;

  --yellow-50: #fefce8;
  --yellow-100: #fef9c3;
  --yellow-300: #fde047;
  --yellow-600: #ca8a04;
  --yellow-700: #a16207;

  --orange-50: #fff7ed;
  --orange-100: #ffedd5;
  --orange-600: #ea580c;

  --red-50: #fef2f2;
  --red-100: #fee2e2;
  --red-300: #fca5a5;
  --red-600: #dc2626;
  --red-700: #b91c1c;

  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--slate-900);
  background: var(--slate-50);
  min-height: 100vh;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; background: none; border: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 700; }
ul[class], ol[class] { list-style: none; }

/* --- Layout utilities --- */
.container-xl { max-width: 80rem; margin: 0 auto; }
.container-lg { max-width: 72rem; margin: 0 auto; }
.container-md { max-width: 48rem; margin: 0 auto; }
.container-sm { max-width: 28rem; margin: 0 auto; }
.page { min-height: 100vh; padding: 1.5rem; }
@media (min-width: 768px) { .page { padding: 2rem; } }

.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.hidden { display: none !important; }
.block { display: block; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1 1 0%; min-width: 0; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 0.25rem; } .gap-2 { gap: 0.5rem; } .gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; } .gap-6 { gap: 1.5rem; } .gap-8 { gap: 2rem; }
.grid-cols-1 { grid-template-columns: 1fr; }
@media (min-width: 768px) {
  .md-grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
  .md-grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
  .md-grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
  .md-flex { display: flex; }
  .md-hidden { display: none !important; }
}

/* --- Spacing utilities --- */
.m-0 { margin: 0; }
.mt-1 { margin-top: 0.25rem; } .mt-2 { margin-top: 0.5rem; } .mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; } .mt-6 { margin-top: 1.5rem; } .mt-8 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.25rem; } .mb-2 { margin-bottom: 0.5rem; } .mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; } .mb-6 { margin-bottom: 1.5rem; } .mb-8 { margin-bottom: 2rem; }
.ml-auto { margin-left: auto; } .mx-auto { margin-left: auto; margin-right: auto; }
.p-2 { padding: 0.5rem; } .p-3 { padding: 0.75rem; } .p-4 { padding: 1rem; }
.p-5 { padding: 1.25rem; } .p-6 { padding: 1.5rem; } .p-8 { padding: 2rem; } .p-12 { padding: 3rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }

/* --- Typography utilities --- */
.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; line-height: 2rem; }
.text-3xl { font-size: 1.875rem; line-height: 2.25rem; }
.text-4xl { font-size: 2.25rem; line-height: 2.5rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.uppercase { text-transform: uppercase; }
.capitalize { text-transform: capitalize; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leading-relaxed { line-height: 1.625; }

.text-white { color: #fff; }
.text-muted { color: var(--slate-600); }
.text-subtle { color: var(--slate-500); }
.text-faint { color: var(--slate-400); }
.text-slate-700 { color: var(--slate-700); }
.text-slate-900 { color: var(--slate-900); }
.text-purple { color: var(--purple); }
.text-blue { color: var(--blue-600); }
.text-green { color: var(--green-600); }
.text-yellow { color: var(--yellow-600); }
.text-orange { color: var(--orange-600); }
.text-red { color: var(--red-600); }

/* --- Background / border utilities --- */
.bg-white { background: #fff; }
.bg-slate-50 { background: var(--slate-50); }
.bg-slate-100 { background: var(--slate-100); }
.bg-purple-50 { background: var(--purple-50); }
.bg-gradient-page { background: linear-gradient(135deg, var(--slate-50), rgba(243, 232, 255, 0.2), var(--slate-50)); }
.rounded { border-radius: var(--radius); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-2xl { border-radius: 1.25rem; }
.rounded-full { border-radius: 9999px; }
.border { border: 1px solid var(--slate-200); }
.border-t { border-top: 1px solid var(--slate-200); }
.border-b { border-bottom: 1px solid var(--slate-200); }
.border-dashed { border-style: dashed; }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow { box-shadow: var(--shadow); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-xl { box-shadow: var(--shadow-xl); }
.overflow-hidden { overflow: hidden; }
.overflow-x-auto { overflow-x: auto; }
.cursor-pointer { cursor: pointer; }
.w-full { width: 100%; }
.min-w-0 { min-width: 0; }
.relative { position: relative; }

/* --- Icon sizing --- */
.icon { width: 1rem; height: 1rem; flex-shrink: 0; }
.icon-sm { width: 0.875rem; height: 0.875rem; flex-shrink: 0; }
.icon-lg { width: 1.5rem; height: 1.5rem; flex-shrink: 0; }
.icon-xl { width: 2.5rem; height: 2.5rem; flex-shrink: 0; }
.icon-2xl { width: 4rem; height: 4rem; flex-shrink: 0; }

/* ==========================================================================
   Components
   ========================================================================== */

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary { background: var(--blue-600); color: #fff; }
.btn-primary:hover { background: var(--blue-700); }
.btn-purple { background: var(--purple-600); color: #fff; }
.btn-purple:hover { background: var(--purple-700); }
.btn-brand { background: var(--purple); color: #fff; }
.btn-brand:hover { background: var(--purple-light); }
.btn-outline { background: #fff; border-color: var(--slate-300); color: var(--slate-700); }
.btn-outline:hover { background: var(--slate-50); }
.btn-ghost { background: transparent; color: var(--slate-700); }
.btn-ghost:hover { background: var(--slate-100); }
.btn-danger { background: #fff; border-color: var(--red-300); color: var(--red-600); }
.btn-danger:hover { background: var(--red-50); }
.btn-danger-solid { background: var(--red-600); color: #fff; }
.btn-danger-solid:hover { background: var(--red-700); }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.75rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; }

/* --- Cards --- */
.card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header { padding: 1.5rem 1.5rem 0.5rem; }
.card-title { font-size: 1.125rem; font-weight: 600; }
.card-content { padding: 1.5rem; }
.card-header + .card-content { padding-top: 0.75rem; }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-default { background: var(--slate-900); color: #fff; }
.badge-secondary { background: var(--slate-100); color: var(--slate-800); }
.badge-outline { background: #fff; border-color: var(--slate-300); color: var(--slate-700); }
.badge-green { background: var(--green-50); color: var(--green-700); border-color: var(--green-300); }
.badge-blue { background: var(--blue-50); color: var(--blue-700); border-color: var(--blue-300); }
.badge-yellow { background: var(--yellow-50); color: var(--yellow-700); border-color: var(--yellow-300); }
.badge-red { background: var(--red-50); color: var(--red-700); border-color: var(--red-300); }
.badge-purple { background: var(--purple-50); color: var(--purple-700); border-color: var(--purple-200); }

/* --- Forms --- */
.label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.375rem; }
.input, .select, .textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius);
  background: #fff;
  font-size: 0.875rem;
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--purple-light);
  outline-offset: 1px;
  border-color: var(--purple-light);
}
.textarea { min-height: 5rem; resize: vertical; }
.checkbox, .radio { width: 1rem; height: 1rem; accent-color: var(--purple-600); cursor: pointer; }
.field { margin-bottom: 1rem; }
.form-error { color: var(--red-600); font-size: 0.875rem; margin-top: 0.5rem; }

/* --- Tables --- */
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th {
  text-align: left;
  font-weight: 600;
  color: var(--slate-600);
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--slate-200);
  background: var(--slate-50);
}
.table td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--slate-200); }
.table tr:hover td { background: var(--slate-50); }

/* --- Dropdown menus --- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.375rem);
  min-width: 14rem;
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.25rem;
  z-index: 100;
  display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu.align-end { right: 0; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem;
  color: var(--slate-800);
  text-align: left;
}
.dropdown-item:hover { background: var(--slate-100); }
.dropdown-label { padding: 0.5rem 0.75rem; }
.dropdown-separator { height: 1px; background: var(--slate-200); margin: 0.25rem 0; }

/* --- Modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.5);
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 32rem;
  padding: 1.5rem;
}
.modal-lg { max-width: 48rem; }

/* --- Progress bar --- */
.progress { height: 0.5rem; background: var(--slate-200); border-radius: 9999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--purple); border-radius: 9999px; transition: width 0.3s; }

/* --- Alerts --- */
.alert { padding: 1rem; border-radius: var(--radius); border: 1px solid; font-size: 0.875rem; }
.alert-info { background: var(--blue-50); border-color: var(--blue-300); color: var(--blue-700); }
.alert-warn { background: var(--yellow-50); border-color: var(--yellow-300); color: var(--yellow-700); }
.alert-error { background: var(--red-50); border-color: var(--red-300); color: var(--red-700); }
.alert-success { background: var(--green-50); border-color: var(--green-300); color: var(--green-700); }

/* --- Avatar --- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 9999px;
  background: var(--slate-700);
  color: #fff;
  font-weight: 600;
}

/* ==========================================================================
   Site header (base.html)
   ========================================================================== */
.site-header { background: #fff; border-bottom: 1px solid var(--slate-200); position: sticky; top: 0; z-index: 50; }
.site-header-inner {
  padding: 0.75rem 1.5rem;
  height: 175px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 5px solid var(--purple);
}
.site-logo img { height: 150px; width: auto; }
.site-nav { display: none; align-items: center; gap: 1.5rem; font-size: 1.125rem; }
@media (min-width: 768px) { .site-nav { display: flex; } }
.site-nav-link {
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  color: var(--slate-700);
  border-bottom: 5px solid transparent;
  transition: border-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.site-nav-link:hover { border-bottom-color: var(--purple-light); }
.site-main { flex: 1; }
.site-wrap { min-height: 100vh; display: flex; flex-direction: column; background: var(--slate-50); }

/* --- Misc --- */
.spinner {
  width: 2rem;
  height: 2rem;
  border: 4px solid var(--slate-200);
  border-top-color: var(--slate-800);
  border-radius: 9999px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.divider-y > * + * { border-top: 1px solid var(--slate-200); }
