/**
 * Admin shell layout: hero, full-width overrides, Django dashboard width fix.
 * Loaded on all pages extending templates/admin/base_site.html.
 */

:root {
  --brand-1: rgb(20, 43, 53);
  --brand-2: #161d31;
  --hero-fg: #ffffff;
  --bg: #f1f5f9;
  --text: #0f172a;
  color-scheme: light;
}

html[data-theme="dark"] {
  --brand-1: #1d3846;
  --brand-2: #11152c;
  --hero-fg: #e5e7eb;
  --bg: #0b1220;
  --text: #e5e7eb;
  color-scheme: dark;
}

html, body {
  margin: 0;
  padding: 0;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#container {
  max-width: 100%;
  width: 100%;
  min-width: 0;
  margin: 0;
  box-sizing: border-box;
}

#header,
#content {
  max-width: 100%;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

body.dashboard #content.colM {
  width: 100% !important;
  max-width: 100% !important;
  margin-right: 0 !important;
  float: none !important;
}

body.dashboard #content-main {
  float: none !important;
  width: 100% !important;
}

#header {
  padding: 0 !important;
}

#header:has(.crm-hero),
#header #branding:has(.crm-hero) {
  overflow: visible;
  position: relative;
  z-index: 40;
}

#branding {
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
}

#content-main {
  padding-left: clamp(16px, 3vw, 40px);
  padding-right: clamp(16px, 3vw, 40px);
  box-sizing: border-box;
}

