/*
 * Tuli Admin — application shell + component overrides, mirroring
 * ui/frame's design language.
 *
 * Layout model (from ui/frame/src/styles/components/layout/*.scss):
 *   .app-shell           — full viewport, column flex
 *     .app-navbar        — 68px tall, deep navy
 *     .app-body          — row flex, fills remaining height
 *       .app-sidebar     — 79px wide icon column, deep navy
 *       .app-content     — scrollable canvas, 20px padding
 *
 * Bootstrap is loaded from CDN; we override only what's needed to match
 * ui/frame: cards, tables, forms, buttons, badges, pagination, modals.
 */

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--primary-font);
  color: var(--tuli-text);
  background: var(--tuli-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---- Shell -------------------------------------------------------------- */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-navbar {
  height: var(--navbar-height);
  background-color: var(--app-navbar-bg);
  color: var(--app-chrome-text);
  border-bottom: 1px solid var(--app-chrome-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.app-navbar .app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--light-side);
  text-decoration: none;
  font-weight: var(--fw-700);
  font-size: 16px;
  letter-spacing: 0.02em;
}

.app-navbar .app-brand .brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--sunflare-gradient);
  color: var(--light-side);
  font-size: 16px;
}

.app-navbar .navbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-navbar .navbar-title {
  font-family: var(--primary-font);
  font-weight: var(--fw-600);
  font-size: 14px;
  color: var(--app-chrome-text);
  margin-left: 8px;
}

.app-body {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

/* ---- Sidebar (ui/frame CollapsibleSidebar pattern) ---------------- */

:root {
  --sidebar-w-open:      256px;
  --sidebar-w-collapsed: 64px;
}

.app-sidebar {
  position: relative;
  background-color: var(--app-sidebar-bg);
  border-right: 1px solid var(--app-chrome-border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  gap: 4px;
  flex-shrink: 0;
  width: var(--sidebar-w-open);
  transition: width 240ms cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--app-chrome-text);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--app-chrome-border) transparent;
}
.app-sidebar::-webkit-scrollbar { width: 4px; }
.app-sidebar::-webkit-scrollbar-thumb { background: var(--app-chrome-border); border-radius: 4px; }

/* Make sure Bootstrap's collapse cleanly toggles when sidebar is open. */
.app-sidebar .collapse:not(.show) { display: none; }
.app-sidebar .collapsing { display: block; height: 0; overflow: hidden; transition: height 0.2s ease; }
.app-sidebar .collapse.show { display: block; }

[data-sidebar="collapsed"] .app-sidebar { width: var(--sidebar-w-collapsed); padding: 18px 8px; }

/* Anchored to .app-body (not inside the sidebar) so the sidebar's
 * overflow-x:hidden doesn't clip it. Position slides with the sidebar
 * width via custom property. */
.sidebar-toggle {
  position: absolute;
  top: 22px;
  left: calc(var(--sidebar-w-open) - 12px);
  z-index: 1050;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--app-navbar-bg);
  color: var(--app-chrome-text);
  border: 1px solid var(--app-chrome-border);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(13, 18, 22, 0.2);
  transition: background-color 0.15s ease, color 0.15s ease,
              left 240ms cubic-bezier(0.16, 1, 0.3, 1);
}
[data-sidebar="collapsed"] .sidebar-toggle {
  left: calc(var(--sidebar-w-collapsed) - 12px);
}
.sidebar-toggle:hover { background: var(--app-chrome-control-hover); color: var(--app-chrome-text-strong); }
.sidebar-toggle i { font-size: 12px; line-height: 1; }
[data-sidebar="open"]      .sidebar-toggle .chev-expand,
[data-sidebar="collapsed"] .sidebar-toggle .chev-collapse { display: none; }

.app-content {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--tuli-canvas);
  color: var(--tuli-text);
}

/* ---- Sidebar nav groups (CollapsibleMenu pattern) ----------------- */

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}

