/* ============================================================
   Ivy refresh — step 1 of the design overhaul (docs/design-overhaul.md)
   Loads after styles.css. Swaps in the new token values, type, and a
   light sidebar, and styles the new top bar controls (topbar.js).
   Screens keep their own markup; they pick this up through the tokens
   they already use (--bg, --card, --line, --teal, --danger, ...).
   ============================================================ */

:root {
  /* Surfaces */
  --bg:            #F4F6F6;
  --card:          #FFFFFF;
  --card-2:        #FFFFFF;
  --muted-surface: #EDF1F1;

  /* Ink */
  --fg:            #0F1F24;
  --fg-soft:       #3D4F55;
  --muted:         #5E7076;
  /* Was #6B7C82, too light for small text on white (under 4.5:1). */
  --muted-2:       #5E7076;

  /* Lines */
  --line:          #E2E8E8;
  --card-line:     #E2E8E8;
  --line-soft:     #EDF1F1;
  --input-line:    #CCD6D6;

  /* Brand teal stays the action color */
  --teal:          #0C5F66;
  --teal-2:        #0C5F66;
  --teal-deep:     #094F55;
  --teal-soft:     #E2F0EF;
  --teal-line:     #B9DAD7;

  /* Status */
  --danger:        #B42318;
  --danger-soft:   #FDEDEB;
  --danger-ink:    #9A2014;
  --warn:          #A3540A;
  --warn-soft:     #FDF1DF;
  --warn-ink:      #86440A;
  --ok:            #11774A;
  --ok-soft:       #E3F4EB;
  --ok-ink:        #0C6040;

  /* Buildings: one color each, the same on every screen (dashboard,
     people, surveys, payroll, the top-bar switcher). */
  --bldg-davenport:  #0C5F66;
  --bldg-angel-oak:  #C4492A;
  --bldg-silver-oak: #5B6BD6;

  /* Type: Inter for reading, Plus Jakarta Sans for headings */
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Plus Jakarta Sans", "Inter", "Segoe UI", system-ui, sans-serif;

  --shadow-sm: 0 1px 2px rgba(16, 32, 36, 0.06);
  --shadow:    0 1px 2px rgba(16, 32, 36, 0.05), 0 6px 16px -4px rgba(16, 32, 36, 0.08);
  --topbar-h:  56px;
}

body { font-size: 14px; line-height: 1.5; font-feature-settings: "cv11", "ss01"; }

