/* ============================================================
   WOKI Customer Portal — shared shell
   Right-side collapsible nav + minimal sticky top header.
   Pages attach into <main class="portal-content">.
   Design tokens mirror the project's root system (styles.css).
   ============================================================ */

:root {
  --brand:        #0064c8;
  --brand-strong: #0051a3;
  --brand-light:  #e8f2ff;
  --brand-subtle: #f3f8ff;

  --bg:        #eef3fa;
  --surface:   #ffffff;
  --surface-2: #f7fbff;

  --ink:   #111827;
  --ink-2: #374151;
  --muted: #5b667a;
  --faint: #8d9aab;

  --line:       #dce6f2;
  --line-light: #edf3fb;

  --ok:    #118a4e;
  --ok-bg: #edf9f3;
  --bad:   #cc3a3a;
  --bad-bg:#fff3f3;

  --shadow-xs: 0 1px 2px rgba(14, 36, 60, .05);
  --shadow-sm: 0 1px 4px rgba(14, 36, 60, .07), 0 0 0 1px rgba(14, 36, 60, .04);
  --shadow-md: 0 4px 18px rgba(14, 36, 60, .09), 0 1px 4px rgba(14, 36, 60, .05);
  --shadow-lg: 0 20px 48px rgba(14, 36, 60, .13), 0 4px 12px rgba(14, 36, 60, .06);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --ease: cubic-bezier(.22, .68, 0, 1.2);
  --t:    .18s ease;

  --nav-w:          264px;
  --nav-w-collapsed: 74px;
  --topbar-h:       60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Heebo", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ============================================================
   Shell: sidebar (right, RTL) + main column — flex row
   In RTL the first flex child sits on the right automatically.
   ============================================================ */
.portal-shell {
  --current-nav: var(--nav-w);
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
}
.portal-shell.is-collapsed {
  --current-nav: var(--nav-w-collapsed);
}

/* ============================================================
   Sidebar
   ============================================================ */
.portal-nav {
  /* literal widths (not var()) on the transitioning property: Chromium
     won't fire a width transition that's driven only by a var() change. */
  width: 264px;          /* = --nav-w */
  flex-shrink: 0;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 40;
  transition: width var(--t);
}
.is-collapsed .portal-nav { width: 74px; }   /* = --nav-w-collapsed */

/* brand / logo row */
.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 18px;
  border-bottom: 1px solid var(--line-light);
  flex-shrink: 0;
}
.nav-brand .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  overflow: hidden;
  white-space: nowrap;
}
.nav-brand .brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .5px;
  color: var(--brand);
}
.nav-brand .brand-sub {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--faint);
  text-transform: uppercase;
}
/* always-visible edge handle straddling the sidebar/content border —
   a sibling of .portal-nav (so it is never clipped by the nav's own
   overflow:hidden), positioned in physical px via portal.js because it
   must track the rail's real pixel width in both states.
   The primary, unmissable control for collapsing/reopening the menu. */
.nav-edge-toggle {
  position: absolute;
  top: 50%;
  right: 252px; /* JS-driven: sits centered on the nav/content border */
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  z-index: 50;
  cursor: pointer;
  transition: right var(--t), background var(--t), color var(--t), border-color var(--t);
}
.nav-edge-toggle:hover { background: var(--brand-light); color: var(--brand); border-color: var(--brand-light); }

/* scroll area */
.nav-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 12px 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.nav-scroll::-webkit-scrollbar { width: 6px; }
.nav-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

.nav-section { margin-bottom: 14px; }
.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--faint);
  padding: 4px 12px 8px;
  white-space: nowrap;
  overflow: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 10px 13px;
  margin-bottom: 2px;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-size: 14.5px;
  font-weight: 500;
  border-radius: var(--r-md);
  text-align: start;
  white-space: nowrap;
  position: relative;
  transition: background var(--t), color var(--t);
  text-decoration: none;
}
.nav-item .ni-icon {
  font-size: 19px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  color: var(--faint);
  transition: color var(--t);
}
.nav-item .ni-label { overflow: hidden; }
.nav-item .ni-badge {
  margin-inline-start: auto;
  font-size: 11px;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-item:hover {
  background: var(--brand-subtle);
  color: var(--ink);
}
.nav-item:hover .ni-icon { color: var(--brand); }

.nav-item.is-active {
  background: var(--brand-light);
  color: var(--brand-strong);
  font-weight: 700;
}
.nav-item.is-active .ni-icon { color: var(--brand); }
.nav-item.is-active::before {
  content: "";
  position: absolute;
  inset-inline-end: -12px;       /* outer (screen) edge */
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  border-radius: 99px 0 0 99px;
  background: var(--brand);
}

.nav-divider {
  height: 1px;
  background: var(--line-light);
  margin: 8px 12px 14px;
}

/* footer block: support + academy */
.nav-foot {
  border-top: 1px solid var(--line-light);
  padding: 10px 12px;
  flex-shrink: 0;
}

/* ---- collapsed state ---- */
.is-collapsed .portal-nav { cursor: pointer; }
.is-collapsed .nav-brand { padding: 0; justify-content: center; }
.is-collapsed .nav-brand .brand-text { display: none; }
.is-collapsed .nav-section-title { text-align: center; padding: 4px 0 8px; color: transparent; height: 14px; }
.is-collapsed .nav-section-title::after {
  content: "•••"; color: var(--line); letter-spacing: 1px;
  display: block;
}
.is-collapsed .nav-item { justify-content: center; padding: 11px 0; gap: 0; }
.is-collapsed .nav-item .ni-label,
.is-collapsed .nav-item .ni-badge { display: none; }
.is-collapsed .nav-item.is-active::before { inset-inline-end: -12px; }

/* tooltip when collapsed */
.is-collapsed .nav-item::after {
  content: attr(data-label);
  position: absolute;
  inset-inline-end: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) scale(.96);
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t), transform var(--t);
  z-index: 60;
  box-shadow: var(--shadow-md);
}
.is-collapsed .nav-item:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }

