/* ============================================================================
   BASE.CSS — Reset + body defaults + typography + link styles + scrollbar
   ============================================================================ */

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

/* Body defaults */
body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  margin: 0;
  padding: 0;
}

/* Headings */
h1, h2, h3, h4 {
  font-family: var(--font-body);
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 8px 0;
}

h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; }

/* Links */
a {
  color: var(--press-red);
  text-decoration: none;
}

a:hover {
  color: var(--press-red-hover);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Focus indicators */
:focus-visible {
  outline: 2px solid var(--press-red);
  outline-offset: 2px;
}

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--ink);
  color: white;
  padding: var(--sp-2) var(--sp-4);
  z-index: 1000;
  transition: top var(--t-fast);
}
.skip-link:focus {
  top: 0;
}

/* ============================================================================
   APP SHELL LAYOUT
   ============================================================================ */

#app-shell { display: flex; height: 100vh; overflow: hidden; }
#sidebar-container { display: flex; flex-shrink: 0; }

/* Primary sidebar — icon strip */
#sidebar-primary {
  width: 74px;
  background: var(--ink);
  color: white;
  display: flex;
  flex-direction: column;
  overflow: hidden;   /* the rail never scrolls: every icon shrinks to fit the window height (Jeff 2026-11-07) */
  border-right: 1px solid var(--ink-lighter);
  flex-shrink: 0;
}

#nav-icons { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; padding-top: var(--sp-2); }

.collapse-btn {
  width: 74px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--silver);
  cursor: pointer;
  transition: color var(--t-fast);
  flex-shrink: 0;
}
.collapse-btn:hover { color: white; }

/* Secondary sidebar — sub-item panel */
#sidebar-secondary {
  width: 200px;
  background: var(--ink-light);
  color: white;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--ink-lighter);
  flex-shrink: 0;
}
#sidebar-secondary.open { display: flex; }

#secondary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #aeb7c3;   /* brighter than --silver so the category header reads clearly */
  border-bottom: 1px solid var(--ink-lighter);
  flex-shrink: 0;
}

#secondary-close {
  background: none;
  border: none;
  color: var(--silver);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: var(--r-sm);
  transition: color var(--t-fast);
}
#secondary-close:hover { color: white; }

#nav-links { display: flex; flex-direction: column; padding: var(--sp-2) 0; }

.nav-section-label {
  padding: var(--sp-3) var(--sp-4) var(--sp-1);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--silver);
  opacity: 0.6;
}

/* Sidebar rail — thin strip when fully closed */
#sidebar-rail {
  width: 12px;
  background: var(--ink);
  display: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: width var(--t-fast), background var(--t-fast);
}
#sidebar-rail:hover {
  width: 16px;
  background: var(--ink-light);
}

/* Sidebar state classes on #app-shell */
#app-shell.sidebar-full #sidebar-container { display: flex; }
#app-shell.sidebar-full #sidebar-secondary { display: flex; }
#app-shell.sidebar-full #sidebar-rail { display: none; }

#app-shell.sidebar-collapsed #sidebar-container { display: flex; }
#app-shell.sidebar-collapsed #sidebar-secondary { display: none !important; }
#app-shell.sidebar-collapsed #sidebar-rail { display: none; }

#app-shell.sidebar-closed #sidebar-container { display: none; }
#app-shell.sidebar-closed #sidebar-rail { display: block; }

/* Main content — always fills remaining space */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-6);
  width: 100%;
  max-width: 100%;
}

/* Header */
#header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-6);
  justify-content: flex-end;
  gap: var(--sp-3);
  flex-shrink: 0;
}

/* Page title + plain-English description live in the header (js/router.js lifts them out of each page). */
#page-heading {
  flex: 1;
  min-width: 0;
  margin-right: var(--sp-3);
  line-height: 1.25;
}
#page-heading-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#page-heading-desc {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#page-heading-desc:empty { display: none; }
.ph-lifted { display: none !important; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: var(--r-sm);
  transition: color var(--t-fast), background var(--t-fast);
}
.icon-btn:hover { color: var(--text); background: var(--cream); }

/* Login screen */
#login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-10);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-6);
  box-shadow: var(--shadow-md);
  min-width: 320px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  text-align: center;
}

