/* ── Everstay — Stylesheet ─────────────────────────────────────────── */
:root {
  --bg:          #ffffff;
  --bg2:         #ffffff;
  --bg3:         #f1f5f9;
  --border:      #e2e8f0;
  --border2:     #cbd5e1;
  --text:        #0f172a;
  --text2:       #475569;
  --text3:       #64748b;
  --accent:      #2563eb;
  --accent2:     #7c3aed;
  --green:       #059669;
  --yellow:      #ca8a04;
  --red:         #dc2626;
  --orange:      #ea580c;
  --chart-surface: #ffffff;
  --chart-label:   #0f172a;
  --chart-label-muted: #475569;
  --chart-link:    #94a3b8;
  --sidebar-w:   240px;
  --radius:      8px;
  --font-body:   'Inter', sans-serif;
  --font-display:'DM Serif Display', serif;
  --font-mono:   'IBM Plex Mono', monospace;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  font-size: 14px;
  line-height: 1.6;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: #f8fafc;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow: hidden;
  z-index: 100;
}

.sidebar-brand {
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-brand a { display: block; }
.sidebar-brand img { display: block; }

.nav-links { list-style: none; padding: 8px 0; flex: 1; overflow-y: auto; }
.nav-section {
  font-size: 10px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text2);
  padding: 16px 20px 5px;
  font-family: var(--font-mono);
  font-weight: 700;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 20px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  transition: all .12s;
  border-left: 2px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-link:hover { color: var(--text); background: #e8f0fe; }
.nav-link.active { color: var(--accent); background: #dbeafe; border-left-color: var(--accent); font-weight: 500; }
.nav-icon { font-size: 13px; width: 16px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  border-radius: 100px;
  font-size: 10px;
  padding: 1px 7px;
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.nav-badge-blue { background: var(--accent); color: #fff; }
.nav-badge-red  { background: var(--red);    color: #fff; }

/* ── Collapsible click-to-open nav groups ───────────────────── */
.nav-group { list-style: none; }
.nav-group > .nav-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: color .15s, background .15s;
}
.nav-group > .nav-section:hover { color: var(--accent); background: var(--bg3); }
.nav-group > .nav-section .nav-caret {
  font-size: 8px;
  opacity: .45;
  transition: transform .25s ease, opacity .2s;
  margin-left: 8px;
}
.nav-group-items {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height .28s ease, opacity .18s ease;
}
/* Open state: click to add .open, mouse-leave to remove */
.nav-group.open > .nav-group-items { max-height: 600px; opacity: 1; }
.nav-group.open > .nav-section .nav-caret { transform: rotate(90deg); opacity: 1; }
/* Show current location even when folded */
.nav-group.has-active > .nav-section { color: var(--accent); }

/* Pinned bottom quick-access group */
.sidebar-bottom-group {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: #f8fafc;
}
.sidebar-bottom-label {
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text3);
  padding: 10px 20px 2px;
  font-family: var(--font-mono);
}

.sidebar-footer {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  flex-shrink: 0;
}

/* Language switcher */
.lang-switcher {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.lang-switcher-label {
  display: block;
  font-size: 9px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text3);
  font-family: var(--font-mono);
  margin-bottom: 8px;
}
.lang-switcher-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--text2);
  text-decoration: none;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.5px;
  transition: all .15s;
}
.lang-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: #dbeafe;
}
.lang-btn.lang-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.lang-code { line-height: 1; }

.lang-switcher-auth {
  position: fixed;
  top: 12px;
  right: 16px;
  display: flex;
  gap: 6px;
  z-index: 100;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 220px;
}

.user-name { display: block; color: var(--text2); margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn { color: var(--text3); text-decoration: none; font-size: 11px; }
.logout-btn:hover { color: var(--red); }

/* Acronym hover expansions (see main.js applyAbbrTooltips) */
abbr.es-abbr {
  cursor: help;
  text-decoration: underline dotted;
  text-decoration-color: var(--text3);
  text-underline-offset: 2px;
}

/* ── Main Content ────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  min-height: 100vh;
}
.main-content.full-width { margin-left: 0; }

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title { font-family: var(--font-display); font-size: 28px; color: var(--text); font-weight: 400; }
.page-subtitle { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #f8fafc; color: var(--text2); border-color: var(--border2); }
.btn-secondary:hover { background: #e2e8f0; color: var(--text); }
.btn-danger    { background: transparent; color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card-title {
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 1px;
  color: var(--text2);
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 8px;
}

/* ── User manual ─────────────────────────────────────────────────────────── */
.manual-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: start;
}
.manual-toc {
  position: sticky;
  top: 16px;
  padding: 16px;
}
.manual-toc-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
}
.manual-toc-list a {
  color: var(--text2);
  text-decoration: none;
}
.manual-toc-list a:hover { color: var(--accent); }
.manual-body { display: flex; flex-direction: column; gap: 16px; }
.manual-section { scroll-margin-top: 16px; }
.manual-section-title {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 400;
  color: var(--text);
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.manual-p {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text2);
  margin: 0 0 12px;
}
.manual-p:last-of-type { margin-bottom: 0; }
.manual-items {
  margin: 14px 0 0;
  padding: 0;
}
.manual-items dt {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 12px;
}
.manual-items dt:first-child { margin-top: 0; }
.manual-items dd {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text2);
}
@media (max-width: 768px) {
  .manual-layout { grid-template-columns: 1fr; }
  .manual-toc { position: static; }
}

