/* SUMERAI base layer. Every value comes from tokens.css; no literals here. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: clip;
}

html {
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  background: var(--page-bg);
  color: var(--page-fg);
  font-family: var(--font-arabic);
  font-size: var(--type-body);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  caret-color: var(--fayrouz-700);
}

:lang(en) {
  font-family: var(--font-latin);
}

h1,
h2,
h3,
p,
ul,
ol,
dl,
dd,
figure {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

img,
svg {
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

::selection {
  background: var(--fayrouz-200);
  color: var(--ink);
}

:focus-visible {
  outline: var(--focus-ring-width) solid var(--action-fayrouz);
  outline-offset: 2px;
}

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

.skip-link:focus-visible {
  position: fixed;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--space-2);
  z-index: 10;
  width: auto;
  height: auto;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: var(--surface-stone);
  color: var(--text-ink);
  border-radius: var(--radius-control);
  text-decoration: none;
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-3);
}

.night {
  background: var(--surface-night);
}

/* ---------- Display scale (login, errors, empty states) ---------- */

h1 {
  font-size: var(--type-h1);
  line-height: var(--leading-head);
  letter-spacing: var(--tracking-latin-head);
  font-weight: 600;
  text-wrap: balance;
}

h2 {
  font-size: var(--type-h2);
  line-height: var(--leading-head);
  letter-spacing: var(--tracking-latin-head);
  font-weight: 600;
  text-wrap: balance;
}

h3 {
  font-size: var(--type-h3);
  line-height: var(--leading-head);
  font-weight: 600;
}

:lang(ar) h1,
:lang(ar) h2,
:lang(ar) h3 {
  letter-spacing: 0;
}

.eyebrow,
.wordmark {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: var(--tracking-display);
}

.eyebrow {
  font-size: var(--type-eyebrow);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: var(--target-min);
  min-width: var(--target-min);
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font: inherit;
  font-size: var(--app-body);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform var(--dur-press) var(--ease-out),
    background-color var(--dur-control) var(--ease-out),
    border-color var(--dur-control) var(--ease-out);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--action-fayrouz);
  color: var(--action-fayrouz-ink);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--surface-raised);
  border-color: var(--line-strong);
  color: var(--text-ink);
}

.btn-quiet {
  background: transparent;
  border-color: var(--line-night);
  color: var(--text-warm-white);
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover {
    background: var(--fayrouz-400);
  }
  .btn-secondary:hover {
    border-color: var(--ink-muted);
  }
  .btn-quiet:hover {
    border-color: var(--text-warm-muted);
  }
}

/* 44px minimum touch targets for inline chrome. */
nav a,
.lang-switch a,
.biz-switcher a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target-min);
  min-width: var(--target-min);
}

/* ---------- Form fields (login + settings renderer) ---------- */

.field {
  display: block;
  margin-block-end: var(--space-3);
}

.field-label,
.field > label {
  display: block;
  margin-block-end: var(--space-1);
  font-size: var(--app-small);
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: var(--target-min);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-clay);
  border-radius: var(--radius-control);
  background: var(--field-bg);
  color: var(--field-fg);
  font: inherit;
  font-size: var(--app-body);
  line-height: var(--leading-ui);
}

.field textarea {
  min-height: calc(var(--target-min) * 2.5);
  resize: vertical;
}

.field input[type="checkbox"] {
  width: 1.375rem;
  min-height: 1.375rem;
  height: 1.375rem;
  padding: 0;
  accent-color: var(--fayrouz-700);
}

.field-error {
  display: block;
  margin-block: calc(var(--space-1) * -2) var(--space-3);
  color: var(--danger);
  font-size: var(--app-small);
  font-weight: 500;
}

/* ---------- Login (Night, the one display moment) ---------- */

.login-screen {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--space-4);
  isolation: isolate;
}

.login-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: var(--dawn-gradient);
  opacity: var(--dawn-opacity);
  pointer-events: none;
}

