/* ===================================================================
   Admin Shell — CSS variables & topbar (matches shop.fixmytech.no/admin)
   =================================================================== */

/* === Light theme (default) === */
:root {
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --background-color: #f4f7fb;
  --surface-color: #ffffff;
  --surface-muted: #eef4fb;
  --text-color: #1f2937;
  --heading-color: #0f172a;
  --muted-text: #526173;
  --border-color: #d9e2ee;
  --border-strong: #c5d5e7;
  --line: rgba(15, 23, 42, 0.08);
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.06);
  --card-surface: rgba(255, 255, 255, 0.88);
  --card-surface-strong: rgba(255, 255, 255, 0.92);
  --glass-border: rgba(255, 255, 255, 0.72);
  --glass-surface: rgba(255, 255, 255, 0.82);
}

/* === Dark theme === */
html[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-strong: #3b82f6;
  --background-color: #07111f;
  --surface-color: #0f1b2e;
  --surface-muted: #13233a;
  --text-color: #d9e4f2;
  --heading-color: #f8fafc;
  --muted-text: #91a4bb;
  --border-color: #26384f;
  --border-strong: #35506f;
  --shadow: 0 20px 50px rgba(2, 6, 23, 0.36);
  --shadow-soft: 0 10px 26px rgba(2, 6, 23, 0.28);
  --card-surface: rgba(12, 22, 36, 0.88);
  --card-surface-strong: rgba(12, 22, 36, 0.94);
  --glass-border: rgba(148, 163, 184, 0.16);
  --glass-surface: rgba(10, 18, 31, 0.82);
}

/* === Base overrides === */
*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--background-color);
  color: var(--text-color);
}

/* === Admin shell wrapper === */
.admin-shell {
  min-height: 100vh;
}

/* === Main content — clear the sticky topbar === */
.admin-shell #main-content {
  padding-top: 4.5rem;
}

/* Admin pages have no hero — let the first section sit close under the topbar */
.admin-shell .subpage-main-section {
  padding-top: 1rem;
}

/* === Admin topbar === */
.admin-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 0;
  width: 100%;
  background: var(--background-color);
  border-bottom: 1px solid var(--border-color);
  box-sizing: border-box;
}

.admin-topbar-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 1.5rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

/* === Brand — matches Shop's .brand / .admin-brand rules verbatim === */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
}

.brand strong {
  color: var(--heading-color);
}

.brand small {
  display: block;
  color: var(--muted-text);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: 1rem;
  background: linear-gradient(135deg, var(--primary), #60a5fa);
  color: #ffffff;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32);
}

.brand-mark svg {
  width: 1.45rem;
  height: 1.45rem;
  fill: currentColor;
}

html[data-theme="dark"] .brand-mark {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* text-decoration/color reset kept so the anchor renders like Shop's brand */
.admin-brand {
  margin: 0;
  flex: 0 0 auto;
  text-decoration: none;
  color: inherit;
}

.admin-brand > span:last-child {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 3rem;
}

.admin-brand strong {
  display: block;
  line-height: 1.1;
}

/* === Tab bar === */
.admin-tabbar {
  display: flex;
  gap: 0.85rem;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
}

.admin-tab-item {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.admin-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-height: 3.25rem;
  padding: 0 1.25rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted-text);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease;
}

.admin-tab.is-active {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

/* === Tab dropdown menus === */
.admin-tab-trigger {
  gap: 0.4rem;
}

.admin-tab-caret {
  font-size: 0.65rem;
  opacity: 0.7;
}

/* Invisible bridge so the menu stays open while moving the cursor onto it. */
.admin-tab-item:has(.admin-tab-menu)::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: 0.6rem;
}

.admin-tab-item.is-active .admin-tab-trigger {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

.admin-tab-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  min-width: 13rem;
  padding: 0.4rem;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--card-surface-strong);
  box-shadow: var(--shadow-soft);
  display: grid;
  gap: 0.15rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
  z-index: 1100;
}

