/* ============================================================
   Flex theme — design tokens + modern app shell
   Loaded after Bootstrap, before site.css and page CSS.
   The single place the app's visual identity lives.
   ============================================================ */

:root {
  /* Brand */
  --flex-primary: #4f46e5;
  --flex-primary-hover: #4338ca;
  --flex-primary-soft: #eef2ff;

  /* Surfaces */
  --flex-bg: #f6f7fb;
  --flex-surface: #ffffff;
  --flex-border: #e5e7eb;

  /* Text */
  --flex-text: #1f2937;
  --flex-text-muted: #6b7280;

  /* Sidebar (dark slate) */
  --flex-sidebar-bg: #111827;
  --flex-sidebar-text: #9ca3af;
  --flex-sidebar-text-active: #ffffff;
  --flex-sidebar-hover: rgba(255, 255, 255, 0.06);
  --flex-sidebar-active: rgba(99, 102, 241, 0.22);
  --flex-sidebar-width: 248px;

  /* Shape & depth */
  --flex-radius: 10px;
  --flex-radius-sm: 8px;
  --flex-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --flex-shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --flex-shadow-lg: 0 12px 24px -6px rgba(16, 24, 40, 0.16);

  --flex-topbar-height: 56px;
}

/* ---------- Base ---------- */

body {
  font-family: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", sans-serif;
  background: var(--flex-bg);
  color: var(--flex-text);
  font-size: 0.925rem;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
  font-weight: 600;
  color: var(--flex-text);
  letter-spacing: -0.01em;
}

h1, .h1 { font-size: 1.6rem; }
h2, .h2 { font-size: 1.35rem; }
h3, .h3 { font-size: 1.15rem; }

.display-4 { font-size: 1.6rem; font-weight: 600; letter-spacing: -0.01em; }

a { color: var(--flex-primary); }
a:hover { color: var(--flex-primary-hover); }

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--flex-sidebar-width);
  background: var(--flex-sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1035;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #374151 transparent;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 14px;
  flex-shrink: 0;
}

.app-brand a {
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  font-size: 0.95rem;
}

.app-nav {
  flex: 1;
  padding: 4px 10px 16px;
}

.app-nav-section {
  margin: 14px 8px 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #4b5563;
}

.app-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  margin: 1px 0;
  border-radius: 8px;
  color: var(--flex-sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.3;
  transition: background 0.12s ease, color 0.12s ease;
}

.app-nav-link i {
  width: 18px;
  text-align: center;
  font-size: 0.85rem;
  flex-shrink: 0;
  opacity: 0.85;
}

.app-nav-link:hover {
  background: var(--flex-sidebar-hover);
  color: var(--flex-sidebar-text-active);
}

.app-nav-link.active {
  background: var(--flex-sidebar-active);
  color: var(--flex-sidebar-text-active);
  font-weight: 600;
}

.app-nav-link.active i { opacity: 1; }

.app-nav-dev {
  margin-left: auto;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(234, 179, 8, 0.18);
  color: #eab308;
  flex-shrink: 0;
}

.app-nav-link .badge { margin-left: auto; }

.app-sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 0.72rem;
  color: #4b5563;
  flex-shrink: 0;
}