.login-panel {
  width: 100%;
  max-width: var(--login-panel-max);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.lockup {
  display: block;
  width: 10rem;
  height: auto;
}

.login-panel .lockup {
  width: 11rem;
  margin-inline: auto;
}

.s-mark {
  width: var(--icon-lg);
  height: var(--icon-lg);
  flex: 0 0 auto;
}

.wordmark {
  font-size: var(--type-h3);
}

.signal-line {
  display: block;
  block-size: 2px;
  inline-size: 100%;
  border-radius: var(--radius-control);
  background: var(--signal-fayrouz);
  box-shadow: var(--glow-inner);
}

.login-title {
  color: var(--page-fg);
  font-size: var(--type-h2);
}

.login-intro {
  color: var(--text-warm-muted);
  max-width: var(--measure);
}

.form-error {
  color: var(--text-warm-white);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-clay);
  border-radius: var(--radius-control);
  background: color-mix(in srgb, var(--clay) 18%, var(--ink));
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.login-form .field-label {
  color: var(--text-warm-white);
}

.login-form .btn {
  margin-block-start: var(--space-1);
}

.login-lang {
  align-self: center;
  display: inline-flex;
  align-items: center;
  min-block-size: 2.75rem;
  padding-inline: var(--space-2);
  color: var(--text-warm-muted);
}

.login-lang:hover {
  color: var(--text-warm-white);
}

.htmx-added {
  opacity: 0;
  transition: opacity var(--dur-swap) var(--ease-out);
}

.htmx-request.catalogue-results,
.htmx-request .catalogue-results {
  opacity: 0.6;
  transition: opacity var(--dur-swap) var(--ease-out);
}

/* ---------- Error pages ---------- */

.error-screen {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: 100dvh;
  justify-content: center;
  padding-block: var(--space-8);
}

.error-screen .signal-line {
  inline-size: 10rem;
}

.error-message {
  max-width: var(--measure);
  color: var(--text-warm-muted);
}


/* =================================================================
   Night CRM workspace (portal + backoffice).
   Icon bar | side nav | workspace. The icon bar and side nav sit on the
   inline-start side: right in Arabic RTL, left in English LTR.
   ================================================================= */

body.app {
  background: var(--night-1);
  color: var(--night-text);
  color-scheme: dark;
  font-size: var(--app-body);
  line-height: var(--leading-body);
  caret-color: var(--action-fayrouz);
  scrollbar-color: var(--night-4) var(--night-1);
}

.app ::selection {
  background: var(--fayrouz-800);
  color: var(--warm-white);
}

.app h1 {
  font-size: var(--app-h1);
  line-height: var(--leading-ui);
  letter-spacing: -0.02em;
}

.app h2 {
  font-size: var(--app-h3);
  line-height: var(--leading-ui);
  letter-spacing: -0.01em;
}

.app h3 {
  font-size: var(--app-body);
  line-height: var(--leading-ui);
}

:lang(ar) .app h1,
.app:lang(ar) h1,
.app:lang(ar) h2 {
  letter-spacing: 0;
}

.num {
  font-family: var(--font-latin);
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--night-text-muted);
}

/* ---------- Shell: one sidebar (inline-start) + main column ---------- */

/* The shell is exactly one viewport tall and never scrolls itself: the
   sidebar and the main column each scroll on their own, so the page's
   scrollbar sits inside the content column (beside the sidebar) instead of
   at the window edge, and the sidebar never moves. */
.app-shell {
  --sidebar-w: var(--sidenav-width);
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns var(--dur-drawer) var(--ease-out);
}

.app-shell[data-nav="compact"] {
  --sidebar-w: var(--iconbar-width);
}

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  height: 100%;
  min-height: 0;
  padding: var(--space-2);
  background: var(--night-0);
  border-inline-end: 1px solid var(--night-line);
  overflow-x: hidden;
  overflow-y: auto;
  /* Opening a plan group can make the list overflow. Reserve the scrollbar's
     space up front so a scrollbar appearing never shifts the column. */
  scrollbar-color: var(--night-4) var(--night-0);
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

/* Scrollbar sides. Browsers draw an element's scrollbar on its inline-end
   edge. The content column's bar belongs against the sidebar (its
   inline-start) and the sidebar's bar against the window edge (also its
   inline-start), so each scroller takes the opposite direction and hands
   the page direction back to its children. */
[dir="rtl"] .main-col,
[dir="rtl"] .sidebar {
  direction: ltr;
}

[dir="rtl"] .main-col > *,
[dir="rtl"] .sidebar > * {
  direction: rtl;
}

[dir="ltr"] .main-col,
[dir="ltr"] .sidebar {
  direction: rtl;
}

[dir="ltr"] .main-col > *,
[dir="ltr"] .sidebar > * {
  direction: ltr;
}

/* A long service list scrolls the sidebar; nothing in it may shrink. */
.sidebar > * {
  flex-shrink: 0;
}

/* position: relative makes the nav (and the sidebar) the containing block
   for the visually hidden labels inside it. Without it those absolutely
   positioned labels escape the scroll container and, where the strip
   overflows, widen the whole page. */
.side-nav {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-label {
  margin: var(--space-2) 0.75rem 4px;
  color: var(--night-text-faint);
  font-size: var(--app-micro);
  font-weight: 500;
  white-space: nowrap;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--target-min);
  padding-inline: 0.8125rem;
  border-radius: var(--radius-control);
  color: var(--night-text-muted);
  font-size: var(--app-small);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--dur-control) var(--ease-out),
    color var(--dur-control) var(--ease-out);
}

.side-link svg {
  flex: 0 0 auto;
  width: 1.125rem;
  height: 1.125rem;
}

.side-link[aria-current="page"] {
  background: var(--action-fayrouz);
  color: var(--action-fayrouz-ink);
  font-weight: 600;
}

/* ---------- Sidebar service groups (one per plan, collapsible) ---------- */

.side-group {
  margin-block-start: 6px;
}

.side-group-head {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 2.25rem;
  padding-inline: 0.8125rem;
  border-radius: var(--radius-control);
  color: var(--night-text-faint);
  font-size: var(--app-micro);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}

.side-group-head::-webkit-details-marker {
  display: none;
}

.side-group-name {
  flex: 1 1 auto;
}

.side-group[data-included="false"] .side-group-name {
  color: var(--night-clay-text);
}

.side-group-count {
  font-weight: 500;
}

.side-group-chevron {
  display: inline-flex;
  width: 0.875rem;
  height: 0.875rem;
  transition: transform var(--dur-control) var(--ease-out);
}

.side-group-chevron svg {
  width: 100%;
  height: 100%;
}

/* Closed groups point the chevron towards the inline end. */
.side-group:not([open]) .side-group-chevron {
  transform: rotate(90deg);
}

[dir="ltr"] .side-group:not([open]) .side-group-chevron {
  transform: rotate(-90deg);
}