/* ---------- Light sidebar ---------- */
.sidebar {
  background: var(--card);
  color: var(--fg);
  border-right: 1px solid var(--line);
  padding: 14px 10px 12px;
}
.sidebar-brand { border-bottom: 0; margin-bottom: 6px; padding: 4px 8px 10px; }
.brand-mark { background: transparent; }
.brand-eyebrow { color: var(--muted); letter-spacing: 0.08em; }
.brand-name { color: var(--fg); font-size: 16px; }
.nav-group { margin-bottom: 10px; }
.nav-group-label { color: var(--muted); font-size: 11px; letter-spacing: 0.06em; padding: 6px 10px 6px; }
.nav-group-label:hover { color: var(--fg); }
.nav-item { color: var(--fg-soft); font-size: 14px; font-weight: 550; height: 36px; padding: 0 10px; border-radius: 8px; margin-bottom: 1px; }
.nav-item:hover { background: #F1F5F5; color: var(--fg); }
.nav-item .ni-icon { color: var(--muted); }
.nav-item:hover .ni-icon { color: var(--teal); }
.nav-item.is-active { background: var(--teal-soft); color: #0A4A50; }
.nav-item.is-active .ni-icon { color: var(--teal); }
.nav-item.is-active::before { display: none; }
.nav-item .ni-badge { background: var(--danger); }
.sidebar-foot { border-top: 1px solid var(--line); }
.sidebar-foot-label { color: var(--muted); letter-spacing: 0.06em; }
.role-pill { background: var(--card); border: 1px solid var(--line); color: var(--fg); border-radius: 8px; }
.role-pill:hover { background: #F1F5F5; }
.role-dot { background: var(--teal); }
.role-caret { color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  background: rgba(244, 246, 246, 0.86);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  box-shadow: none;
  border-bottom: 1px solid var(--line);
  padding: 0 20px 0 12px;
}
.crumb-section { font-size: 14px; font-weight: 650; }
.topbar-right { gap: 6px; }

.ivy-tb-search {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; width: min(340px, 30vw); padding: 0 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--muted); font-size: 13px; font-family: inherit;
}
.ivy-tb-search:hover { border-color: var(--input-line); }
.ivy-tb-search svg, .ivy-tb-btn svg, .ivy-tb-building svg { width: 16px; height: 16px; flex: none; }
.ivy-kbd { margin-left: auto; height: 20px; padding: 0 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; }
.ivy-tb-building {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px 0 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  color: var(--fg); font-size: 13px; font-weight: 600; font-family: inherit; white-space: nowrap;
}
.ivy-tb-building:hover { border-color: var(--input-line); }
.ivy-tb-building[disabled] { cursor: default; color: var(--fg-soft); }
.ivy-tb-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--muted-2); flex: none; }
.ivy-tb-dot.is-davenport { background: var(--bldg-davenport); }
.ivy-tb-dot.is-angel-oak { background: var(--bldg-angel-oak); }
.ivy-tb-dot.is-silver-oak { background: var(--bldg-silver-oak); }
.ivy-tb-dot.is-all { background: conic-gradient(var(--bldg-davenport) 0 33.3%, var(--bldg-angel-oak) 0 66.6%, var(--bldg-silver-oak) 0); border-radius: 50%; }
.ivy-tb-building[aria-expanded="true"] { border-color: var(--teal-line); }
.ivy-tb-building:focus-visible, .ivy-tb-search:focus-visible, .ivy-tb-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.ivy-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ivy-tb-help {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  color: var(--fg); font-size: 13px; font-weight: 600; font-family: inherit; white-space: nowrap; cursor: pointer;
}
.ivy-tb-help:hover { border-color: var(--input-line); }
.ivy-tb-help svg { width: 16px; height: 16px; flex: none; color: var(--teal); }
.ivy-tb-help[aria-expanded="true"] { background: var(--teal-soft); border-color: var(--teal-line); color: #0A4A50; }
.ivy-tb-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  border: 0; background: transparent; color: var(--fg-soft);
}
.ivy-tb-btn:hover { background: #E8EEEE; color: var(--fg); }
.ivy-tb-avatar {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--teal); color: #fff; font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em;
}