/* ── Reference library ───────────────────────────────────────────────────── */
.ref-subject-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.ref-subject-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.ref-subject-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 400;
  margin: 0;
  color: var(--text);
}
.ref-item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ref-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.ref-item:last-child { border-bottom: none; padding-bottom: 0; }
.ref-item-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}
.ref-item-link:hover { text-decoration: underline; }
.ref-item-icon { font-size: 14px; }
.ref-item-file {
  font-size: 11px;
  color: var(--text3);
  font-weight: 400;
}
.ref-item-desc {
  font-size: 12px;
  color: var(--text3);
  margin-top: 4px;
  line-height: 1.5;
}
.ref-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.ref-empty {
  font-size: 13px;
  color: var(--text3);
  padding: 8px 0;
}

/* ── Stat Grid ───────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}
.stat-card.accent::before   { background: var(--accent); }
.stat-card.green::before    { background: var(--green); }
.stat-card.red::before      { background: var(--red); }
.stat-card.yellow::before   { background: var(--yellow); }
.stat-card.orange::before   { background: var(--orange); }
.stat-card.purple::before   { background: var(--accent2); }

.stat-value { font-family: var(--font-display); font-size: 36px; color: var(--text); line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 11px; color: var(--text2); font-family: var(--font-mono); }

/* ── Dashboard Grids ─────────────────────────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--bg3);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border2);
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 10px 14px; color: var(--text); vertical-align: middle; }
tbody td:first-child { color: var(--text); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 500;
  border: 1px solid;
}
.badge-critical { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.badge-high     { color: #c2410c; border-color: #fed7aa; background: #fff7ed; }
.badge-medium   { color: #a16207; border-color: #fde68a; background: #fffbeb; }
.badge-low      { color: #047857; border-color: #a7f3d0; background: #ecfdf5; }
.badge-active   { color: #047857; border-color: #a7f3d0; background: #ecfdf5; }
.badge-draft    { color: var(--text3); border-color: var(--border2); background: var(--bg3); }
.badge-open     { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.badge-closed   { color: var(--text3); border-color: var(--border2); background: var(--bg3); }
.badge-progress { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.badge-planned  { color: #6d28d9; border-color: #ddd6fe; background: #f5f3ff; }
.badge-done     { color: #047857; border-color: #a7f3d0; background: #ecfdf5; }
.badge-review   { color: #a16207; border-color: #fde68a; background: #fffbeb; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }
label { font-size: 11px; font-family: var(--font-mono); color: var(--text2); letter-spacing: .5px; text-transform: uppercase; font-weight: 600; }
input, select, textarea {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 9px 12px;
  width: 100%;
  transition: border-color .15s;
  outline: none;
}
input::placeholder, textarea::placeholder { color: var(--text3); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
select option { background: #fff; color: var(--text); }
textarea { resize: vertical; min-height: 80px; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ── Risk Matrix ─────────────────────────────────────────────────────────── */
.risk-matrix {
  display: grid;
  grid-template-columns: 24px repeat(5, 1fr);
  grid-template-rows: repeat(5, 40px) 24px;
  gap: 3px;
  margin-top: 16px;
}
.rm-cell {
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: opacity .15s;
  position: relative;
}
.rm-cell:hover { opacity: .8; }
.rm-axis-label { color: var(--text3); font-size: 10px; font-family: var(--font-mono); }