/* A plan the business does not have: a heading with a lock, no drop-down. */
.side-group-locked .side-group-head {
  gap: 6px;
  cursor: default;
  color: var(--night-clay-text);
}

.side-group-locked .side-group-name {
  flex: 0 0 auto;
}

.side-group-locked .side-group-count {
  margin-inline-start: auto;
}

.side-group-lock {
  display: inline-flex;
  width: 0.875rem;
  height: 0.875rem;
  color: var(--night-clay-text);
}

.side-group-lock svg {
  width: 100%;
  height: 100%;
}

.side-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-block: 2px 4px;
}

.side-service {
  min-height: 2.5rem;
  gap: 0.625rem;
}

.side-icon {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
}

.side-service-name {
  display: -webkit-box;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: var(--leading-ui);
  white-space: normal;
}

.side-service {
  padding-block: 6px;
}

.side-service[data-state="locked"] {
  color: var(--night-text-faint);
}

.side-service[data-state="locked"] .side-icon {
  opacity: 0.45;
}

.side-lock {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--night-clay-text);
}

.side-lock svg {
  width: 0.875rem;
  height: 0.875rem;
}

/* The current service gets a tint, not the solid pill: its family icon is
   drawn in warm-white and would vanish on Fayrouz. */
.side-service[aria-current="page"] {
  background: var(--night-tint-lit-strong);
  color: var(--night-text);
  font-weight: 600;
}

.side-admin {
  margin-block-start: var(--space-1);
  border-block-start: 1px solid var(--night-line);
  border-radius: 0 0 var(--radius-control) var(--radius-control);
}

@media (hover: hover) and (pointer: fine) {
  .side-group:not(.side-group-locked) .side-group-head:hover {
    background: var(--night-3);
    color: var(--night-text);
  }
}

.app-shell[data-nav="compact"] .side-group-head {
  justify-content: center;
  padding-inline: 0;
  border-block-start: 1px solid var(--night-line);
  border-radius: 0;
}

.app-shell[data-nav="compact"] .side-group-name {
  flex: 0 0 auto;
}

.sidebar-foot {
  margin-block-start: auto;
  padding-block-start: var(--space-2);
  border-block-start: 1px solid var(--night-line);
}

.nav-toggle {
  width: 100%;
  cursor: pointer;
}

.nav-toggle .when-compact {
  display: none;
}

/* Compact: icons only. Labels stay in the accessibility tree (visually
   hidden, not removed); section labels give way to spacing. */
/* The icon column is too narrow to give up width to a scrollbar: it still
   scrolls (wheel, touch, keyboard), the bar itself is hidden. */
.app-shell[data-nav="compact"] .sidebar {
  padding-inline: 0.875rem;
  scrollbar-gutter: auto;
  scrollbar-width: none;
}

.app-shell[data-nav="compact"] .sidebar::-webkit-scrollbar {
  display: none;
}

.app-shell[data-nav="compact"] .side-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.app-shell[data-nav="compact"] .side-label {
  height: 0;
  margin: var(--space-1) 0;
  overflow: hidden;
  border-block-start: 1px solid var(--night-line);
}

.app-shell[data-nav="compact"] .side-link {
  justify-content: center;
  padding-inline: 0;
}

.app-shell[data-nav="compact"] .nav-toggle svg {
  transform: scaleX(-1);
}

.app-shell[data-nav="compact"] .nav-toggle .when-full {
  display: none;
}

.app-shell[data-nav="compact"] .nav-toggle .when-compact {
  display: inline;
}

/* ---------- Main column and top bar ---------- */

.main-col {
  /* Positioned so absolutely placed descendants (.sr-only labels, ring
     captions) take it as their containing block and scroll and clip with
     it. Unpositioned, they hang off <body> at their in-content offset and
     stretch the document, adding a second, outer scrollbar. */
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  /* Reserve the bar's space on every page, so content width is the same on
     short and long pages. */
  scrollbar-gutter: stable;
  scrollbar-color: var(--night-4) var(--night-1);
}

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  min-height: 4rem;
  padding: 0.75rem var(--space-4);
  background: color-mix(in srgb, var(--night-1) 92%, transparent);
  border-block-end: 1px solid var(--night-line);
  backdrop-filter: blur(10px);
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  min-height: var(--target-min);
  padding-inline: 4px;
  border-radius: var(--radius-control);
}

.brand-s {
  display: block;
  width: auto;
  height: 1.75rem;
}

/* The wordmark keeps Latin letter order in both directions. */
.brand-word {
  display: block;
  width: auto;
  height: 0.6875rem;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  margin-inline-start: auto;
}

.workspace-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--target-min);
  padding-inline: 0.875rem;
  border: 1px solid var(--night-line);
  border-radius: var(--radius-control);
  background: var(--night-2);
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.workspace-chip svg {
  width: 1.125rem;
  height: 1.125rem;
  color: var(--night-lit-text);
}

/* ---------- Top-bar menus (native <details>) ---------- */

.menu {
  position: relative;
  min-width: 0;
}

.menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: var(--target-min);
  max-width: 18rem;
  padding: 4px 0.75rem 4px 4px;
  padding-inline: 4px 0.75rem;
  border: 1px solid var(--night-line);
  border-radius: var(--radius-control);
  background: var(--night-2);
  cursor: pointer;
  list-style: none;
  transition: background-color var(--dur-control) var(--ease-out),
    border-color var(--dur-control) var(--ease-out);
}