.crm-hero {
  width: 100%;
  max-width: 100%;
  /* Must stay visible so the account dropdown can paint above breadcrumbs/content */
  overflow: visible;
  position: relative;
  z-index: 40;
  color: var(--hero-fg, #ffffff);
  /* Fixed MedInDepth brand shell — never tinted by accent (avoids yellow/gold bleed) */
  background:
    radial-gradient(1100px 520px at 85% -10%, #1f2937, transparent 60%),
    radial-gradient(900px 460px at -10% 0%, #0c172e, transparent 60%),
    linear-gradient(92deg, var(--brand-1) 0%, var(--brand-2) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  box-sizing: border-box;
}

/* Light mode: keep dark brand bar + white title (readable on all skins) */
html[data-theme="light"] .crm-hero {
  --hero-fg: #ffffff;
  background:
    radial-gradient(1100px 520px at 85% -10%, #1f2937, transparent 60%),
    radial-gradient(900px 460px at -10% 0%, #0c172e, transparent 60%),
    linear-gradient(92deg, var(--brand-1, rgb(20, 43, 53)) 0%, var(--brand-2, #161d31) 100%) !important;
  color: #ffffff !important;
  border-bottom-color: rgba(255, 255, 255, 0.15);
}

.crm-hero h1,
.crm-hero .crm-hero-title,
.crm-hero .crm-hero-org__label,
.crm-hero .crm-hero-org__badge,
.crm-hero .crm-hero-org__status,
.crm-hero .crm-hero-account__trigger,
.crm-hero .crm-hero-logo .fas,
.crm-hero .crm-hero-logo .fa-solid {
  color: var(--hero-fg, #ffffff) !important;
}

.crm-hero .btn-primary {
  color: var(--brand-2, #161d31) !important;
  background: #ffffff !important;
}

.crm-hero-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 auto;
  border-radius: 0.55rem;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

.crm-hero-logo .fas,
.crm-hero-logo .fa-solid {
  font-size: 1rem;
  line-height: 1;
}

.crm-hero-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.crm-hero-org {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: nowrap;
  min-width: 0;
  max-width: 15rem;
}

.crm-hero-org__label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.85;
  white-space: nowrap;
}

.crm-hero-org__label-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.crm-hero-org__select {
  min-width: 8.5rem;
  max-width: 13rem;
  width: auto;
  padding: 0.35rem 0.5rem;
  border-radius: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
}

.crm-hero-org__select:focus {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.crm-hero-org__status {
  font-size: 0.68rem;
  opacity: 0.95;
  white-space: nowrap;
}

.crm-hero-org__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 13rem;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-size: 0.75rem;
  font-weight: 600;
}

.crm-hero-org__badge--muted {
  opacity: 0.85;
}

.crm-hero-org__badge-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-hero .inner {
  width: 100%;
  box-sizing: border-box;
  padding: 0.7rem clamp(12px, 2.5vw, 40px);
  overflow: visible;
}

.crm-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: 0.6rem;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  box-sizing: border-box;
}

button.btn {
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

.crm-hero-logout-form {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
}

.btn-ghost {
  color: var(--hero-fg);
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  text-decoration: none;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-primary {
  background: var(--hero-fg);
  color: var(--bg);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-primary:hover {
  filter: brightness(0.96);
}

/* Account dropdown */
.crm-hero-account {
  position: relative;
  z-index: 50;
  flex: 0 0 auto;
}

.crm-hero-account__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 14rem;
  min-width: 0;
  padding: 0.28rem 0.55rem 0.28rem 0.28rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.1);
  color: var(--hero-fg, #fff);
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.crm-hero-account__trigger:hover,
.crm-hero-account.is-open .crm-hero-account__trigger {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.4);
}

.crm-hero-account__trigger:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.crm-hero-account__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a !important;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  flex: 0 0 auto;
}

.crm-hero-account__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 0;
}

.crm-hero-account__chevron {
  font-size: 0.65rem;
  opacity: 0.85;
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}

.crm-hero-account.is-open .crm-hero-account__chevron {
  transform: rotate(180deg);
}

.crm-hero-account__menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 1300;
  width: min(18.5rem, calc(100vw - 1.5rem));
  padding: 0.4rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(15, 23, 42, 0.1);
  background: #ffffff;
  color: #0f172a !important;
  box-shadow:
    0 12px 28px rgba(15, 23, 42, 0.18),
    0 2px 6px rgba(15, 23, 42, 0.08);
}

/* Beat Django #header link + light-hero white inheritance (Change password is an <a>) */
.crm-hero .crm-hero-account__menu,
.crm-hero .crm-hero-account__menu a,
.crm-hero .crm-hero-account__menu a:link,
.crm-hero .crm-hero-account__menu a:visited,
.crm-hero .crm-hero-account__menu a:hover,
.crm-hero .crm-hero-account__menu a:focus,
.crm-hero .crm-hero-account__menu button,
.crm-hero .crm-hero-account__menu .crm-hero-account__item,
.crm-hero .crm-hero-account__menu .crm-hero-account__header-user,
.crm-hero .crm-hero-account__menu .crm-hero-account__header-label,
.crm-hero .crm-hero-account__menu .crm-hero-account__theme-label,
.crm-hero .crm-hero-account__menu .fa-solid,
.crm-hero .crm-hero-account__menu .fas {
  color: #0f172a !important;
}

html[data-theme="dark"] .crm-hero-account__menu {
  background: #111827;
  color: #e5e7eb !important;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.45),
    0 2px 6px rgba(0, 0, 0, 0.3);
}

html[data-theme="dark"] .crm-hero .crm-hero-account__menu,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu a,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu a:link,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu a:visited,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu a:hover,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu a:focus,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu button,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu .crm-hero-account__item,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu .crm-hero-account__header-user,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu .crm-hero-account__header-label,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu .crm-hero-account__theme-label,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu .fa-solid,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu .fas {
  color: #e5e7eb !important;
}

.crm-hero-account__header {
  padding: 0.55rem 0.7rem 0.65rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  margin-bottom: 0.25rem;
}

html[data-theme="dark"] .crm-hero-account__header {
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

.crm-hero-account__header-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  opacity: 0.65;
}

.crm-hero-account__header-user {
  margin-top: 0.15rem;
  font-size: 0.86rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-hero-account__section,
.crm-hero-account__footer {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.crm-hero-account__footer {
  margin-top: 0.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
}

html[data-theme="dark"] .crm-hero-account__footer {
  border-top-color: rgba(255, 255, 255, 0.1);
}

.crm-hero-account__item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  margin: 0;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: inherit !important;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  box-sizing: border-box;
}

.crm-hero-account__item > .fa-solid,
.crm-hero-account__theme-label > .fa-solid {
  width: 1rem;
  text-align: center;
  opacity: 0.85;
  color: inherit !important;
  flex: 0 0 auto;
}

.crm-hero-account__item:hover,
.crm-hero-account__item:focus-visible {
  background: rgba(15, 23, 42, 0.06);
  outline: none;
}

html[data-theme="dark"] .crm-hero-account__item:hover,
html[data-theme="dark"] .crm-hero-account__item:focus-visible {
  background: rgba(255, 255, 255, 0.08);
}

.crm-hero-account__item.is-disabled,
.crm-hero-account__item:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.crm-hero-account__item.is-disabled:hover,
.crm-hero-account__item:disabled:hover {
  background: transparent;
}

.crm-hero-account__hint {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  opacity: 0.7;
}

.crm-hero-account__item--theme {
  justify-content: space-between;
  cursor: default;
}

.crm-hero-account__item--theme:hover {
  background: transparent;
}

.crm-hero-account__theme-label {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
}

.crm-hero .crm-hero-account__menu .crm-hero-account__item--danger,
.crm-hero .crm-hero-account__menu .crm-hero-account__item--danger .fa-solid {
  color: #b91c1c !important;
}

html[data-theme="dark"] .crm-hero .crm-hero-account__menu .crm-hero-account__item--danger,
html[data-theme="dark"] .crm-hero .crm-hero-account__menu .crm-hero-account__item--danger .fa-solid {
  color: #fca5a5 !important;
}

/* Reset admin appearance button chrome inside the menu */
.crm-hero-account__menu .btn-appearance {
  border: 0 !important;
  background: transparent !important;
  color: inherit !important;
  padding: 0.55rem 0.65rem !important;
  border-radius: 0.5rem !important;
  gap: 0.65rem !important;
  font-size: 0.84rem !important;
}

.crm-hero-account__menu .btn-appearance:hover {
  background: rgba(15, 23, 42, 0.06) !important;
}

html[data-theme="dark"] .crm-hero-account__menu .btn-appearance:hover {
  background: rgba(255, 255, 255, 0.08) !important;
}

.crm-hero .crm-hero-account__menu .theme-switch {
  width: 40px !important;
  height: 24px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(15, 23, 42, 0.2);
  background: rgba(15, 23, 42, 0.12);
  position: relative !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  left: auto !important;
  display: inline-block;
  flex: 0 0 auto;
  cursor: pointer;
  padding: 0;
  box-shadow: none !important;
  transform: none !important;
}

.crm-hero .crm-hero-account__menu .theme-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  transition: left 0.18s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.25);
}

html[data-theme="dark"] .crm-hero .crm-hero-account__menu .theme-switch {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.14);
}

html[data-theme="dark"] .crm-hero .crm-hero-account__menu .theme-switch::after {
  left: 18px;
  background: #e5e7eb;
}

.hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: nowrap;
  min-width: 0;
}

.cluster-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 0 1 auto;
}

.cluster-right {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0.75rem;
  flex: 1 1 auto;
  min-width: 0;
}

@media (max-width: 900px) {
  .crm-hero-account__name {
    display: none;
  }
  .crm-hero-account__trigger {
    padding-right: 0.4rem;
  }
  .crm-hero-org {
    max-width: 12rem;
  }
  .crm-hero-org__select {
    min-width: 7.5rem;
    max-width: 11rem;
  }
}

@media (max-width: 640px) {
  .hero-row {
    flex-wrap: wrap;
    gap: 0.65rem;
  }
  .cluster-right {
    width: 100%;
    justify-content: space-between;
    gap: 0.5rem;
  }
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.skip-link:focus {
  position: fixed;
  left: 1rem;
  top: 1rem;
  z-index: 1000;
  padding: 0.5rem 0.75rem;
  background: var(--hero-fg);
  color: var(--bg);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 0.5rem;
}
