/*
 * DFMS — Custom stylesheet
 * Builds on top of Bootstrap 5.3
 *
 * NOTE: The portal auth pages intentionally match the Django admin login UI.
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --dfms-sidebar-width: 240px;
  --dfms-navbar-height: 56px;
  /* Match Admin theme tokens */
  --dfms-primary-dark: #122056;
  --dfms-primary: #5B65DC;
  --dfms-primary-hover: #4A53C4;

  --dfms-grey-50: #F9FAFB;
  --dfms-grey-100: #F3F4F6;
  --dfms-grey-200: #E5E7EB;
  --dfms-grey-300: #D1D5DB;
  --dfms-grey-500: #6B7280;
  --dfms-grey-700: #374151;
  --dfms-grey-900: #111827;

  --dfms-font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --dfms-font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --dfms-sidebar-bg: #1e2a3a;
  --dfms-sidebar-text: rgba(255, 255, 255, 0.75);
  --dfms-sidebar-active: var(--dfms-primary);
  --dfms-success: #16A34A;
  --dfms-success-bg: #D1FAE5;
  --dfms-warning: #D97706;
  --dfms-warning-bg: #FEF3C7;
  --dfms-danger: #C0392B;
  --dfms-danger-bg: #FEE2E2;
  --dfms-text: var(--dfms-grey-900);
  --dfms-text-muted: var(--dfms-grey-500);
}

[data-theme="dark"],
[data-bs-theme="dark"] {
  --dfms-primary: #7580F0;
  --dfms-primary-hover: #8A94F5;
  --dfms-primary-dark: #1C2044;
  --dfms-grey-50: #0D0F1A;
  --dfms-grey-100: #161929;
  --dfms-grey-200: #1E2340;
  --dfms-grey-300: #2A3050;
  --dfms-grey-500: #9CA3AF;
  --dfms-grey-700: #D1D5DB;
  --dfms-grey-900: #F9FAFB;
  --dfms-success: #34D475;
  --dfms-success-bg: rgba(52, 212, 117, 0.15);
  --dfms-warning: #F59E0B;
  --dfms-warning-bg: rgba(245, 158, 11, 0.15);
  --dfms-danger: #F87171;
  --dfms-danger-bg: rgba(248, 113, 113, 0.15);
  --dfms-text: var(--dfms-grey-900);
  --dfms-text-muted: var(--dfms-grey-500);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-bs-theme="light"]) {
    --dfms-primary: #7580F0;
    --dfms-primary-hover: #8A94F5;
    --dfms-primary-dark: #1C2044;
    --dfms-grey-50: #0D0F1A;
    --dfms-grey-100: #161929;
    --dfms-grey-200: #1E2340;
    --dfms-grey-300: #2A3050;
    --dfms-grey-500: #9CA3AF;
    --dfms-grey-700: #D1D5DB;
    --dfms-grey-900: #F9FAFB;
    --dfms-success: #34D475;
    --dfms-success-bg: rgba(52, 212, 117, 0.15);
    --dfms-warning: #F59E0B;
    --dfms-warning-bg: rgba(245, 158, 11, 0.15);
    --dfms-danger: #F87171;
    --dfms-danger-bg: rgba(248, 113, 113, 0.15);
    --dfms-text: var(--dfms-grey-900);
    --dfms-text-muted: var(--dfms-grey-500);
  }
}

/* ── Layout ────────────────────────────────────────────────── */

body {
  padding-top: var(--dfms-navbar-height);
  font-size: 0.9rem;
  font-family: var(--dfms-font-sans);
  overflow-x: hidden;
  background: var(--dfms-grey-50);
  color: var(--dfms-text);
}

/* ── Portal navbar (match DFMS theme, not Bootstrap default) ── */

#dfms-navbar.navbar {
  background-color: var(--dfms-primary-dark) !important;
}

#dfms-navbar .navbar-brand,
#dfms-navbar .nav-link {
  color: rgba(255, 255, 255, 0.92) !important;
}