.menu-trigger::-webkit-details-marker {
  display: none;
}

.menu[open] > .menu-trigger {
  border-color: var(--night-line-strong);
  background: var(--night-3);
}

.menu-icon,
.avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2.125rem;
  height: 2.125rem;
  border-radius: calc(var(--radius-control) - 3px);
  background: var(--night-tint-lit);
  color: var(--night-lit-text);
}

.avatar {
  border-radius: 50%;
  background: var(--night-4);
  color: var(--night-text);
}

.menu-icon svg,
.avatar svg {
  width: 1.125rem;
  height: 1.125rem;
}

.menu-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: var(--leading-ui);
}

.menu-name {
  overflow: hidden;
  color: var(--night-text);
  font-size: var(--app-small);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-meta {
  color: var(--night-lit-text);
  font-size: var(--app-micro);
  white-space: nowrap;
}

.menu-chevron {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  color: var(--night-text-muted);
  transition: transform var(--dur-control) var(--ease-out);
}

.menu-chevron svg {
  display: block;
  width: 100%;
  height: 100%;
}

.menu[open] .menu-chevron {
  transform: rotate(180deg);
}

/* The panel opens towards the page, aligned to the trigger's end edge. */
.menu-panel {
  position: absolute;
  inset-block-start: calc(100% + 6px);
  inset-inline-end: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 15rem;
  max-width: min(22rem, calc(100vw - 2rem));
  padding: 6px;
  border: 1px solid var(--night-line-strong);
  border-radius: var(--radius-control);
  background: var(--night-2);
  box-shadow: 0 16px 40px -12px color-mix(in srgb, black 70%, transparent);
  transform-origin: top var(--menu-origin, left);
}

[dir="ltr"] .menu-panel {
  --menu-origin: right;
}

.menu[open] .menu-panel {
  animation: menu-in var(--dur-swap) var(--ease-out);
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(-4px);
  }
}

.menu-label {
  padding: 6px 0.625rem 4px;
  color: var(--night-text-faint);
  font-size: var(--app-micro);
}

.menu-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.625rem;
  margin-block-end: 4px;
  border-block-end: 1px solid var(--night-line);
}

.menu-head .menu-meta {
  color: var(--night-text-muted);
  overflow-wrap: anywhere;
  white-space: normal;
}

.biz-switcher {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  min-height: 2.5rem;
  padding: 0 0.625rem;
  border: 0;
  border-radius: calc(var(--radius-control) - 3px);
  background: transparent;
  color: var(--night-text-muted);
  font: inherit;
  font-size: var(--app-small);
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.menu-item svg {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
}

.menu-item-text {
  flex: 1 1 auto;
  min-width: 0;
}

.menu-item-meta {
  color: var(--night-text-faint);
  font-size: var(--app-micro);
}

.menu-item[aria-current="page"] {
  background: var(--night-tint-lit);
  color: var(--night-text);
}

.menu-item-sep {
  margin-block-start: 4px;
  border-block-start: 1px solid var(--night-line);
  border-radius: 0 0 calc(var(--radius-control) - 3px) calc(var(--radius-control) - 3px);
}

.logout-form {
  display: contents;
}

.menu-empty {
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

@media (hover: hover) and (pointer: fine) {
  .side-link:not([aria-current]):hover,
  .menu-item:hover {
    background: var(--night-3);
    color: var(--night-text);
  }
  .menu-trigger:hover {
    border-color: var(--night-line-strong);
  }
}

/* ---------- Workspace ---------- */

.workspace {
  min-width: 0;
  padding: var(--space-3) var(--space-4) var(--space-8);
}

.page {
  container-type: inline-size;
  max-width: var(--workspace-max);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-wrap: break-word;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-2);
}

.page-head-text {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.page-intro {
  max-width: var(--measure);
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.head-action {
  max-width: 100%;
  white-space: normal;
  text-align: start;
  line-height: var(--leading-ui);
}

.head-action svg {
  width: 1rem;
  height: 1rem;
}

.next-step-name {
  font-weight: 600;
}

.crumbs a {
  gap: 6px;
  color: var(--night-text-muted);
  font-size: var(--app-small);
  text-decoration: none;
}

.crumbs svg {
  width: 1rem;
  height: 1rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 1.75rem;
  padding: 2px 0.75rem;
  border: 1px solid var(--night-line);
  border-radius: 999px;
  background: var(--night-2);
  color: var(--night-text-muted);
  font-size: var(--app-micro);
}

.chip-plan {
  color: var(--night-text);
  font-weight: 600;
}

.chip-lit {
  border-color: color-mix(in srgb, var(--fayrouz) 30%, var(--ink));
  background: var(--night-tint-lit);
  color: var(--night-lit-text);
}

/* ---------- Buttons on Night ---------- */

.app .btn {
  font-size: var(--app-small);
  font-weight: 600;
}

.app .btn-secondary {
  background: var(--night-3);
  border-color: var(--night-line-strong);
  color: var(--night-text);
}

.btn svg {
  flex: 0 0 auto;
  width: 1.125rem;
  height: 1.125rem;
}

@media (hover: hover) and (pointer: fine) {
  .app .btn-secondary:hover {
    background: var(--night-4);
    border-color: var(--night-line-control);
  }
}

/* ---------- Dashboard grid and panels ---------- */

.dash {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--dash-gap);
}

.span-4 {
  grid-column: span 4;
}

.span-8 {
  grid-column: span 8;
}

.span-12 {
  grid-column: 1 / -1;
}

@container (max-width: 60rem) {
  .span-4,
  .span-8 {
    grid-column: 1 / -1;
  }
}

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-panel);
  background: var(--night-2);
  box-shadow: var(--night-shadow);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-1) var(--space-2);
}