/* ============================================================
   Main column
   ============================================================ */
.portal-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}

/* ---- minimal sticky top header ---- */
.portal-topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-mobile-toggle {
  display: none;
  width: 36px; height: 36px;
  border: none; background: transparent;
  color: var(--ink-2); font-size: 21px;
  border-radius: var(--r-sm);
}
.topbar-mobile-toggle:hover { background: var(--brand-subtle); }

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}
.topbar-spacer { flex: 1; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* round icon button (notifications / help) */
.icon-btn {
  position: relative;
  width: 38px; height: 38px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 50%;
  font-size: 19px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--brand-subtle); color: var(--brand); }
.icon-btn .dot {
  position: absolute;
  top: 7px; inset-inline-end: 8px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  background: var(--bad);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
}

.topbar-sep {
  width: 1px;
  height: 26px;
  background: var(--line);
  margin: 0 4px;
}

/* ---- customer / subscription selector ---- */
.cust-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 5px 14px 5px 10px;
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 600;
  transition: border-color var(--t), box-shadow var(--t);
  max-width: 230px;
}
.cust-selector:hover { border-color: var(--brand); box-shadow: var(--shadow-xs); }
/* read-only: this login IS that customer's own user, nothing to switch to */
.cust-selector--static { padding: 5px 12px; cursor: default; }
.cust-selector--static:hover { border-color: var(--line); box-shadow: none; }
.cust-selector .cs-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--brand-light);
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cust-selector .cs-text { display: flex; flex-direction: column; line-height: 1.15; overflow: hidden; }
.cust-selector .cs-name { font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cust-selector .cs-meta { font-size: 11px; color: var(--faint); font-weight: 500; }
.cust-selector .bs-caret { font-size: 10px; color: var(--faint); flex-shrink: 0; }
.cust-selector[hidden] { display: none; }

/* ---- branch/subscription switcher popover list ---- */
.branch-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: none; background: transparent; border-radius: var(--r-sm);
  text-align: start; font-family: inherit; font-size: 13px; color: var(--ink-2);
  cursor: pointer; transition: background var(--t);
}
.branch-item:hover { background: var(--brand-subtle); }
.branch-item.is-active { background: var(--brand-light); color: var(--brand-strong); font-weight: 700; }
.branch-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch-item-id { font-size: 11px; color: var(--faint); font-weight: 500; }
.branch-item.is-active .branch-item-id { color: var(--brand); }
.branch-item i.bi-check-circle-fill { color: var(--brand); font-size: 13px; flex-shrink: 0; }

/* ---- account menu trigger ---- */
.acct-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  border: none;
  background: transparent;
  padding: 4px 6px 4px 4px;
  border-radius: 99px;
  transition: background var(--t);
}
.acct-btn:hover { background: var(--brand-subtle); }
.acct-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.acct-btn .acct-caret { color: var(--faint); font-size: 13px; }

/* ============================================================
   Popovers / dropdown menus (shared)
   ============================================================ */
.pop {
  position: absolute;
  top: calc(var(--topbar-h) - 6px);
  inset-inline-end: 22px;
  min-width: 268px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  z-index: 80;
  overflow: hidden;
  transform-origin: top;
  animation: pop-in .16s var(--ease);
}
.pop[hidden] { display: none; }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.pop-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pop-head h4 { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink); }
.pop-head a { font-size: 12px; color: var(--brand); text-decoration: none; font-weight: 600; }
.pop-body { max-height: 340px; overflow-y: auto; }

.pop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 16px;
  border: none;
  background: transparent;
  text-align: start;
  font-size: 13.5px;
  color: var(--ink-2);
  transition: background var(--t);
}
.pop-item:hover { background: var(--brand-subtle); }
.pop-item .pi-icon {
  width: 20px; text-align: center; color: var(--faint); font-size: 16px; flex-shrink: 0;
}
.pop-item.danger { color: var(--bad); }
.pop-item.danger .pi-icon { color: var(--bad); }
.pop-divider { height: 1px; background: var(--line-light); margin: 4px 0; }