.app-sidebar-footer a { color: #6b7280; text-decoration: none; }
.app-sidebar-footer a:hover { color: #9ca3af; }

/* Content column */
.app-content {
  flex: 1;
  min-width: 0;
  margin-left: var(--flex-sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.app-topbar {
  height: var(--flex-topbar-height);
  background: var(--flex-surface);
  border-bottom: 1px solid var(--flex-border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.app-topbar-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--flex-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-topbar .navbar-nav { flex-direction: row; align-items: center; }
.app-topbar .nav-link { color: var(--flex-text); padding: 6px 10px; }

.app-sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.15rem;
  color: var(--flex-text);
  padding: 4px 8px;
  border-radius: 8px;
}

.app-sidebar-toggle:hover { background: var(--flex-bg); }

/* Main + footer */
.app-main {
  flex: 1;
  padding: 20px 24px 28px;
  width: 100%;
  max-width: 1700px;
  margin: 0 auto;
}

.app-footer {
  padding: 12px 24px;
  border-top: 1px solid var(--flex-border);
  color: var(--flex-text-muted);
  font-size: 0.78rem;
  background: var(--flex-surface);
}

/* Mobile: off-canvas sidebar */
.app-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  z-index: 1034;
}

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
  .app-sidebar.open { transform: translateX(0); }
  .app-sidebar-backdrop.show { display: block; }
  .app-content { margin-left: 0; }
  .app-sidebar-toggle { display: inline-flex; }
  .app-main { padding: 14px 14px 24px; }
}

/* Signed-out (login / registration) shell */
.app-anon {
  background: linear-gradient(160deg, #111827 0%, #1e1b4b 55%, #312e81 100%);
  min-height: 100vh;
}

.app-anon .app-anon-main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.app-anon-brand {
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-anon-card {
  width: 100%;
  max-width: 440px;
  background: var(--flex-surface);
  border-radius: 14px;
  box-shadow: var(--flex-shadow-lg);
  padding: 28px;
}

.app-anon-footer {
  margin-top: 16px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.75rem;
}
.app-anon-footer a { color: rgba(255, 255, 255, 0.75); }

/* ---------- Bootstrap component polish ---------- */

/* Buttons */
.btn {
  border-radius: var(--flex-radius-sm);
  font-weight: 500;
  --bs-btn-padding-y: 0.42rem;
}

.btn-primary {
  background-color: var(--flex-primary);
  border-color: var(--flex-primary);
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active,
.btn-primary:first-child:active, .btn-primary.active {
  background-color: var(--flex-primary-hover) !important;
  border-color: var(--flex-primary-hover) !important;
}

.btn-outline-primary { color: var(--flex-primary); border-color: var(--flex-primary); }
.btn-outline-primary:hover, .btn-outline-primary:active, .btn-outline-primary.active {
  background-color: var(--flex-primary) !important;
  border-color: var(--flex-primary) !important;
  color: #fff !important;
}

.btn-check:focus + .btn-primary, .btn-primary:focus,
.btn-check:focus + .btn-outline-primary, .btn-outline-primary:focus {
  box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.25);
}

/* Links & text helpers that reference bootstrap primary */
.text-primary { color: var(--flex-primary) !important; }
.bg-primary { background-color: var(--flex-primary) !important; }
.border-primary { border-color: var(--flex-primary) !important; }
.link-primary { color: var(--flex-primary) !important; }

/* Cards */
.card {
  border: 1px solid var(--flex-border);
  border-radius: var(--flex-radius);
  box-shadow: var(--flex-shadow-sm);
}

.card-header {
  background: var(--flex-surface);
  border-bottom: 1px solid var(--flex-border);
  font-weight: 600;
  border-top-left-radius: var(--flex-radius) !important;
  border-top-right-radius: var(--flex-radius) !important;
}

.card-header.bg-light { background: #fafbfc !important; }

/* Forms */
.form-control, .form-select {
  border-radius: var(--flex-radius-sm);
  border-color: #d1d5db;
}

.form-control:focus, .form-select:focus {
  border-color: var(--flex-primary);
  box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15);
}

.form-label { font-weight: 500; font-size: 0.85rem; }

.form-check-input:checked {
  background-color: var(--flex-primary);
  border-color: var(--flex-primary);
}

/* Tables */
.table {
  --bs-table-hover-bg: #f8fafc;
}

.table thead th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--flex-text-muted);
  border-bottom-width: 1px;
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}

.table > :not(caption) > * > * { padding: 0.55rem 0.6rem; }

/* Badges */
.badge { border-radius: 999px; font-weight: 600; letter-spacing: 0.01em; }

/* Modals */
.modal-content {
  border: none;
  border-radius: 14px;
  box-shadow: var(--flex-shadow-lg);
}

.modal-header { border-bottom: 1px solid var(--flex-border); }
.modal-footer { border-top: 1px solid var(--flex-border); }

/* Dropdowns */
.dropdown-menu {
  border: 1px solid var(--flex-border);
  border-radius: var(--flex-radius);
  box-shadow: var(--flex-shadow-lg);
  font-size: 0.875rem;
  padding: 6px;
}

.dropdown-item { border-radius: 6px; padding: 6px 10px; }
.dropdown-item:hover { background: var(--flex-primary-soft); }

/* Alerts */
.alert { border-radius: var(--flex-radius); }

/* Pagination */
.page-link { color: var(--flex-primary); }
.page-item.active .page-link {
  background-color: var(--flex-primary);
  border-color: var(--flex-primary);
}

/* Breadcrumbs */
.breadcrumb { font-size: 0.85rem; }

/* Nav tabs / pills */
.nav-pills .nav-link.active { background-color: var(--flex-primary); }
.nav-tabs .nav-link.active { border-bottom-color: var(--flex-surface); }
.nav-tabs .nav-link { color: var(--flex-text-muted); }
.nav-tabs .nav-link.active { color: var(--flex-text); font-weight: 600; }

/* Select2 alignment with the theme */
.select2-container--bootstrap-5 .select2-selection { border-radius: var(--flex-radius-sm) !important; }

/* Sticky page elements must clear the sticky topbar */
.app-shell .sticky-top { top: calc(var(--flex-topbar-height) + 8px); }