.admin-tab-item:hover .admin-tab-menu,
.admin-tab-item:focus-within .admin-tab-menu,
.admin-tab-item.is-open .admin-tab-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.admin-tab-menu-link {
  display: block;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: transparent;
  color: var(--heading-color);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.admin-tab-menu-link:hover,
.admin-tab-menu-link:focus-visible {
  background: var(--surface-muted);
  outline: none;
}

.admin-tab-menu-link.is-active {
  background: var(--surface-muted);
  color: var(--primary-strong);
}

.admin-tab-external {
  border: 1px solid var(--border-color);
  background: var(--card-surface);
  color: var(--heading-color);
  font-size: 0.85rem;
}

.admin-tab-external:hover {
  background: var(--surface-muted);
  color: var(--heading-color);
}

/* === Mobile nav toggle === */
.admin-nav-toggle {
  display: none;
  flex: 0 0 auto;
}

.site-nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.18rem;
  width: 2.9rem;
  height: 2.9rem;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  background: var(--card-surface);
  color: var(--heading-color);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.site-nav-toggle span {
  display: block;
  width: 1.1rem;
  height: 2px;
  margin: 0;
  border-radius: 999px;
  background: currentColor;
}

/* === Profile / theme dropdown === */
.theme-dropdown {
  position: relative;
  flex: 0 0 auto;
}

.theme-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.6rem;
  padding: 0 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--card-surface);
  color: var(--heading-color);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.theme-dropdown-trigger svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
  flex-shrink: 0;
}

/* === Round icon button (matches Shop's .profile-button) ===
   Used for the search trigger, app switcher, and account/theme menu.
   When combined with .theme-dropdown-trigger the fixed 2.9rem box wins,
   so the control renders as a circle regardless of the pill padding. */
.profile-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 2.9rem;
  height: 2.9rem;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--heading-color);
  box-shadow: none;
  cursor: pointer;
  flex: 0 0 auto;
}

.profile-button svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: currentColor;
  flex-shrink: 0;
}

.theme-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  min-width: 11rem;
  padding: 0.45rem;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  background: var(--card-surface-strong);
  box-shadow: var(--shadow-soft);
  z-index: 40;
}

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