/* notification row */
.notif {
  display: flex; gap: 11px; padding: 12px 16px;
  border-bottom: 1px solid var(--line-light);
}
.notif:last-child { border-bottom: none; }
.notif .nf-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-top: 6px; flex-shrink: 0; }
.notif.read .nf-dot { background: var(--line); }
.notif .nf-body { min-width: 0; }
.notif .nf-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.notif .nf-text { font-size: 12px; color: var(--muted); margin-top: 1px; }
.notif .nf-time { font-size: 11px; color: var(--faint); margin-top: 3px; }

.acct-card {
  padding: 16px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line-light);
}
.acct-card .ac-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff; font-size: 16px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.acct-card .ac-name { font-size: 14px; font-weight: 700; color: var(--ink); }
.acct-card .ac-mail { font-size: 12px; color: var(--muted); }

/* ============================================================
   Content area (pages attach here)
   ============================================================ */
.portal-content {
  flex: 1;
  overflow-y: auto;
  padding: 26px clamp(18px, 3vw, 38px) 40px;
}

/* "coming soon" placeholder for nav routes with no page built yet */
.coming-soon-wrap { max-width: 1180px; margin: 0 auto; }
.coming-soon {
  padding: 56px 32px;
  text-align: center;
}
.coming-soon i {
  font-size: 46px;
  color: var(--brand);
  margin-bottom: 18px;
  display: block;
}
.coming-soon-title { font-size: 20px; font-weight: 800; color: var(--ink); margin-bottom: 8px; }
.coming-soon-desc { font-size: 14px; color: var(--muted); max-width: 440px; margin: 0 auto; line-height: 1.6; }
.coming-soon-badge {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 18px;
  padding: 5px 14px;
  border-radius: 99px;
  background: var(--brand-subtle);
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 700;
}

/* placeholder shown until a page is attached */
.attach-placeholder {
  height: 100%;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--faint);
  border: 2px dashed var(--line);
  border-radius: var(--r-xl);
  background: var(--surface-2);
}
.attach-placeholder i { font-size: 42px; margin-bottom: 14px; color: var(--line); }
.attach-placeholder h3 { margin: 0 0 6px; font-size: 17px; color: var(--muted); font-weight: 700; }
.attach-placeholder p { margin: 0; font-size: 13.5px; }
.attach-placeholder code {
  background: var(--brand-light); color: var(--brand-strong);
  padding: 2px 7px; border-radius: 6px; font-size: 12.5px;
}

/* ============================================================
   Shared in-app dialog — replaces prompt()/alert()/confirm() everywhere.
   Invoke via window.WokiPortal.dialog({...}) (see portal.js).
   ============================================================ */
.app-modal-scrim {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .42);
  opacity: 0; pointer-events: none; transition: opacity var(--t);
  z-index: 120;
}
.app-modal-scrim.is-open { opacity: 1; pointer-events: auto; }

.app-modal {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.97);
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  z-index: 121;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t), transform var(--t);
}
.app-modal.is-open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }

.app-modal-head {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 50px 14px 18px;
  border-bottom: 1px solid var(--line-light);
  font-size: 15px; font-weight: 800; color: var(--ink);
}
.app-modal-close {
  position: absolute; top: 12px; inset-inline-start: 12px;
  width: 30px; height: 30px; border: none; background: var(--surface-2);
  border-radius: 50%; color: var(--muted); font-size: 13px;
}
.app-modal-close:hover { background: var(--brand-light); color: var(--brand); }

.app-modal-body { padding: 20px 22px; }
.app-modal-field { display: block; margin-bottom: 16px; }
.app-modal-field[hidden] { display: none; }
.app-modal-field span { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-2); margin-bottom: 7px; }
.app-modal-field input {
  width: 100%;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2);
  padding: 10px 12px;
  font-family: inherit; font-size: 13.5px; color: var(--ink);
  transition: border-color var(--t), background var(--t), box-shadow var(--t);
}
.app-modal-field input:focus {
  outline: none; border-color: var(--brand); background: var(--surface);
  box-shadow: 0 0 0 3px var(--brand-light);
}
.app-modal-message { margin: 0 0 16px; font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.app-modal-actions { display: flex; gap: 8px; }
.app-modal-actions .qa-btn { flex: 1; justify-content: center; height: 42px; }

/* ============================================================
   Mobile / responsive
   ============================================================ */
.nav-scrim {
  position: fixed;
  inset: 0;
  background: rgba(14, 36, 60, .42);
  z-index: 35;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t);
}

@media (max-width: 900px) {
  /* off-canvas nav uses the hamburger toggle instead of the edge handle */
  .nav-edge-toggle { display: none; }

  .portal-nav {
    position: fixed;
    inset-block: 0;
    inset-inline-end: 0;
    width: var(--nav-w);
    transform: translateX(100%);
    transition: transform var(--t);
    box-shadow: var(--shadow-lg);
  }
  .portal-shell.nav-open .portal-nav { transform: translateX(0); }
  .portal-shell.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  /* collapse toggle behaves as off-canvas open on mobile */
  .is-collapsed .portal-nav { transform: translateX(100%); }
  .topbar-mobile-toggle { display: inline-flex; }
  .cust-selector .cs-text { display: none; }
  .cust-selector { padding: 5px; }
}