.nav-group .collapsible-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--app-chrome-text);
  text-align: left;
  cursor: pointer;
  font-family: var(--primary-font);
  font-weight: var(--fw-600);
  font-size: 14px;
  line-height: 17px;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.nav-group .collapsible-button .icon-container {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  flex-shrink: 0;
  color: var(--app-chrome-text);
}
.nav-group .collapsible-button .icon-container i { font-size: 17px; line-height: 1; }
.nav-group .collapsible-button .collapsible-label { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-group .collapsible-button .chev-toggle {
  font-size: 12px;
  color: var(--app-chrome-text);
  transition: transform 0.18s ease;
}
.nav-group .collapsible-button[aria-expanded="true"] .chev-toggle { transform: rotate(180deg); }

.nav-group .collapsible-button:hover {
  background: var(--app-chrome-hover);
  color: var(--app-chrome-text-strong);
}
.nav-group .collapsible-button:hover .icon-container { color: var(--app-chrome-text-strong); }

.nav-group.is-active > .collapsible-button {
  background: var(--app-chrome-active);
}
.nav-group.is-active > .collapsible-button .icon-container,
.nav-group.is-active > .collapsible-button .collapsible-label,
.nav-group.is-active > .collapsible-button .chev-toggle { color: var(--app-chrome-text-strong); }

/* Sub-items list */
.collapsible-content {
  list-style: none;
  margin: 4px 0 6px;
  padding: 0 0 0 28px;
  border-left: 1px solid var(--app-chrome-border);
  margin-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.collapsible-content li a {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  font-family: var(--primary-font);
  font-weight: var(--fw-500);
  font-size: 13px;
  line-height: 17px;
  color: var(--app-chrome-text);
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.collapsible-content li a:hover { color: var(--app-chrome-text-strong); background: var(--app-chrome-hover); }
.collapsible-content li a.active {
  color: var(--app-chrome-accent);
  background: rgba(229, 107, 162, 0.10);
  font-weight: var(--fw-700);
}

/* ---- Collapsed sidebar (icon-only) ------------------------------- */

[data-sidebar="collapsed"] .app-sidebar .collapsible-label,
[data-sidebar="collapsed"] .app-sidebar .chev-toggle,
[data-sidebar="collapsed"] .app-sidebar .collapse,
[data-sidebar="collapsed"] .app-sidebar .collapsing { display: none !important; }

[data-sidebar="collapsed"] .nav-group .collapsible-button {
  justify-content: center;
  padding: 9px 0;
}
[data-sidebar="collapsed"] .nav-group .collapsible-button .icon-container {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--app-chrome-control);
  color: var(--app-chrome-text);
}
[data-sidebar="collapsed"] .nav-group .collapsible-button:hover .icon-container,
[data-sidebar="collapsed"] .nav-group.is-active > .collapsible-button .icon-container {
  background: var(--app-chrome-active);
  color: var(--app-chrome-text-strong);
  box-shadow: 0 0 16px 0 rgba(229, 107, 162, 0.35);
}

/* ---- Tooltip (sidebar labels in collapsed mode) ------------------ */

/* Override Bootstrap's tooltip CSS variables so the bubble AND the arrow
 * (which Bootstrap colors from --bs-tooltip-bg) flip together per theme. */
.tooltip {
  --bs-tooltip-opacity: 1;
  --bs-tooltip-bg:    #ffffff;
  --bs-tooltip-color: #0D1216;
}
[data-theme="dark"] .tooltip {
  --bs-tooltip-bg:    #1A2026;
  --bs-tooltip-color: #F2F3F5;
}
.tooltip-inner {
  background-color: var(--bs-tooltip-bg) !important;
  color:            var(--bs-tooltip-color) !important;
  font-family: var(--primary-font);
  font-weight: var(--fw-600);
  font-size: 13px;
  line-height: 17px;
  padding: 7px 12px;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(13, 18, 22, 0.18);
  max-width: 240px;
  border: 1px solid var(--gray-300);
}
[data-theme="dark"] .tooltip-inner {
  border-color: #2F3942;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* ---- Navbar widgets --------------------------------------------------- */

.navbar-icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; background: transparent;
  border-radius: 50%;
  color: var(--app-chrome-text);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.navbar-icon-btn:hover { background: var(--app-chrome-hover); color: var(--app-chrome-text-strong); }
.navbar-icon-btn i { font-size: 18px; }

[data-theme="light"] .navbar-icon-btn .icon-dark,
[data-theme="dark"]  .navbar-icon-btn .icon-light { display: none; }

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--app-chrome-control);
  color: var(--app-chrome-text);
  border: 0;
  cursor: pointer;
  font-family: var(--primary-font);
  font-size: 13px;
  font-weight: var(--fw-600);
}
.user-pill:hover { background: var(--app-chrome-control-hover); color: var(--app-chrome-text-strong); }
.user-pill .avatar {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--rose-lemonade);
  color: var(--light-side);
  font-weight: var(--fw-700);
}