#dfms-navbar .nav-link:hover,
#dfms-navbar .nav-link:focus {
  color: #ffffff !important;
}

.sidebar {
  position: fixed;
  top: var(--dfms-navbar-height);
  left: 0;
  width: var(--dfms-sidebar-width);
  height: calc(100vh - var(--dfms-navbar-height));
  background-color: var(--dfms-sidebar-bg);
  overflow-y: auto;
  padding: 1rem 0.75rem;
  z-index: 1000;
  transition: transform 0.3s ease;
}

.sidebar .nav-link {
  color: var(--dfms-sidebar-text);
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
  background-color: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar .nav-link.active {
  background-color: var(--dfms-sidebar-active);
  color: #fff;
}

.sidebar .sidebar-heading {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.4);
  padding: 0 0.75rem;
  margin-bottom: 0.25rem;
}

.main-content {
  margin-left: var(--dfms-sidebar-width);
  padding: 1.5rem;
  min-height: calc(100vh - var(--dfms-navbar-height));
}

.sidebar-backdrop {
  position: fixed;
  inset: var(--dfms-navbar-height) 0 0 0;
  background: rgba(17, 24, 39, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 999;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
  .main-content {
    margin-left: 0;
    padding: 1rem;
  }
  .navbar .navbar-nav {
    align-items: flex-start !important;
    gap: 0.25rem;
  }
  .navbar .dropdown-menu {
    position: static;
    width: 100%;
  }
}

@media (max-width: 575.98px) {
  .main-content {
    padding: 0.75rem;
  }
  .auth-card {
    padding: 28px 20px 24px;
  }
  .auth-hints {
    flex-direction: column;
    gap: 4px;
  }
}

/* ── Utilities ─────────────────────────────────────────────── */

.letter-spacing-wide {
  letter-spacing: 0.2em;
}

[x-cloak] { display: none !important; }

/* ── Auth pages (login, activate, etc.) ────────────────────── */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 24px 16px;
  background: var(--dfms-grey-50);
  font-family: var(--dfms-font-sans);
}

/* Override base body padding-top on auth pages */
body.auth-body {
  padding-top: 0;
  background: var(--dfms-grey-50);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--dfms-grey-50);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  padding: 40px 40px 36px;
  border: 1px solid var(--dfms-grey-200);
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo-mark {
  width: 48px;
  height: 48px;
  background: transparent;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  overflow: hidden;
}

.auth-logo-mark span {
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -1px;
}

.auth-logo-mark .dfms-brand-mark,
.auth-logo-mark .dfms-brand-mark__img {
  width: 40px;
  height: 40px;
}

.auth-logo-lockup {
  display: flex;
  justify-content: center;
  margin: 0 auto 14px;
}

.auth-logo-lockup .dfms-brand-lockup {
  width: min(220px, 78%);
  max-height: 44px;
}

.auth-logo-lockup .dfms-brand-lockup__img {
  max-height: 44px;
}

.auth-logo h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--dfms-text);
  margin: 0 0 4px;
  line-height: 1.25;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--dfms-text-muted);
  margin: 0;
}

.auth-footer {
  text-align: center;
  font-size: 12px;
  color: #9CA3AF;
  margin-top: 24px;
}

/* ── Auth form fields ── */

.auth-field {
  margin-bottom: 16px;
}

.auth-field:last-of-type {
  margin-bottom: 24px;
}

.auth-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--dfms-grey-700);
  margin-bottom: 6px;
}

.auth-input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  background: var(--dfms-grey-100);
  border: 1px solid var(--dfms-grey-300);
  border-radius: 8px;
  font-size: 14px;
  color: var(--dfms-text);
  outline: none;
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}

.auth-input:focus {
  border-color: var(--dfms-primary);
  box-shadow: 0 0 0 3px rgba(91,101,220,.15);
  background: var(--dfms-grey-50);
}

.auth-input.is-invalid {
  border-color: #C0392B;
}

/* Password input + show/hide toggle */
.auth-input-group {
  display: flex;
  align-items: stretch;
}