.panel-head > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.panel-note {
  color: var(--night-text-muted);
  font-size: var(--app-small);
  line-height: var(--leading-ui);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: var(--dash-gap);
  align-items: start;
}

@container (max-width: 52rem) {
  .split {
    grid-template-columns: minmax(0, 1fr);
  }
}

.empty {
  padding: var(--space-3) var(--space-2);
  border: 1px dashed var(--night-line-strong);
  border-radius: var(--radius-control);
  color: var(--night-text-muted);
  font-size: var(--app-small);
  text-align: center;
}

/* ---------- Stat tiles ---------- */

.stat-grid {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  grid-auto-rows: 1fr;
  gap: 0.75rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: var(--space-2);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-control);
  background: var(--night-1);
}

.stat-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-block-end: 0.75rem;
  border-radius: var(--radius-control);
  background: var(--night-4);
  color: var(--night-text);
}

.stat-icon svg {
  width: 1.25rem;
  height: 1.25rem;
}

.stat[data-tone="lit"] .stat-icon {
  background: var(--night-tint-lit-strong);
  color: var(--night-lit-text);
}

.stat[data-tone="clay"] .stat-icon {
  background: var(--night-tint-clay);
  color: var(--night-clay-text);
}

.stat[data-tone="muted"] .stat-icon {
  background: var(--night-3);
  color: var(--night-text-muted);
}

.stat-num {
  font-family: var(--font-latin);
  font-size: 1.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-label {
  font-size: var(--app-small);
  font-weight: 500;
}

.stat-sub {
  color: var(--night-text-muted);
  font-size: var(--app-micro);
  line-height: var(--leading-ui);
}

.stat[data-tone="lit"] .stat-sub {
  color: var(--night-lit-text);
}

.stat[data-tone="clay"] .stat-sub {
  color: var(--night-clay-text);
}

/* ---------- Vertical bar chart (plan level, plan mix) ---------- */

.level-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--space-2);
  align-items: end;
  flex: 1 1 auto;
  padding-block-start: var(--space-1);
}

.level-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.level-value {
  font-family: var(--font-latin);
  font-size: var(--app-small);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.level-track {
  display: flex;
  align-items: flex-end;
  width: min(3rem, 100%);
  height: 7rem;
  border-radius: 8px;
  background: var(--night-track);
  overflow: hidden;
}

.level-fill {
  display: block;
  width: 100%;
  height: calc(var(--v, 0) * 1%);
  border-radius: 8px;
  background: var(--series-1);
}

.level-name {
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.level-col[data-current="true"] .level-name {
  color: var(--night-lit-text);
  font-weight: 600;
}

.level-col[data-included="false"] .level-fill {
  background: var(--night-line-control);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  color: var(--night-text-muted);
  font-size: var(--app-micro);
}

.legend li,
.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend svg {
  width: 0.875rem;
  height: 0.875rem;
}

.legend-dot {
  width: var(--lit-size);
  height: var(--lit-size);
  border-radius: 2px;
  background: var(--series-1);
}

.legend-dot[data-series="track"] {
  background: var(--night-4);
}

/* ---------- Activity bars (backoffice) ---------- */

.spark-bars {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 6px;
  align-items: end;
}

.spark-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.spark-track {
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: 8rem;
  border-radius: 6px;
  background: var(--night-track);
  overflow: hidden;
}

.spark-fill {
  display: block;
  width: 100%;
  height: calc(var(--v, 0) * 1%);
  border-radius: 6px;
  background: var(--series-1);
}

.spark-label {
  color: var(--night-text-faint);
  font-family: var(--font-latin);
  font-size: var(--app-micro);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@container (max-width: 44rem) {
  .spark-col:nth-child(even) .spark-label {
    visibility: hidden;
  }
}

/* ---------- Horizontal meters ---------- */

.meter {
  display: block;
  width: 100%;
  height: 0.375rem;
  border-radius: 999px;
  background: var(--night-track);
  overflow: hidden;
}

.meter-fill {
  display: block;
  width: calc(var(--v, 0) * 1%);
  height: 100%;
  border-radius: inherit;
  background: var(--series-1);
}

.meter-fill[data-tone="part"] {
  background: var(--fayrouz-600);
}

.hbars {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.hbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px var(--space-1);
  font-size: var(--app-small);
}

.hbar .meter {
  grid-column: 1 / -1;
}

.hbar-value {
  font-weight: 600;
}

/* ---------- Ring ---------- */

.ring {
  position: relative;
  display: grid;
  place-items: center;
  margin-block: var(--space-1);
}

.ring svg {
  width: min(11rem, 100%);
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 11;
}

.ring-track {
  stroke: var(--night-track);
}

.ring-fill {
  stroke: var(--series-1);
  stroke-linecap: round;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-num {
  font-family: var(--font-latin);
  font-size: var(--app-h2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ring-label {
  color: var(--night-text-muted);
  font-size: var(--app-micro);
}

.ring-foot {
  color: var(--night-text-muted);
  font-size: var(--app-small);
  text-align: center;
}

.ring-foot strong {
  color: var(--night-text);
}

/* ---------- Portal: agents panel ---------- */

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0.75rem;
}

.agent-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-2);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-control);
  background: var(--night-1);
}

.agent-name {
  font-weight: 600;
}

.agent-meta {
  color: var(--night-text-muted);
  font-size: var(--app-micro);
}

.agent-count {
  margin-block-start: var(--space-1);
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.agent-count strong {
  color: var(--night-text);
  font-size: var(--app-h3);
}

/* ---------- Pills and badges ---------- */

.pill,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 1.5rem;
  padding: 2px 0.625rem;
  border: 1px solid var(--night-line-strong);
  border-radius: 6px;
  background: var(--night-3);
  color: var(--night-text);
  font-size: var(--app-micro);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge {
  border-radius: 999px;
}

.pill[data-tone="lit"],
.badge[data-state="active"] {
  border-color: color-mix(in srgb, var(--fayrouz) 32%, var(--ink));
  background: var(--night-tint-lit);
  color: var(--night-lit-text);
}

.pill[data-tone="clay"],
.badge[data-state="pending"],
.badge[data-state="locked"] {
  border-color: color-mix(in srgb, var(--clay) 40%, var(--ink));
  background: var(--night-tint-clay);
  color: var(--night-clay-text);
}

.badge[data-state="managed"] {
  border-color: var(--night-line-strong);
  background: var(--night-4);
  color: var(--night-text);
}

.badge svg {
  width: 0.875rem;
  height: 0.875rem;
}

/* ---------- The lit square: the dot of the i, used as state ---------- */

.lit {
  display: inline-block;
  flex: 0 0 auto;
  width: var(--lit-size);
  height: var(--lit-size);
  border-radius: 2px;
  background: var(--night-4);
}

.lit[data-lit="true"] {
  background: var(--lit);
  box-shadow: var(--lit-glow);
}

/* ---------- Plan ladder (squares) ---------- */

.ladder {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.75rem;
}

.tier {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-control);
  background: var(--night-1);
}

.tier[data-current="true"] {
  border-color: color-mix(in srgb, var(--fayrouz) 45%, var(--ink));
}

.tier-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
  font-weight: 600;
}

.tier-you {
  padding: 1px 0.5rem;
  border-radius: 999px;
  background: var(--night-tint-lit);
  color: var(--night-lit-text);
  font-size: var(--app-micro);
}

.tier-count {
  font-size: var(--app-small);
}

.tier-count strong {
  font-family: var(--font-latin);
  font-size: var(--app-h3);
}

.tier-squares {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tier-state {
  color: var(--night-text-muted);
  font-size: var(--app-micro);
}

.tier[data-tier="locked"] .tier-state {
  color: var(--night-clay-text);
}

/* ---------- Row lists ---------- */

.rows {
  display: flex;
  flex-direction: column;
}

.rows li + li {
  border-block-start: 1px solid var(--night-line);
}

.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3rem;
  padding: var(--space-1) 4px;
  color: var(--night-text);
  text-decoration: none;
}

.row-icon {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
}

.row-title {
  flex: 1 1 auto;
  font-size: var(--app-small);
  font-weight: 500;
}

.row-end {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--night-text-faint);
}