/* ---- Page header / title --------------------------------------------- */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-heading {
  margin: 0;
  font-family: var(--primary-font);
  font-weight: var(--fw-700);
  font-size: 20px;
  line-height: 24.2px;
  background: var(--sunflare-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.page-subheading {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 18px;
  color: var(--gray-500);
}

/* ---- Cards ------------------------------------------------------------ */

.card {
  border: 1px solid var(--tuli-border) !important;
  border-radius: var(--tuli-radius-md) !important;
  background: var(--tuli-surface) !important;
  color: var(--tuli-text);
  box-shadow: none;
}
.card-body { color: var(--tuli-text); }

/* ---- Tables (ui/frame dynamic-table pattern) ------------------------- */

.table {
  --bs-table-bg: var(--tuli-surface);
  --bs-table-color: var(--tuli-text);
  --bs-table-border-color: var(--gray-300);
  --bs-table-hover-bg: var(--gray-100);
  color: var(--tuli-text);
  margin-bottom: 0;
  border-collapse: collapse;
}

.table > thead th {
  background-color: var(--gray-300);
  color: var(--tuli-text);
  font-family: var(--primary-font);
  font-weight: var(--fw-600);
  font-size: 10px;
  line-height: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 0;
  padding: 8px 12px;
}
[data-theme="dark"] .table > thead th { background: var(--gray-200); color: var(--gray-700); }

.table > thead th:first-child { border-top-left-radius:  4px; }
.table > thead th:last-child  { border-top-right-radius: 4px; }

.table > tbody > tr > td {
  font-family: var(--primary-font);
  font-weight: var(--fw-400);
  font-size: 13px;
  line-height: 18px;
  color: var(--tuli-text);
  /* padding: 10px 12px; */
  border-top: 0;
  border-bottom: 1px solid var(--gray-300);
  background: transparent;
}
.table > tbody > tr:hover > td { background-color: var(--gray-100); }
[data-theme="dark"] .table > tbody > tr:hover > td { background-color: var(--gray-200); }

.table-compact th,
.table-compact td { padding: 8px 12px; font-size: 13px; }

/* ---- Buttons (ui/frame button.module.scss) --------------------------- */

.btn {
  border-radius: var(--tuli-radius-sm);
  font-family: var(--primary-font);
  font-weight: var(--fw-600);
  font-size: 13px;
  line-height: 18px;
  letter-spacing: 0;
}

.btn-primary {
  --bs-btn-bg:                  var(--rose-lemonade);
  --bs-btn-border-color:        var(--rose-lemonade);
  --bs-btn-hover-bg:            var(--rose-lemonade-light);
  --bs-btn-hover-border-color:  var(--rose-lemonade-light);
  --bs-btn-active-bg:           var(--pink-dark);
  --bs-btn-active-border-color: var(--pink-dark);
  --bs-btn-color:               var(--light-side);
  --bs-btn-hover-color:         var(--light-side);
  --bs-btn-active-color:        var(--light-side);
  --bs-btn-disabled-bg:         var(--gray-400);
  --bs-btn-disabled-border-color: var(--gray-400);
}

.btn-outline-primary {
  --bs-btn-color:              var(--rose-lemonade);
  --bs-btn-border-color:       var(--rose-lemonade);
  --bs-btn-hover-bg:           var(--rose-lemonade-light);
  --bs-btn-hover-border-color: var(--rose-lemonade-light);
  --bs-btn-hover-color:        var(--light-side);
  --bs-btn-active-bg:          var(--rose-lemonade);
  --bs-btn-active-border-color: var(--rose-lemonade);
  --bs-btn-active-color:       var(--light-side);
}

.btn-outline-secondary {
  --bs-btn-color:              var(--gray-700);
  --bs-btn-border-color:       var(--gray-300);
  --bs-btn-hover-bg:           var(--gray-100);
  --bs-btn-hover-border-color: var(--gray-400);
  --bs-btn-hover-color:        var(--tuli-text);
}

.btn-success {
  --bs-btn-bg:           var(--wimbledon-100);
  --bs-btn-border-color: var(--wimbledon-100);
  --bs-btn-hover-bg:     var(--wimbledon-75);
  --bs-btn-hover-border-color: var(--wimbledon-75);
}

.btn-outline-warning {
  --bs-btn-color:        var(--graph-3);
  --bs-btn-border-color: var(--graph-3);
  --bs-btn-hover-bg:     var(--graph-3);
  --bs-btn-hover-color:  var(--light-side);
}

.btn-outline-danger {
  --bs-btn-color:        var(--bloody-75);
  --bs-btn-border-color: var(--bloody-75);
  --bs-btn-hover-bg:     var(--bloody-75);
  --bs-btn-hover-color:  var(--light-side);
}

/* ---- Form controls (ui/frame Input) ---------------------------------- */

.form-control,
.form-select {
  font-family: var(--primary-font);
  font-size: 14px;
  line-height: 18px;
  padding: 9px 12px;
  background-color: var(--tuli-surface);
  color: var(--tuli-text);
  border: 1px solid var(--gray-400);
  border-radius: var(--tuli-radius-md);
  box-shadow: none;
}
/* Reserve room on the right edge of every <select.form-select> for the caret
 * SVG (which Bootstrap renders via background-image at `right 0.75rem`). The
 * shorthand padding above wipes Bootstrap's caret-aware padding, so without
 * this the arrow overlaps the selected option text — especially on
 * `style="width:auto"` selects (pagination size pickers, datetime mode
 * dropdown, query-editor target picker). */
.form-select                  { padding-right: 2.25rem; }
.form-select.form-select-sm   { padding: 4px 1.75rem 4px 8px; line-height: 18px; }
.form-select.form-select-lg   { padding: 12px 2.5rem 12px 16px; }
.form-control:focus,
.form-select:focus {
  border-color: var(--bluesky-60);
  box-shadow: 0 0 4px 0 var(--bluesky-25);
}
.form-control::placeholder { color: var(--gray-500); }
.form-label.small { color: var(--gray-600); font-weight: var(--fw-500); }

/* ---- Badges (status pills) ------------------------------------------ */

.badge {
  font-family: var(--primary-font);
  font-weight: var(--fw-600);
  font-size: 11px;
  line-height: 14px;
  letter-spacing: 0.02em;
  border-radius: var(--tuli-radius-sm);
  padding: 4px 8px;
}
.text-bg-success { background-color: var(--wimbledon-10) !important; color: var(--wimbledon-100) !important; }
.text-bg-danger  { background-color: var(--bloody-10)    !important; color: var(--bloody-100)    !important; }
.text-bg-warning { background-color: var(--mustard-10)   !important; color: var(--mustard-100)   !important; }
.text-bg-info    { background-color: var(--bluesky-10)   !important; color: var(--bluesky-75)    !important; }
.text-bg-light   { background-color: var(--gray-100)     !important; color: var(--gray-700)      !important; }
.text-bg-secondary { background-color: var(--gray-200)   !important; color: var(--gray-700)      !important; }

/* ---- Pagination ----------------------------------------------------- */

.pagination .page-link {
  font-family: var(--secondary-font);
  font-size: 13px;
  line-height: 18px;
  background: transparent;
  border: 0;
  color: var(--bluesky-60);
  padding: 4px 10px;
  border-radius: 4px;
}
.pagination .page-link:hover { background: var(--gray-100); color: var(--bluesky-75); }
.pagination .page-item.active .page-link {
  background: var(--gray-100);
  color: var(--rose-lemonade);
  font-weight: var(--fw-700);
}
.pagination .page-item.disabled .page-link { color: var(--gray-400); }

/* ---- Alerts --------------------------------------------------------- */

.alert {
  border-radius: var(--tuli-radius-md);
  border: 1px solid transparent;
  font-size: 13px;
}
.alert-info    { background: var(--bluesky-10);    color: var(--bluesky-75); }
.alert-danger  { background: var(--bloody-5);      color: var(--bloody-100); }
.alert-success { background: var(--wimbledon-10);  color: var(--wimbledon-100); }

/* ---- Dropdowns / modals --------------------------------------------- */

.dropdown-menu {
  background: var(--tuli-surface);
  border: 1px solid var(--gray-300);
  border-radius: var(--tuli-radius-md);
  box-shadow: var(--tuli-shadow-md);
  padding: 6px;
}
.dropdown-item { color: var(--tuli-text); border-radius: var(--tuli-radius-sm); padding: 6px 10px; font-size: 13px; }
.dropdown-item:hover { background: var(--gray-100); color: var(--tuli-text); }

.modal-content {
  background: var(--tuli-surface);
  color: var(--tuli-text);
  border: 1px solid var(--gray-300);
  border-radius: var(--tuli-radius-lg);
}
.modal-header, .modal-footer { border-color: var(--gray-300); }
.modal-title { font-weight: var(--fw-700); font-size: 16px; }

/* ---- Off-canvas (mobile sidebar) ------------------------------------ */

.offcanvas { background: var(--app-sidebar-bg); color: var(--app-chrome-text); }
.offcanvas-header { border-color: var(--app-chrome-border); }

/* ---- Auth (login) shell -------------------------------------------- */

.auth-page-body { background: var(--gray-25); }
.auth-card {
  width: 100%;
  max-width: 380px;
  border-radius: var(--tuli-radius-lg);
  border: 1px solid var(--gray-300);
  background: var(--light-side);
}
.auth-card h1 {
  font-size: 20px;
  font-weight: var(--fw-700);
  text-align: center;
  background: var(--sunflare-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 4px;
}
.auth-card .auth-subtitle { text-align: center; color: var(--gray-500); font-size: 13px; margin-bottom: 18px; }

/* ---- Mobile --------------------------------------------------------- */

@media (max-width: 767.98px) {
  .app-sidebar { display: none; }
  .app-content { padding: 16px; }
}