.auth-input-group .auth-input {
  border-radius: 8px 0 0 8px;
  flex: 1;
}

.auth-input-group .auth-toggle {
  height: 42px;
  width: 44px;
  background: var(--dfms-grey-100);
  border: 1px solid var(--dfms-grey-300);
  border-left: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  color: var(--dfms-grey-500);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}

.auth-input-group .auth-toggle:hover { background: var(--dfms-grey-200); }

/* Generic password field wrapper (works across portal + auth pages) */
.dfms-password-wrap {
  position: relative;
  width: 100%;
}

.dfms-password-wrap input[type="password"],
.dfms-password-wrap input[type="text"] {
  padding-right: 40px !important; /* reserve space for suffix icon */
}

/* Hide Edge/IE native reveal so only our custom eye toggle shows */
.dfms-password-wrap input[type="password"]::-ms-reveal,
.dfms-password-wrap input[type="password"]::-ms-clear {
  display: none;
}

.dfms-password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--dfms-grey-500);
  cursor: pointer;
  padding: 0;
  border-radius: 6px;
}

.dfms-password-wrap > .dfms-password-toggle {
  position: absolute !important;
  right: 6px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  display: inline-flex !important;
  border: 0 !important;
  background: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
  width: 28px !important;
  height: 28px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  appearance: none;
}

.dfms-password-wrap--toggle-flush > .dfms-password-toggle {
  right: 0 !important;
}

.dfms-password-wrap--toggle-flush input[type="password"],
.dfms-password-wrap--toggle-flush input[type="text"] {
  padding-right: 28px !important; /* only reserve the icon width */
}

.dfms-password-toggle:hover {
  background: rgba(17, 24, 39, 0.06);
  color: var(--dfms-grey-700);
}

.dfms-password-toggle:focus-visible {
  outline: 3px solid rgba(91,101,220,.35);
  outline-offset: 2px;
}

/* Hint chips below a field */
.auth-hints {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 12px;
}

.auth-hint { color: #9CA3AF; }
.auth-hint.ok { color: var(--dfms-success); }

.auth-field-error {
  font-size: 12px;
  color: var(--dfms-danger);
  margin: 4px 0 0;
}

/* ── Auth alerts ── */

.auth-alert {
  border-radius: 6px;
  font-size: 13px;
  padding: 10px 14px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-alert-error {
  background: var(--dfms-danger-bg);
  border: 1px solid color-mix(in srgb, var(--dfms-danger) 25%, transparent);
  border-left: 4px solid var(--dfms-danger);
  color: var(--dfms-danger);
  font-weight: 500;
}

.auth-alert-warning {
  background: var(--dfms-warning-bg);
  border: 1px solid color-mix(in srgb, var(--dfms-warning) 25%, transparent);
  border-left: 4px solid var(--dfms-warning);
  color: var(--dfms-warning);
}

.auth-alert-warning p   { margin: 0 0 4px; font-weight: 600; }
.auth-alert-warning small { font-size: 12px; }

/* ── Auth submit button ── */

.auth-btn {
  width: 100%;
  height: 44px;
  background: var(--dfms-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s;
}

.auth-btn:hover:not(:disabled) { background: var(--dfms-primary-hover); }
.auth-btn:focus-visible {
  outline: 3px solid rgba(91,101,220,.35);
  outline-offset: 2px;
}
.auth-btn:disabled { opacity: .65; cursor: not-allowed; }

/* Inline spinner used inside auth-btn */
.auth-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: dfms-spin .6s linear infinite;
  flex-shrink: 0;
}

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

/* ── Status badges ─────────────────────────────────────────── */

.status-badge {
  font-size: 0.75rem;
  padding: 0.2em 0.6em;
  border-radius: 100px;
  font-weight: 600;
  text-transform: capitalize;
}

/* ── Tables ────────────────────────────────────────────────── */

.table-hover tbody tr:hover {
  background-color: rgba(13, 110, 253, 0.04);
}

/* ── Cards ─────────────────────────────────────────────────── */

.stat-card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
}