.row-end svg {
  width: 1rem;
  height: 1rem;
}

@media (hover: hover) and (pointer: fine) {
  .row:hover .row-title,
  .cell-link:hover {
    color: var(--night-lit-text);
  }
}

.panel-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  min-height: var(--target-min);
  margin-block-start: auto;
  color: var(--night-lit-text);
  font-size: var(--app-small);
  font-weight: 600;
  text-decoration: none;
}

.panel-link svg {
  width: 1rem;
  height: 1rem;
}

/* ---------- Tables ---------- */

.table-wrap {
  /* Same reason as .main-col: keeps .sr-only cells inside the scroller.
     On phones .main-col is display: contents, so this is the only clip. */
  position: relative;
  overflow-x: auto;
  min-width: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--app-small);
}

.data-table th {
  padding: var(--space-1) 0.75rem;
  border-block-end: 1px solid var(--night-line);
  color: var(--night-text-faint);
  font-size: var(--app-micro);
  font-weight: 500;
  text-align: start;
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem;
  border-block-end: 1px solid var(--night-line);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-block-end: 0;
}

.data-table a {
  color: var(--night-text);
  font-weight: 500;
}

.col-num {
  width: 3rem;
  color: var(--night-text-faint);
}

.col-meter {
  width: 34%;
  min-width: 8rem;
}

.col-end,
.data-table th.col-end {
  text-align: end;
}

.cell-link {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2.25rem;
  text-decoration: none;
}

.cell-link .row-icon {
  width: 1.75rem;
  height: 1.75rem;
}

/* Narrow panels: the service name keeps the room; the meter and row number
   step aside (the status pill still carries the filled count). */
@container (max-width: 36rem) {
  .progress-table .col-num,
  .progress-table .col-meter {
    display: none;
  }
}

.td-empty {
  color: var(--night-text-muted);
  text-align: center;
}

