/* 12-menu.css — The menu and the top bar as floating cards on a warm background: icon tiles per
   block, a pill that slides to the active item, the collapsed icon rail, and in the top bar the
   environment picker and the account menu (components/side-menu.js).
   Part of the portal stylesheet; index.html loads the parts in order (01 to 12), so the cascade is
   the same as one file. */

:root {
  /* Warm off-white instead of cool grey, still tinted by the brand colour. */
  --theme-bg-start: color-mix(in srgb, var(--brand-primary) 2%, #f9f5f0);
  --theme-bg-mid: color-mix(in srgb, var(--brand-primary) 3%, #f3ede6);
  --theme-bg-end: color-mix(in srgb, var(--brand-primary) 1%, #f7f2ec);
  --sidebar-width: 290px;
  --menu-gap: 14px;
  --menu-bg: rgba(255, 252, 248, 0.86);
  --menu-border: rgba(255, 255, 255, 0.85);
  --menu-shadow: 0 1px 2px rgba(60, 30, 20, 0.06), 0 14px 36px -14px rgba(80, 35, 25, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --menu-hover: rgba(60, 40, 30, 0.055);
  --menu-card: #fffdfa;
  --menu-line: #ece6df;
  --menu-pop-shadow: 0 2px 4px rgba(60, 30, 20, 0.06), 0 24px 48px -16px rgba(80, 35, 25, 0.35);
  --tile-work-bg: #e7eefb;
  --tile-work-ink: #24508f;
  --tile-sites-bg: #e3f3ec;
  --tile-sites-ink: #1f6b4c;
  --tile-money-bg: #fbf0dc;
  --tile-money-ink: #8a5a00;
  --tile-system-bg: #eceef2;
  --tile-system-ink: #4a5263;
  --pill: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
  --pill-shadow: 0 6px 16px -6px color-mix(in srgb, var(--brand-primary) 60%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  --badge-soft-bg: color-mix(in srgb, var(--brand-primary) 11%, #ffffff);
  --badge-soft-ink: var(--brand-primary);
  --menu-glow: color-mix(in srgb, var(--brand-primary) 15%, transparent);
}
:root[data-theme="dark"] {
  --theme-bg-start: #171514;
  --theme-bg-mid: #1a1817;
  --theme-bg-end: #151312;
  --menu-bg: rgba(33, 30, 29, 0.84);
  --menu-border: rgba(255, 255, 255, 0.06);
  --menu-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --menu-hover: rgba(255, 255, 255, 0.055);
  --menu-card: #272322;
  --menu-line: #3a3431;
  --menu-pop-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 24px 48px -16px rgba(0, 0, 0, 0.75);
  --tile-work-bg: #1d2a40;
  --tile-work-ink: #8fb3ef;
  --tile-sites-bg: #17302a;
  --tile-sites-ink: #7fd1ad;
  --tile-money-bg: #33281a;
  --tile-money-ink: #efc06c;
  --tile-system-bg: #2b2a2e;
  --tile-system-ink: #b9bcc6;
  /* Darker than the light --primary of dark mode, so white text on it stays readable. */
  --pill: linear-gradient(135deg, color-mix(in srgb, var(--primary) 72%, #000000), color-mix(in srgb, var(--primary) 52%, #000000));
  --pill-shadow: 0 8px 20px -8px color-mix(in srgb, var(--primary) 50%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  --badge-soft-bg: color-mix(in srgb, var(--primary) 20%, transparent);
  --badge-soft-ink: var(--primary-dark);
  --menu-glow: color-mix(in srgb, var(--primary) 13%, transparent);
}

/* A warm glow behind the top of the menu. */
body::after { content: ""; position: fixed; left: -14vmax; top: -16vmax; z-index: -1; width: 52vmax; height: 44vmax; pointer-events: none;
  background: radial-gradient(closest-side, var(--menu-glow), transparent); }
body.signed-out::after { display: none; }

/* ---------- The menu as a floating card ---------- */
.sidebar { gap: 14px; padding: 22px 14px 14px; background: var(--menu-bg); }
@media (min-width: 1101px) {
  body { transition: grid-template-columns 0.25s ease; }
  .sidebar { top: var(--menu-gap); height: calc(100vh - 2 * var(--menu-gap)); margin: var(--menu-gap) 0 var(--menu-gap) var(--menu-gap);
    border: 1px solid var(--menu-border); border-radius: 22px; box-shadow: var(--menu-shadow); scrollbar-width: thin; }
  :root[data-theme="dark"] .sidebar { box-shadow: var(--menu-shadow); }
}
.sidebar-logo { display: block; padding: 0 6px; }
.sidebar-logo img { width: 196px; }
.sidebar-logo .sidebar-mark { display: none; width: 40px; height: 40px; object-fit: contain; filter: none; }
.menu-collapse { display: none; }
@media (min-width: 1101px) {
  .menu-collapse { position: absolute; top: 20px; right: 12px; display: grid; place-items: center; width: 30px; height: 30px; padding: 0;
    border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; opacity: 0.55; transition: opacity 0.16s ease, background 0.16s ease; }
  .sidebar:hover .menu-collapse, .menu-collapse:focus-visible { opacity: 1; }
  .menu-collapse:hover { background: var(--menu-hover); color: var(--ink); }
  .menu-collapse svg { width: 17px; height: 17px; }
}

/* ---------- The top bar as a floating card, like the menu (desktop) ---------- */
@media (min-width: 1101px) {
  .topbar { top: var(--menu-gap); margin: var(--menu-gap) 0 22px; padding: 16px 22px; border: 1px solid var(--menu-border); border-radius: 22px;
    background: var(--menu-bg); box-shadow: var(--menu-shadow); }
  :root[data-theme="dark"] .topbar { box-shadow: var(--menu-shadow); }
  .topbar-titles h1 { font-size: 26px; }
}
.topbar-tools { gap: 10px; }
.topbar .env-card { width: 260px; min-height: 0; padding: 6px 10px; }
.account-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer;
  box-shadow: 0 0 0 3px var(--menu-card), 0 0 0 4px var(--menu-line); transition: box-shadow 0.18s ease; }
.account-button:hover, .account-button[aria-expanded="true"], .account-button.active { box-shadow: 0 0 0 3px var(--menu-card), 0 0 0 5px color-mix(in srgb, var(--primary) 45%, transparent); }
.account-button .avatar { width: 40px; height: 40px; font-size: 13px; }
@media (max-width: 1300px) {
  .topbar .env-card { width: 210px; }
}
@media (max-width: 760px) {
  .topbar .env-card { width: auto; padding: 4px; }
  .topbar .env-card-text, .topbar .env-card > svg { display: none; }
  .help-button span { display: none; }
}

/* ---------- Links with icon tiles ---------- */
.side-nav { position: relative; gap: 1px; }
.nav-group-label { margin: 12px 0 3px 10px; }
.side-link { gap: 10px; min-height: 40px; padding: 4px 10px 4px 5px; border-radius: 999px; transition: background 0.18s ease, color 0.25s ease; }
.side-link:hover { background: var(--menu-hover); color: var(--ink); }
.side-link.active::before { content: none; }
.side-nav .side-link { z-index: 1; }
.side-nav .side-link.active, .side-nav .side-link.active:hover { background: transparent; box-shadow: none; color: #ffffff; }
/* Without the pill (no script yet): the active link carries the colour itself. */
.side-nav:not(.has-marker) .side-link.active { background: var(--pill); box-shadow: var(--pill-shadow); }
.side-link .side-label { flex: 1; min-width: 0; }
.side-icon { display: grid; place-items: center; flex: 0 0 auto; width: 30px; height: 30px; border-radius: 9px;
  background: var(--tile-bg); color: var(--tile-ink); transition: transform 0.2s ease, background 0.25s ease, color 0.25s ease; }
.side-link .side-icon svg { width: 16px; height: 16px; opacity: 1; }
.tint-work { --tile-bg: var(--tile-work-bg); --tile-ink: var(--tile-work-ink); }
.tint-sites { --tile-bg: var(--tile-sites-bg); --tile-ink: var(--tile-sites-ink); }
.tint-money { --tile-bg: var(--tile-money-bg); --tile-ink: var(--tile-money-ink); }
.tint-system { --tile-bg: var(--tile-system-bg); --tile-ink: var(--tile-system-ink); }
.side-link:hover .side-icon { transform: translateX(2px); }
.side-nav .side-link.active .side-icon { background: rgba(255, 255, 255, 0.17); color: #ffffff; transform: none; }
.side-sub .side-link { min-height: 34px; padding-left: 26px; font-size: 13px; }
.side-sub .side-icon { width: 24px; height: 24px; border-radius: 8px; }
.side-sub .side-link .side-icon svg { width: 14px; height: 14px; }

/* The pill: one element behind the links that glides to the active one. */
.nav-marker { position: absolute; left: 0; top: 0; z-index: 0; border-radius: 999px; background: var(--pill); box-shadow: var(--pill-shadow); pointer-events: none; }
.nav-marker.moving { transition: transform 0.34s cubic-bezier(0.3, 0.7, 0.2, 1), width 0.34s ease, height 0.34s ease; }

/* Soft counters; white on the pill. */
.nav-badge { background: var(--badge-soft-bg); color: var(--badge-soft-ink); }
.nav-badge-error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.side-nav .side-link.active .nav-badge { background: rgba(255, 255, 255, 0.24); color: #ffffff; }

/* ---------- Environment picker (top bar) ---------- */
.avatar { display: grid; place-items: center; flex: 0 0 auto; width: 32px; height: 32px; overflow: hidden; border-radius: 10px;
  background: #5a6474; color: #ffffff; font-size: 12px; font-weight: 800; letter-spacing: 0.02em; line-height: 1; }
.avatar-round { border-radius: 50%; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.avatar-platform { background: var(--pill); font-size: 10px; letter-spacing: 0; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18); }
.env-card { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 50px; padding: 8px 10px; border: 1px solid var(--menu-line); border-radius: 14px;
  background: var(--menu-card); color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  box-shadow: 0 1px 2px rgba(60, 30, 20, 0.05); transition: border-color 0.18s ease, box-shadow 0.18s ease; }
.env-card:hover, .env-card[aria-expanded="true"] { border-color: color-mix(in srgb, var(--primary) 28%, var(--menu-line)); box-shadow: 0 8px 18px -12px rgba(80, 35, 25, 0.4); }
.env-card-text, .env-option-text, .account-who { display: grid; flex: 1; min-width: 0; line-height: 1.25; }
.env-card-text b, .env-option-text b, .account-who b { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.env-card-text small, .env-option-text small, .account-who small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.env-card > svg { width: 16px; height: 16px; color: var(--muted); }
.env-pop { position: fixed; z-index: 80; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 6px; max-height: min(70vh, 480px); padding: 10px;
  border: 1px solid var(--menu-line); border-radius: 16px; background: var(--menu-card); color: var(--ink); box-shadow: var(--menu-pop-shadow);
  animation: env-pop-in 0.16s ease-out; }
@keyframes env-pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }
.env-search { display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--menu-line); border-radius: 10px; color: var(--muted); }
.env-search:focus-within { border-color: color-mix(in srgb, var(--primary) 45%, var(--menu-line)); }
.env-search svg { width: 15px; height: 15px; }
.env-search input, :root[data-theme="dark"] .env-search input { width: 100%; height: 36px; min-height: 0; padding: 0; border: 0; background: transparent; box-shadow: none; outline: none; color: var(--ink); font-size: 13px; }
.env-list { display: grid; align-content: start; gap: 2px; overflow-y: auto; }
.env-option { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: 10px; background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.env-option.current { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.env-option.highlight { background: var(--menu-hover); }
.env-option.current.highlight { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.env-divider { height: 1px; margin: 4px 2px; background: var(--menu-line); }
.env-empty { margin: 0; padding: 8px; color: var(--muted); font-size: 13px; }

/* ---------- Account menu (top bar) ---------- */
.account-pop { position: fixed; z-index: 80; display: grid; gap: 4px; padding: 10px; border: 1px solid var(--menu-line); border-radius: 16px;
  background: var(--menu-card); color: var(--ink); box-shadow: var(--menu-pop-shadow); animation: env-pop-in 0.16s ease-out; }
.account-pop-head { display: flex; align-items: center; gap: 12px; padding: 6px 6px 10px; border-bottom: 1px solid var(--menu-line); margin-bottom: 4px; }
.account-pop-head .avatar { width: 44px; height: 44px; font-size: 14px; }
.account-pop-head .account-who b { font-size: 15px; }
.account-pop-head .account-who small { white-space: normal; }
.account-pop-label { margin: 6px 6px 2px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.segmented { display: flex; gap: 2px; margin: 0 4px 4px; padding: 3px; border-radius: 12px; background: var(--menu-hover); }
.segmented button { display: flex; flex: 1; align-items: center; justify-content: center; gap: 6px; padding: 6px 4px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }
.segmented svg { width: 14px; height: 14px; }
.account-pop-divider { height: 1px; margin: 4px 2px; background: var(--menu-line); }
.account-pop-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 10px; background: transparent;
  color: var(--nav-ink); font: inherit; font-weight: 650; text-align: left; text-decoration: none; cursor: pointer; }
.account-pop-item:hover, .account-pop-item:focus-visible { background: var(--menu-hover); color: var(--ink); }
.account-pop-item svg { width: 17px; height: 17px; }

/* ---------- Collapsed: an icon rail (desktop only) ---------- */
.menu-tip { position: fixed; z-index: 90; padding: 5px 10px; border-radius: 8px; background: #22201d; color: #ffffff; font-size: 12px; font-weight: 700;
  white-space: nowrap; pointer-events: none; box-shadow: 0 8px 20px -8px rgba(0, 0, 0, 0.5); }
.menu-tip::before { content: ""; position: absolute; left: -5px; top: calc(50% - 5px); border: 5px solid transparent; border-left: 0; border-right-color: #22201d; }
:root[data-theme="dark"] .menu-tip { background: #f1ede9; color: #22201d; }
:root[data-theme="dark"] .menu-tip::before { border-right-color: #f1ede9; }
@media (min-width: 1101px) {
  :root.menu-collapsed { --sidebar-width: 96px; }
  .menu-collapsed .sidebar { gap: 10px; padding: 16px 10px 12px; }
  .menu-collapsed .sidebar-logo { display: grid; justify-items: center; padding: 0; }
  .menu-collapsed .sidebar-logo img:not(.sidebar-mark), .menu-collapsed .sidebar-logo .powered-by { display: none; }
  .menu-collapsed .sidebar-logo .sidebar-mark { display: block; }
  .menu-collapsed .menu-collapse { position: static; justify-self: center; opacity: 1; }
  .menu-collapsed .side-label { display: none; }
  .menu-collapsed .nav-group-label { height: 1px; margin: 8px 12px; overflow: hidden; background: var(--menu-line); font-size: 0; }
  .menu-collapsed .side-link, .menu-collapsed .side-sub .side-link { justify-content: center; padding: 5px; border-radius: 14px; }
  .menu-collapsed .nav-marker { border-radius: 14px; }
  .menu-collapsed .nav-badge { position: absolute; top: 4px; right: calc(50% - 19px); width: 11px; min-width: 0; height: 11px; padding: 0;
    border: 2px solid var(--menu-card); background: var(--brand-primary); font-size: 0; line-height: 0; }
  :root.menu-collapsed[data-theme="dark"] .nav-badge { background: var(--primary); }
  .menu-collapsed .nav-badge-error { background: var(--danger); }
  .menu-collapsed .side-nav .side-link.active .nav-badge { background: #ffffff; border-color: transparent; }
}

/* ---------- Low screens (laptop): the whole menu fits ---------- */
@media (min-width: 1101px) and (max-height: 900px) {
  :root { --menu-gap: 10px; }
  .sidebar { gap: 10px; padding: 16px 12px 12px; }
  .topbar { padding: 12px 18px; margin-bottom: 16px; }
  .sidebar-logo img { width: 168px; }
  .side-link { min-height: 34px; padding: 3px 10px 3px 4px; font-size: 14px; }
  .side-icon { width: 26px; height: 26px; border-radius: 8px; }
  .side-link .side-icon svg { width: 15px; height: 15px; }
  .side-sub .side-link { min-height: 30px; }
  .side-sub .side-icon { width: 22px; height: 22px; }
  .nav-group-label { margin-top: 8px; }
}
@media (min-width: 1101px) and (max-height: 780px) {
  .sidebar { gap: 8px; padding-top: 12px; }
  .sidebar-logo img { width: 150px; }
  .side-link { min-height: 31px; }
  .side-icon { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .nav-marker.moving, .side-link, .side-icon, .env-pop, .account-pop, body { transition: none !important; animation: none !important; }
}