/* ── Flash messages ──────────────────────────────────────────────────────── */
.flash-container { margin-bottom: 20px; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 8px;
  border-left: 3px solid;
}
.flash-success { background: #ecfdf5; border-color: var(--green); color: #047857; }
.flash-danger  { background: #fef2f2; border-color: var(--red); color: #b91c1c; }
.flash-info    { background: #eff6ff; border-color: var(--accent); color: #1d4ed8; }
.flash-warning { background: #fffbeb; border-color: var(--yellow); color: #a16207; }

/* ── Login / Setup page ──────────────────────────────────────────────────── */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.auth-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo-icon { font-size: 40px; display: block; margin-bottom: 8px; }
.auth-title { font-family: var(--font-display); font-size: 24px; color: var(--text); }
.auth-sub { font-size: 12px; color: var(--text3); font-family: var(--font-mono); letter-spacing: .5px; }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.actions-cell { display: flex; gap: 6px; flex-wrap: nowrap; }
.text-mono { font-family: var(--font-mono); }
.text-dim  { color: var(--text2); }
.mt-4  { margin-top: 16px; }
.mb-4  { margin-bottom: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.section-header { font-family: var(--font-display); font-size: 17px; margin-bottom: 12px; }

/* ── Chart placeholder ───────────────────────────────────────────────────── */
.chart-container { position: relative; height: 200px; }

/* ── Progress bar ────────────────────────────────────────────────────────── */
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 3px; transition: width .4s; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .form-group.span-2, .form-group.span-3 { grid-column: span 1; }
  .main-content { padding: 16px; }
}
@media (max-width: 700px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Delete confirm form ─────────────────────────────────────────────────── */
.delete-form { display: inline; }

/* ── Logo splash animation ───────────────────────────────────────────────── */
.logo-splash {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  visibility: hidden;
  background: rgba(255, 255, 255, 0.94);
}
.logo-splash.is-active {
  visibility: visible;
}
.logo-splash__img {
  width: min(75vw, 520px);
  height: auto;
  max-height: 75vh;
  object-fit: contain;
  transform: scale(0.05);
  opacity: 0;
  will-change: transform, opacity;
  filter: drop-shadow(0 8px 24px rgba(15, 23, 42, 0.12));
}
.logo-splash.is-active .logo-splash__img {
  animation: es-logo-splash 5s ease-in-out forwards;
}
@keyframes es-logo-splash {
  0% {
    transform: scale(0.05);
    opacity: 0.7;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .logo-splash.is-active .logo-splash__img {
    animation-duration: 0.01ms;
  }
}

/* ── Charts & graphs (light theme — legible labels) ─────────────────────── */
.card svg#org-chart,
.card svg#dep-chart {
  background: var(--chart-surface);
}

svg#org-chart text,
svg#dep-chart text {
  fill: var(--chart-label);
}

svg#org-chart g.node--out-of-scope {
  opacity: 0.55;
  filter: grayscale(0.85);
}

#graph-wrap svg#dep-graph {
  background: var(--chart-surface);
}

#graph-wrap svg#dep-graph text {
  fill: var(--chart-label);
}

/* Fixed on-screen chart area — content zooms to fit inside */
.chart-viewport {
  position: relative;
  width: 100%;
  height: min(72vh, 780px);
  min-height: 320px;
  overflow: hidden;
  background: var(--chart-surface);
}

.chart-viewport > svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-viewport .chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