/* ---------- Catalogue ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-panel);
  background: var(--night-2);
}

.toolbar .field {
  flex: 0 1 20rem;
  margin: 0;
}

.catalogue-results {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.plan-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.plan-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
}

.app .plan-head h2 {
  font-size: var(--app-h2);
}

.plan-status {
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.plan-group[data-included="false"] .plan-status {
  color: var(--night-clay-text);
}

.plan-head .summary-line {
  margin-inline-start: auto;
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.summary-line strong {
  color: var(--night-text);
  font-family: var(--font-latin);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
  gap: var(--dash-gap);
}

.tiles > li {
  display: flex;
  min-width: 0;
}

.tile {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "icon top" "icon desc";
  align-content: start;
  gap: 4px var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-panel);
  background: var(--night-2);
  color: var(--night-text);
  text-decoration: none;
  transition: background-color var(--dur-control) var(--ease-out),
    border-color var(--dur-control) var(--ease-out),
    transform var(--dur-press) var(--ease-out);
}

.tile:active {
  transform: scale(0.985);
}

.tile-icon {
  grid-area: icon;
  width: 2.5rem;
  height: 2.5rem;
}

.tile-top {
  grid-area: top;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-1);
  min-width: 0;
}

.tile-top > .badge,
.tile-top > .chip {
  flex: 0 0 auto;
}

.tile-name {
  font-size: var(--app-small);
  font-weight: 600;
  line-height: var(--leading-ui);
}

.tile-desc {
  grid-area: desc;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  color: var(--night-text-muted);
  font-size: var(--app-micro);
  line-height: var(--leading-ui);
}

.tile[data-state="locked"] {
  background: var(--night-1);
}

.tile[data-state="locked"] .tile-icon {
  opacity: 0.5;
}

.tile[data-state="locked"] .tile-name {
  color: var(--night-text-muted);
}

@media (hover: hover) and (pointer: fine) {
  .tile:hover {
    background: var(--night-3);
    border-color: var(--night-line-strong);
  }
}

/* ---------- Service page ---------- */

.service-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-1) var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-panel);
  background: var(--night-2);
}

.family-icon {
  grid-row: span 2;
  width: 4rem;
  height: 4rem;
  padding: 0.75rem;
  border-radius: var(--radius-panel);
  background: var(--night-1);
  box-sizing: content-box;
}

.service-titles {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.service-fullname {
  color: var(--night-text-muted);
  font-size: var(--app-body);
}

.service-desc {
  grid-column: 1 / -1;
  max-width: var(--measure);
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.service-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: var(--dash-gap);
  align-items: start;
}

@container (max-width: 52rem) {
  .service-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-panel);
  background: var(--night-2);
}

.notice > svg {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
  margin-block-start: 2px;
  color: var(--night-text-muted);
}

.notice[data-tone="unlock"] {
  border-color: color-mix(in srgb, var(--clay) 40%, var(--ink));
  background: var(--night-tint-clay);
}

.notice[data-tone="unlock"] > svg {
  color: var(--night-clay-text);
}

.notice-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.notice-title,
.app h2.notice-title {
  font-size: var(--app-body);
  font-weight: 600;
}

.notice-body p:not(.notice-title) {
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.notice-body strong {
  color: var(--night-text);
}

.facts {
  display: flex;
  flex-direction: column;
}

.facts > div {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding-block: 0.75rem;
  font-size: var(--app-small);
}

.facts > div + div {
  border-block-start: 1px solid var(--night-line);
}

.facts dt {
  color: var(--night-text-muted);
}

.facts dd {
  font-weight: 500;
  text-align: end;
  min-width: 0;
}

.account-info {
  max-width: 40rem;
}

/* ---------- Forms on Night ---------- */

.app .field-label,
.app .field > label {
  color: var(--night-text-muted);
}

.app .field input,
.app .field select,
.app .field textarea {
  border-color: var(--night-line-control);
  background: var(--night-1);
  color: var(--night-text);
  font-size: var(--app-small);
}

.app .field input:disabled,
.app .field select:disabled,
.app .field textarea:disabled {
  border-style: dashed;
  color: var(--night-text-muted);
  cursor: not-allowed;
}

.app .field input[type="checkbox"] {
  accent-color: var(--action-fayrouz);
}

.app .field-error {
  color: var(--night-clay-text);
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 0 var(--space-3);
}

.field-slot {
  min-width: 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.save-ok,
.form-ok {
  color: var(--night-lit-text);
  font-size: var(--app-small);
  font-weight: 500;
}

.form-ok {
  padding: 0.75rem var(--space-2);
  border: 1px solid color-mix(in srgb, var(--fayrouz) 32%, var(--ink));
  border-radius: var(--radius-control);
  background: var(--night-tint-lit);
}

.form-error {
  padding: 0.75rem var(--space-2);
  border: 1px solid color-mix(in srgb, var(--clay) 40%, var(--ink));
  border-radius: var(--radius-control);
  background: var(--night-tint-clay);
  color: var(--night-clay-text);
  font-size: var(--app-small);
}

.hint {
  color: var(--night-text-muted);
  font-size: var(--app-micro);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0 var(--space-3);
}

.form-grid > h3,
.form-grid > .form-actions,
.form-grid > .hint,
.form-grid > .field-wide,
.field-wide {
  grid-column: 1 / -1;
}

.form-grid > h3 {
  margin-block: var(--space-2) var(--space-2);
  padding-block-start: var(--space-2);
  border-block-start: 1px solid var(--night-line);
}

/* ---------- Backoffice: field schema ---------- */

.family-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.family-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--target-min);
  padding-inline: 0.75rem;
  border: 1px solid var(--night-line);
  border-radius: var(--radius-control);
  background: var(--night-2);
  color: var(--night-text-muted);
  font-size: var(--app-small);
  text-decoration: none;
}

.family-chip img {
  width: 1.25rem;
  height: 1.25rem;
}

