:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1f27;
  --text-muted: #64707d;
  /* Brand palette sampled from the Root-Sys International logo */
  --brand-navy: #063c58;
  --brand-navy-light: #0a5a86;
  --brand-green: #01cc34;
  --brand-green-dark: #019428;
  /* Primary accent is the logo green. #017a20 (not the vivid #01cc34) is used
     for interactive fills so white text on top clears WCAG AA (~5.5:1) -
     the bright green alone only manages ~2:1 with white text. */
  --accent: #017a20;
  --accent-hover: #019428;
  --accent-text: #ffffff;
  --sidebar-bg: #14181f;
  --sidebar-text: #aab3c0;
  --sidebar-text-active: #ffffff;
  --green: #1a8f5a; --green-bg: #e4f7ee;
  --red: #c53535; --red-bg: #fbe9e9;
  --amber: #b3790a; --amber-bg: #fdf1dc;
  --purple: #6b46c1; --purple-bg: #f0eafb;
  --gray: #5a6472; --gray-bg: #eceef1;
  --blue: #2f6fed; --blue-bg: #e8f0fe;
  --shadow: 0 1px 2px rgba(20, 24, 31, 0.06), 0 1px 8px rgba(20, 24, 31, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --border: #2a2e36;
    --text: #e7e9ec;
    --text-muted: #9aa3b0;
    --brand-navy: #063c58;
    --brand-navy-light: #2f88c2;
    --brand-green: #2fe35c;
    --brand-green-dark: #01cc34;
    /* Dark mode needs a brighter green to read against the dark surface;
       dark text on top (not white) is what actually clears AA against it. */
    --accent: #2fe35c;
    --accent-hover: #4fed7c;
    --accent-text: #062310;
    --sidebar-bg: #0e1014;
    --green: #3fcf8e; --green-bg: #113727;
    --red: #f0685f; --red-bg: #3a1e1e;
    --amber: #e3ab3d; --amber-bg: #3a2f14;
    --purple: #a78bfa; --purple-bg: #2a2140;
    --gray: #9aa3b0; --gray-bg: #262a31;
    --blue: #5b8def; --blue-bg: #172440;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* !important so this utility always wins regardless of source-order
   against component rules (e.g. .nav-item sets its own display later
   in this file - without !important that rule would win on a tie). */
.hidden { display: none !important; }

.app { display: flex; min-height: 100vh; }
.app.hidden { display: none; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, rgba(1, 204, 52, 0.10), transparent 55%), var(--bg);
}
.login-page.hidden { display: none; }

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--brand-green);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 36px 28px;
  text-align: center;
}
.login-logo {
  width: 110px;
  height: 110px;
  object-fit: contain;
  border-radius: 50%;
  margin: 0 auto 16px;
  display: block;
}
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-subtitle { font-size: 12.5px; color: var(--text-muted); margin: 0 0 22px; }
.login-card form { text-align: left; }
.login-submit { width: 100%; margin-top: 6px; padding: 10px 14px; }
.login-footer { font-size: 11px; color: var(--text-muted); margin: 20px 0 0; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  padding: 0 20px 22px;
}
.brand span { color: var(--brand-green); }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }

.nav-item {
  all: unset;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--sidebar-text);
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--accent); color: var(--accent-text); }
/* icons inherit the button's own color (currentColor) so hover/active states
   apply to them automatically, no separate icon coloring needed */
.nav-item svg { flex-shrink: 0; opacity: 0.85; }
.nav-item:hover svg, .nav-item.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 20px 0;
  font-size: 11px;
  color: #5c6472;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h1 { font-size: 19px; margin: 0; }
.topbar .subtitle { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.health { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.health-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); }
.health-dot.ok { background: var(--green); }
.health-dot.down { background: var(--red); }