.ivy-pop {
  position: fixed; z-index: 3000; min-width: 230px; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 2px 6px rgba(16,32,36,.06), 0 24px 48px -12px rgba(16,32,36,.24);
}
.ivy-pop-label { padding: 8px 10px 4px; font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.ivy-pop-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
  border: 0; border-radius: 7px; background: none; text-align: left; color: var(--fg); font: inherit; font-size: 13px;
}
.ivy-pop-item:hover, .ivy-pop-item.is-focus, .ivy-pop-item:focus { background: #F1F5F5; outline: none; }
.ivy-pop-item:focus-visible { box-shadow: inset 0 0 0 2px var(--teal); }
.ivy-palette .ivy-pop-item { cursor: pointer; }
.ivy-pop-item .ivy-pop-trail svg { color: var(--teal); }
.ivy-pop-item svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.ivy-pop-item .ivy-pop-trail { margin-left: auto; color: var(--muted); font-size: 12px; }
.ivy-pop-sep { height: 1px; background: var(--line); margin: 6px 4px; }

.ivy-palette-layer { position: fixed; inset: 0; z-index: 3100; background: rgba(10,24,28,.42); }
.ivy-palette {
  position: fixed; z-index: 3101; left: 50%; top: 10vh; transform: translateX(-50%);
  width: min(620px, calc(100vw - 24px)); background: #fff; border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 24px 48px -12px rgba(16,32,36,.3); overflow: hidden;
}
.ivy-palette-input { display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.ivy-palette-input svg { width: 20px; height: 20px; color: var(--muted); }
.ivy-palette-input input { flex: 1; border: 0; outline: none; font: inherit; font-size: 16px; background: none; color: var(--fg); }
.ivy-palette-results { max-height: 50vh; overflow-y: auto; padding: 6px; }

/* Page titles from toolShell are the page's h1. */
.page-shell .page-header h1.page-title { font-size: clamp(24px, 3.6vw, 30px); margin: 0 0 6px; }

/* A page's one extra scope next to the top-bar building (HR: Management
   staff). Quiet, not the coral page action. */
.ivy-scope-toggle,
.page-shell .page-actions .ivy-scope-toggle {
  display: inline-flex; align-items: center; height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
  color: var(--fg); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.ivy-scope-toggle:hover, .page-shell .page-actions .ivy-scope-toggle:hover { border-color: var(--input-line); }
.ivy-scope-toggle[aria-pressed="true"], .page-shell .page-actions .ivy-scope-toggle[aria-pressed="true"] { background: var(--teal-soft); border-color: var(--teal-line); color: var(--teal-deep); }
.ivy-scope-toggle:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* Building chips (opt-in only now): the selected one is plain teal, not
   Angel Oak's coral, so a pick never reads as an alert. */
.facility-chip.is-active { background: var(--teal-soft); color: var(--teal-deep); box-shadow: inset 0 0 0 1px var(--teal-line); }

@media (max-width: 900px) {
  .ivy-tb-search { width: 36px; padding: 0; justify-content: center; border-color: transparent; background: transparent; }
  .ivy-tb-search span, .ivy-tb-search .ivy-kbd { display: none; }
  .ivy-tb-help { width: 36px; padding: 0; justify-content: center; }
  .ivy-tb-help span { display: none; }
  .ivy-tb-building { max-width: 150px; }
  .ivy-tb-building .ivy-tb-label { overflow: hidden; text-overflow: ellipsis; }
  .topbar { padding: 0 8px; }
}
@media print { .topbar-right { display: none !important; } }

/* ---------- Shell accessibility (audit fixes) ---------- */
/* One focus ring for keyboard users everywhere. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[role="tab"]:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* Inline line icons that replaced emoji in buttons. */
.ivy-ico { display: inline-block; vertical-align: -3px; margin-right: 6px; flex: none; }
.ivy-help-photo .ivy-ico { margin: 0; vertical-align: middle; }
.role-caret svg { display: block; }

/* Ask Ivy closed: fully hidden (no focusable controls, no shadow strip on
   the right edge). Visibility waits for the slide-out to finish. */
.ask-ivy-panel:not(.is-open) {
  visibility: hidden;
  box-shadow: none;
  transition: transform 0.2s ease, visibility 0s linear 0.2s;
}
.ask-ivy-panel.is-open { visibility: visible; transition: transform 0.2s ease; }

/* Phone drawer: hidden and out of the tab order while closed; the floating
   buttons stay off while it is open so they do not cover the menu. */
@media (max-width: 880px) {
  body:not(.nav-open) .sidebar {
    visibility: hidden;
    transition: transform 0.18s ease, visibility 0s linear 0.18s;
  }
  body.nav-open .sidebar { visibility: visible; transition: transform 0.18s ease; }
  body.nav-open .ask-ivy-fab,
  body.nav-open .ivy-feedback-fab,
  body.nav-open .fin-chat-fab { display: none !important; }
}

/* ---------- Phones: tap targets at least 40px ----------
   One rule set for the shell's small controls under 720px: the menu's
   group labels and rows, Schedule's name buttons, the small button sizes
   (.tiny, .btn-sm, .button-sm, .icon-btn) and Ask Ivy's close. Layout
   stays the same; only the hit area grows. */
@media (max-width: 720px) {
  .sidebar .nav-group-label,
  .sidebar .nav-item,
  .staff-root .pname,
  .button.tiny,
  .btn-sm,
  .button-sm,
  .icon-btn,
  .ask-ivy-close,
  .ivy-feedback-close,
  .facility-chip,
  .chip,
  .ivy-tb-search,
  .ivy-tb-help,
  .ivy-tb-building,
  .ivy-tb-btn,
  .role-pill {
    min-height: 40px;
  }
  .icon-btn,
  .ask-ivy-close,
  .ivy-feedback-close,
  .ivy-tb-search,
  .ivy-tb-help,
  .ivy-tb-btn { min-width: 40px; }
  /* Links styled as small buttons are inline: give them a box. */
  a.button.tiny:not([hidden]), a.btn-sm:not([hidden]), a.button-sm:not([hidden]) { display: inline-flex; align-items: center; justify-content: center; }
  .staff-root .pname:not([hidden]) { display: flex; align-items: center; }
  .ask-ivy-close:not([hidden]) { display: inline-flex; align-items: center; justify-content: center; }
}