/* Primary nav items */
.nav-icon {
  width: 74px;
  min-height: 72px;
  padding: 6px 2px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--silver);
  transition: color var(--t-fast), background var(--t-fast);
  border-left: 3px solid transparent;
  flex-shrink: 0;
}
/* Fit-to-height: icons share the rail's height equally and shrink with it, so all are always visible. */
#nav-icons > .nav-icon { flex: 1 1 0; min-height: 0; max-height: 104px; overflow: hidden; padding-top: 2px; padding-bottom: 2px; }
#nav-icons > .nav-icon svg { flex: 1 1 0; min-height: 12px; max-height: 35px; width: auto; aspect-ratio: 1; }
.nav-icon-text { flex: 0 0 auto; }
.nav-icon-name { font-size: 10px; white-space: nowrap; }
.nav-icon-desc { overflow: hidden; max-height: 2.4em; }
@media (max-height: 1000px) { .nav-icon-desc { display: none; } }
@media (max-height: 640px) { .nav-icon-name { font-size: 9px; } .nav-icon-text { margin-top: 1px; } }
/* Category glyphs: white, sized up from the 20px SVG default (CSS wins over the width/height attrs).
   color drives currentColor, so the icons' fill/stroke follow it. */
.nav-icon svg { width: 35px; height: 35px; color: #fff; flex-shrink: 0; }
.nav-icon-text { display: block; max-width: 70px; margin-top: 3px; text-align: center; }
.nav-icon-name { display: block; font-weight: 600; line-height: 1.2; color: #fff; }
.nav-icon-desc { display: block; font-size: 9px; line-height: 1.2; color: #94a3b8; }
.nav-icon:hover .nav-icon-desc, .nav-icon.active .nav-icon-desc { color: #cbd5e1; }
/* Needs-you dot (Jeff 2026-10-22): red = work is waiting on a person on that page; grey = the count could not be read.
   On a rail icon it sits at the upper right; on a menu row it follows the label. */
.nav-icon { position: relative; }
.nav-dot { position: absolute; top: 10px; right: 14px; width: 11px; height: 11px; border-radius: 50%; background: var(--press-red, #e5322d); box-shadow: 0 0 0 2px var(--ink, #111); pointer-events: none; }
.nav-dot.nav-dot-error { background: #94a3b8; }
.nav-dot.nav-dot-inline { position: static; display: inline-block; margin-left: 8px; vertical-align: middle; box-shadow: none; pointer-events: auto; }
.nav-icon:hover { color: white; background: var(--ink-light); }
.nav-icon.active { color: white; border-left-color: var(--press-red); background: var(--ink-light); }

/* Secondary nav items */
.nav-link {
  display: block;
  padding: var(--sp-2) var(--sp-4);
  color: #cbd5e1;   /* light slate — brighter than --silver for readability on the dark panel */
  font-size: 13px;
  white-space: pre-line; /* honor an explicit \n in a label (e.g. "Past Due\nInvoices") */
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
  border-radius: var(--r-sm);
  margin: 2px var(--sp-2);
}
.nav-link-label { display: block; }
.nav-link-desc { display: block; margin-top: 1px; font-size: 11px; line-height: 1.3; color: #94a3b8; white-space: normal; }
.nav-link:hover .nav-link-desc, .nav-link.active .nav-link-desc { color: #cbd5e1; }
.nav-link:hover { color: white; background: var(--ink-lighter); }
.nav-link.active { color: white; background: var(--ink-lighter); }

/* Dark mode base overrides */
body.dark-mode {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-alt: #1c2128;
  --card: #1c2128;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #656d76;
  --border: #30363d;
  --border-strong: #3d444d;
  --cream: #1c2128;
}

/* Global "Working…" status chip — shown by js/api.js while any request is in flight >300ms. */
#api-busy {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: none; align-items: center; gap: 8px;
  background: var(--ink); color: #fff; padding: 6px 14px; border-radius: 999px;
  font-size: 13px; box-shadow: 0 2px 10px rgba(0,0,0,.25); pointer-events: none;
  opacity: 0; transition: opacity .15s;
}
#api-busy.on { display: inline-flex; opacity: 1; }
.api-busy-spin {
  width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; animation: api-busy-spin .7s linear infinite;
}
@keyframes api-busy-spin { to { transform: rotate(360deg); } }