.session-widget { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.session-widget .who { color: var(--text-muted); }
.session-widget .who strong { color: var(--text); }

.content { padding: 24px 28px; overflow-x: auto; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card .label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.card .value { font-size: 24px; font-weight: 700; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
}
.panel-header h2 { font-size: 14.5px; margin: 0; }
.panel-header p { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }
/* Tables render with white-space: nowrap cells and can end up wider than
   the panel (many columns, e.g. Staff/Attendance/Payroll) - scroll here,
   right at the panel-body, instead of relying on an ancestor's overflow
   (the .panel above this clips instead of scrolling, so without this a
   wide table's extra columns would just be silently cut off). Applies to
   both variants: most tables sit directly in a no-pad body, but some
   (e.g. the Attendance staff month view) render into a nested div inside
   a normally-padded body - overflow-x here covers that case too. */
.panel-body { padding: 18px; overflow-x: auto; }
.panel-body.no-pad { padding: 0; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(127,127,127,0.06); }
.empty-row td { color: var(--text-muted); text-align: center; padding: 26px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  margin: 2px 0;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray { background: var(--gray-bg); color: var(--gray); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }

button, .btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { background: var(--accent-hover); }
button.danger { color: var(--red); }
button.danger:hover { border-color: var(--red); }
button.small { padding: 5px 10px; font-size: 12px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; text-decoration: underline; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.field { display: flex; flex-direction: column; gap: 2px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.combobox-field { position: relative; }
/* position: fixed (not absolute) and positioned via JS against the
   viewport (see initSearchableStaffField) rather than offset from
   .combobox-field - so a long option list isn't clipped by an ancestor
   .panel's `overflow: hidden` when the field sits near a panel's bottom
   edge. top/left/width are set in JS on open; min-width is just a floor. */
.combobox-list {
  position: fixed;
  min-width: 220px;
  max-height: min(280px, 50vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 40;
}
.combobox-option { padding: 8px 10px; font-size: 13px; cursor: pointer; }
.combobox-option:hover, .combobox-option.active { background: var(--accent); color: var(--accent-text); }
.combobox-empty { padding: 8px 10px; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 12, 16, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 14px; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.whatsapp-qr-wrap {
  display: flex;
  justify-content: center;
  padding: 12px 0;
}
.whatsapp-qr {
  width: 220px;
  height: 220px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  object-fit: contain;
}

.wa-perm-drop {
  position: relative;
  min-width: 190px;
}
.wa-perm-drop[inert] { opacity: 0.55; pointer-events: none; }
.wa-perm-summary {
  list-style: none;
  cursor: pointer;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-perm-summary::-webkit-details-marker { display: none; }
.wa-perm-menu {
  position: static;
  z-index: auto;
  margin-top: 6px;
  min-width: 0;
  width: max-content;
  max-width: 280px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: none;
}
.wa-perm-drop[open] {
  z-index: 2;
}
tbody td:has(.wa-perm-drop) {
  white-space: normal;
  vertical-align: top;
  overflow: visible;
}
.wa-perm-menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 4px;
  font-size: 13px;
  color: var(--text);
  font-weight: 400;
  cursor: pointer;
}

.toast-container {
  position: fixed; bottom: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  min-width: 220px;
  max-width: 340px;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }

.result-log {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  margin-top: 10px;
}

.menu-toggle {
  all: unset;
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.menu-toggle:hover { background: rgba(127,127,127,0.12); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.5);
  z-index: 55;
}

/* Below this width the sidebar becomes an off-canvas drawer (hidden by
   default, slides in over the content) instead of a permanent 220px
   column - on a phone that column would leave barely any room for the
   actual page content. */
@media (max-width: 860px) {
  .menu-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 78vw;
    max-width: 280px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop.open { display: block; }

  .topbar { padding: 14px 16px; }
  .content { padding: 16px; }
  .cards { gap: 10px; }
  .panel-header { padding: 12px 14px; }
  .panel-body { padding: 14px; }

  /* Designation is useful context on desktop but is the first thing that
     causes the session widget to wrap/overflow awkwardly next to the
     logout button on a narrow phone screen - name alone is enough there. */
  .session-widget .role { display: none; }
}