.dropdown-section-title {
  margin: 0;
  padding: 0.45rem 0.85rem 0.35rem;
  color: var(--muted-text);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dropdown-divider {
  height: 1px;
  margin: 0.35rem 0.45rem;
  background: var(--border-color);
}

/* Signed-in identity line at the top of the account menu (set by *-nav.js).
   Unlike .dropdown-section-title this is not uppercased, so emails stay legible. */
.dropdown-account-label {
  margin: 0;
  padding: 0.5rem 0.85rem;
  max-width: 16rem;
  color: var(--heading-color);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-dropdown-option {
  display: block;
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--heading-color);
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  text-decoration: none;
}

.theme-dropdown-option:hover,
.theme-dropdown-option:focus-visible,
.theme-dropdown-option.is-active {
  background: var(--surface-muted);
  outline: none;
}

.theme-dropdown-option.is-active {
  font-weight: 700;
}

/* === App switcher === */
.app-switcher-trigger {
  padding: 0 0.75rem;
}

.app-switcher-menu {
  min-width: 13rem;
}

.app-switcher-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  background: transparent;
  color: var(--heading-color);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.app-switcher-item:hover,
.app-switcher-item:focus-visible {
  background: var(--surface-muted);
  outline: none;
}

.app-switcher-item i {
  width: 1.15rem;
  text-align: center;
  color: var(--muted-text);
}

.app-switcher-item.is-current {
  background: var(--surface-muted);
  color: var(--primary-strong);
  cursor: default;
}

.app-switcher-item.is-current i {
  color: var(--primary-strong);
}

/* === Responsive === */
/* === Collapsed (hamburger) nav — matches Shop's is-collapsed header verbatim.
   Applied via @media at Shop's 1024px breakpoint so the collapse is instant
   (no post-paint flash). JS toggles .is-open/.is-nav-open to open the panel. === */
@media (max-width: 1024px) {
  body.admin-nav-open {
    overflow: hidden;
  }

  .admin-topbar-row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .admin-topbar-row .admin-brand {
    margin-right: auto;
  }

  .admin-topbar-row .theme-dropdown {
    order: 3;
  }

  .admin-topbar-row .admin-tabbar {
    display: flex;
    flex-wrap: nowrap;
    position: absolute;
    top: calc(100% + 0.75rem);
    right: 0;
    left: auto;
    width: max-content;
    min-width: min(13.5rem, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
    padding: 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    background: var(--card-surface-strong);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(16px);
    z-index: 25;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.35rem;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-0.35rem) scale(0.98);
    transform-origin: top right;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
  }

  .admin-topbar-row.is-nav-open .admin-tabbar,
  .admin-topbar-row .admin-tabbar.is-open {
    position: fixed;
    top: var(--admin-nav-panel-top, 5.75rem);
    left: auto;
    right: 1rem;
    width: min(32rem, calc(100vw - 2rem));
    min-width: 0;
    max-width: calc(100vw - 2rem);
    max-height: calc(100dvh - var(--admin-nav-panel-top, 5.75rem) - 1rem);
    z-index: 600;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transform-origin: top right;
  }

  .admin-topbar.is-nav-open,
  .admin-topbar-row.is-nav-open {
    z-index: 550;
  }

  .admin-topbar-row.is-nav-open .admin-tab-item {
    justify-items: center;
  }

  .admin-topbar-row.is-nav-open .admin-tab,
  .admin-topbar-row.is-nav-open .admin-tab-link,
  .admin-topbar-row.is-nav-open .admin-tab-menu-link {
    justify-content: center;
    text-align: center;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .admin-topbar-row.is-nav-open .admin-tab,
  .admin-topbar-row.is-nav-open .admin-tab-link {
    font-size: 1.12rem;
    font-weight: 800;
    min-height: 3.35rem;
  }

  .admin-topbar-row.is-nav-open .admin-tab-menu-link {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.35;
  }

  .admin-topbar-row.is-nav-open .admin-tab-menu,
  .admin-topbar-row.is-nav-open .dropdown-section-title {
    text-align: center;
  }

  .admin-topbar-row.is-nav-open .admin-tab-menu-group,
  .admin-topbar-row.is-nav-open .dropdown-section-title {
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.12em;
  }

  .admin-topbar-row .admin-nav-toggle {
    display: inline-flex;
    order: 2;
    margin-left: 0;
    position: relative;
    z-index: 30;
  }

  .admin-topbar-row .admin-tab-item,
  .admin-topbar-row .admin-tab {
    width: 100%;
  }

  .admin-topbar-row .admin-tab-item {
    display: grid;
    padding-bottom: 0;
    margin-bottom: 0;
    width: 100%;
  }

  .admin-topbar-row .admin-tab-item + .admin-tab-item {
    padding-top: 0.35rem;
    border-top: 0;
  }

  .admin-topbar-row .admin-tab-item::after {
    display: none;
  }

  .admin-topbar-row .admin-tab {
    justify-content: flex-start;
    min-height: 3rem;
    padding: 0 0.4rem 0 0.85rem;
    border-radius: 16px;
    text-align: left;
    background: transparent;
    box-shadow: none;
    border: 0;
  }

  .admin-topbar-row .admin-tab-menu {
    position: static;
    min-width: 0;
    width: 100%;
    margin-top: 0.3rem;
    padding: 0.25rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    transition: none;
  }

  .admin-topbar-row .admin-tab-link {
    margin-left: 0;
    width: 100%;
    min-height: 3rem;
    border-radius: 16px;
    justify-content: flex-start;
    text-align: left;
    background: transparent;
    box-shadow: none;
    border: 0;
  }

  .admin-topbar-row .admin-tab-menu-link {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    padding: 0.75rem 0.4rem 0.75rem 0.85rem;
  }

  .admin-topbar-row .admin-tab.is-active,
  .admin-topbar-row .admin-tab-item.is-active .admin-tab:not(.admin-tab-link),
  .admin-topbar-row .admin-tab:hover,
  .admin-topbar-row .admin-tab:focus-visible,
  .admin-topbar-row .admin-tab-menu-link:hover,
  .admin-topbar-row .admin-tab-menu-link:focus-visible,
  .admin-topbar-row .admin-tab-link:hover,
  .admin-topbar-row .admin-tab-link:focus-visible {
    background: transparent;
    box-shadow: none;
    border: 0;
    outline: none;
  }

  .admin-topbar-row .admin-tab-menu-link.is-active {
    background: var(--surface-muted) !important;
    color: var(--primary) !important;
    border-radius: 12px;
  }

  .admin-topbar-row .theme-dropdown-menu,
  .admin-topbar-row .theme-dropdown-option,
  .admin-topbar-row .dropdown-section-title {
    text-align: left;
  }

  .admin-topbar-row .theme-dropdown-option {
    justify-content: flex-start;
  }

  .admin-shell #main-content {
    padding-top: 4.5rem;
  }
}

@media (max-width: 480px) {
  .admin-topbar {
    padding: 0 0.75rem;
  }

  .admin-brand strong {
    font-size: 0.85rem;
  }

  .admin-brand small {
    display: none;
  }
}

/* === Dark-mode scoped overrides ===
   theme.css sets CSS vars on body.dark-mode (closer in DOM than html),
   so we override at the component level to ensure the shop-style palette applies
   to the topbar and admin shell background. */

/* Page background: override body.dark-mode's solid color with the gradient */
html[data-theme="dark"] body.admin-shell {
  background: var(--background-color);
}

/* Topbar: re-declare the dark palette on the row so child elements inherit it,
   overriding any body-level variable from theme.css */
html[data-theme="dark"] .admin-topbar-row {
  --primary: #60a5fa;
  --primary-strong: #3b82f6;
  --glass-border: rgba(148, 163, 184, 0.16);
  --glass-surface: rgba(10, 18, 31, 0.82);
  --card-surface: rgba(12, 22, 36, 0.88);
  --card-surface-strong: rgba(12, 22, 36, 0.94);
  --surface-muted: #13233a;
  --heading-color: #f8fafc;
  --muted-text: #91a4bb;
  --border-color: #26384f;
}

/* === Global search dialog ===
   Header search-trigger opens this native <dialog>. Queries /api/search
   (FTS5-backed) and lets you jump to the matching record. */
.admin-search-dialog {
  padding: 0;
  border: none;
  background: transparent;
  max-width: 100vw;
  max-height: 100vh;
  color: var(--text-color);
  overflow: visible;
}

.admin-search-dialog::backdrop {
  background: rgba(8, 15, 30, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.admin-search-shell {
  width: min(94vw, 46rem);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(2, 6, 23, 0.45);
}

.admin-search-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.admin-search-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 3.25rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--surface-muted);
  color: var(--heading-color);
  font: inherit;
}

.admin-search-input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.admin-search-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  height: 2.6rem;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--muted-text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.admin-search-close:hover {
  background: var(--surface-muted);
  color: var(--heading-color);
}

.admin-search-results {
  display: grid;
  gap: 0.9rem;
  overflow-y: auto;
}

.admin-search-group-title {
  margin: 0 0 0.35rem;
  color: var(--muted-text);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.admin-search-group {
  display: grid;
  gap: 0.4rem;
}

.admin-search-result {
  display: grid;
  gap: 0.25rem;
  width: 100%;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--card-surface);
  color: var(--heading-color);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.admin-search-result:hover,
.admin-search-result:focus-visible {
  border-color: var(--primary);
  background: var(--surface-muted);
  outline: none;
}

.admin-search-result strong {
  font-size: 0.96rem;
  font-weight: 700;
}

.admin-search-result span {
  color: var(--muted-text);
  font-size: 0.88rem;
  line-height: 1.35;
}

.admin-search-empty {
  margin: 0;
  padding: 0.5rem 0.2rem;
  color: var(--muted-text);
  font-size: 0.92rem;
}

/* Record landed on via search ?focus=<id> — brief highlight pulse.
   Animates both box-shadow (cards) and background (table rows) so it shows
   regardless of the element type. */
.search-focus-flash {
  animation: search-focus-pulse 2.2s ease-out 1;
}

.search-focus-flash > td {
  animation: search-focus-bg 2.2s ease-out 1;
}

@keyframes search-focus-pulse {
  0%, 25% {
    box-shadow: 0 0 0 2px var(--primary), 0 0 0 6px rgba(37, 99, 235, 0.18);
    background: var(--surface-muted);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
  }
}

@keyframes search-focus-bg {
  0%, 25% { background: rgba(37, 99, 235, 0.14); }
  100% { background: transparent; }
}