.family-chip[aria-current="page"] {
  border-color: color-mix(in srgb, var(--fayrouz) 45%, var(--ink));
  background: var(--night-tint-lit);
  color: var(--night-text);
}

.family-count {
  color: var(--night-text-faint);
}

.field-list {
  display: flex;
  flex-direction: column;
}

.field-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding-block: var(--space-2);
}

.field-item + .field-item {
  border-block-start: 1px solid var(--night-line);
}

.field-item-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
}

.field-item-name {
  flex: 1 1 12rem;
  font-weight: 600;
}

.field-item-options {
  color: var(--night-text-muted);
  font-size: var(--app-small);
}

.field-edit > summary,
.field-delete > summary {
  display: inline-flex;
  list-style: none;
}

.field-edit > summary::-webkit-details-marker,
.field-delete > summary::-webkit-details-marker {
  display: none;
}

.field-edit[open] > form {
  margin-block-start: var(--space-2);
}

.field-check {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.field-check .field-label {
  margin: 0;
}

.field-delete-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-block-start: var(--space-1);
  padding: var(--space-2);
  border: 1px solid color-mix(in srgb, var(--clay) 40%, var(--ink));
  border-radius: var(--radius-control);
  background: var(--night-tint-clay);
  color: var(--night-clay-text);
  font-size: var(--app-small);
}

/* Clay Deep keeps warm-white text at 9.7:1 (plain Clay is 3.7:1, below AA). */
.btn-danger {
  border-color: var(--clay);
  background: var(--clay-deep);
  color: var(--warm-white);
}

@media (hover: hover) and (pointer: fine) {
  .btn-danger:hover {
    background: color-mix(in srgb, var(--clay) 30%, var(--clay-deep));
  }
  .family-chip:not([aria-current]):hover {
    border-color: var(--night-line-strong);
    color: var(--night-text);
  }
}

/* ---------- Backoffice: agents ---------- */

.inline-form {
  display: inline-block;
}

.outbound-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-block: var(--space-1);
}

.outbound-body {
  font-size: var(--app-small);
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* ---------- Backoffice: sign-in accounts ---------- */

.login-list {
  display: flex;
  flex-direction: column;
}

.login-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-block: var(--space-2);
}

.login-item + .login-item {
  border-block-start: 1px solid var(--night-line);
}

.login-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.login-id {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.login-name {
  font-weight: 600;
}

.login-email {
  color: var(--night-text-muted);
  font-size: var(--app-small);
  overflow-wrap: anywhere;
}

.login-forms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: var(--space-2) var(--space-3);
}

.login-form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0 var(--space-2);
}

.login-form-row .field {
  flex: 1 1 12rem;
}

.login-form-row .btn {
  margin-block-end: var(--space-3);
}

.next-step {
  margin-block: var(--space-1);
}

/* ---------- Phones: icon bar on top, side nav as a scrolling strip ---------- */

@media (max-width: 52rem) {
  .app-shell,
  .app-shell[data-nav="compact"] {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  .main-col {
    overflow: visible;
  }
  [dir] .sidebar {
    direction: inherit;
  }
  .sidebar {
    border-inline-end: 0;
    flex-direction: row;
    align-items: center;
    gap: var(--space-1);
    height: auto;
    padding: var(--space-1) var(--space-2);
    background: var(--night-0);
    border-block-end: 1px solid var(--night-line);
  }
  .side-label,
  .sidebar-foot {
    display: none;
  }
  /* Phones: brand bar on top, then the service strip, then the page. */
  .app-shell {
    display: flex;
    flex-direction: column;
  }
  .main-col {
    display: contents;
  }
  .topbar {
    order: -1;
  }
  .sidebar {
    order: 0;
  }
  .workspace {
    order: 1;
  }
  .brand-word {
    display: none;
  }
  /* The strip scrolls inside itself; min-width 0 stops it from growing to
     the width of every icon and widening the page. */
  .side-nav {
    flex: 1 1 auto;
    flex-direction: row;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .side-link,
  .app-shell[data-nav="compact"] .side-link {
    flex: 0 0 auto;
    padding-inline: 0.75rem;
  }
  .side-group,
  .side-group[open] {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    margin: 0;
  }
  .side-group-head {
    padding-inline: 0.625rem;
    border-inline-start: 1px solid var(--night-line);
    border-radius: 0;
  }
  .side-items {
    flex-direction: row;
    padding: 0;
  }
  .side-service {
    padding-inline: 0.625rem;
  }
  .side-service .side-text,
  .side-group-count {
    display: none;
  }
  .app-shell[data-nav="compact"] .side-text {
    position: static;
    width: auto;
    height: auto;
    clip: auto;
  }
  .topbar {
    position: static;
    padding: var(--space-1) var(--space-2);
  }
  .topbar-end {
    width: 100%;
  }
  .biz-menu {
    flex: 1 1 auto;
  }
  .menu-trigger {
    max-width: none;
  }
  .account-menu .menu-text,
  .account-menu .menu-chevron {
    display: none;
  }
  .account-menu .menu-trigger {
    padding-inline: 4px;
  }
  .workspace {
    padding: var(--space-3) var(--space-2) var(--space-6);
  }
  .panel,
  .service-head {
    padding: var(--space-2);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .btn:active,
  .btn-primary:active,
  .tile:active {
    transform: none;
  }
  .menu[open] .menu-panel {
    animation: none;
  }
}
