:root {
  --nav-bg: #16324f;
  --nav-bg-hover: #1f4a72;
  --nav-bg-active: #0f2540;
  --nav-text: #c7dbec;
  --nav-text-dim: #7fa3c2;
  --accent: #1a7fc1;
  --accent-dark: #0f4b7a;
  --page-bg: #eef1f5;
  --card: #ffffff;
  --border: #d3dce5;
  --text: #1c2b36;
  --text-dim: #5c7a8f;
  --ok: #1f8a4c;
  --warn: #b06f00;
  --danger: #c0392b;
  --radius: 6px;
  --nav-width: 248px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--page-bg);
}

a { color: var(--accent-dark); }

/* ---------------------------------------------------------- app shell --- */

.app { display: flex; min-height: 100%; }

.nav {
  width: var(--nav-width);
  flex: 0 0 var(--nav-width);
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 15px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-decoration: none;
}
/* It is a link home, but it is also the masthead — so it stays looking like
   the masthead until you approach it. */
.nav-brand:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-brand:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav-brand .mark {
  width: 24px; height: 24px; border-radius: 5px;
  background: linear-gradient(135deg, #2aa8e0, #1a7fc1);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}

.nav-filter { padding: 10px; display: flex; gap: 6px; align-items: stretch; }
.nav-filter input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 7px 9px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  font-size: 13px;
}
.nav-filter input::placeholder { color: var(--nav-text-dim); }
.nav-filter input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Collapse or expand every section at once. */
.nav-toggle-all {
  flex: 0 0 auto;
  padding: 0 9px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.22);
  color: var(--nav-text);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.nav-toggle-all:hover { background: var(--nav-bg-hover); color: #fff; }
.nav-toggle-all:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }

.nav-scroll { overflow-y: auto; flex: 1; padding-bottom: 12px; }

.nav-section > .nav-section-title {
  display: flex; align-items: center; gap: 7px;
  width: 100%;
  padding: 9px 14px;
  background: none; border: 0;
  color: var(--nav-text-dim);
  font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  cursor: pointer; text-align: left;
}
.nav-section > .nav-section-title:hover { color: #fff; }
.nav-section .caret { transition: transform 0.15s; font-size: 9px; }
.nav-section.collapsed .caret { transform: rotate(-90deg); }
.nav-section.collapsed .nav-items { display: none; }

.nav-items { list-style: none; margin: 0; padding: 0; }
.nav-items a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 14px 8px 26px;
  color: var(--nav-text); text-decoration: none; font-size: 13.5px;
  border-left: 3px solid transparent;
}
.nav-items a:hover { background: var(--nav-bg-hover); color: #fff; }
.nav-items a.active {
  background: var(--nav-bg-active); color: #fff;
  border-left-color: var(--accent); font-weight: 600;
}

.badge {
  background: var(--accent); color: #fff;
  border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 700;
}
.badge.zero { display: none; }

.nav-foot {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 11px 14px; font-size: 12px; color: var(--nav-text-dim);
}

/* ------------------------------------------------------------- content --- */

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

.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 0 20px; height: 52px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }
.topbar .who { color: var(--text-dim); font-size: 13px; display: flex; align-items: center; gap: 12px; }

.content { padding: 20px; flex: 1; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 18px;
}
.card > h2 {
  margin: 0; padding: 13px 16px; font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-body { padding: 16px; }
.card-body > p:first-child { margin-top: 0; }
.card-body > :last-child { margin-bottom: 0; }

.muted { color: var(--text-dim); }
.small { font-size: 12.5px; }

/* --------------------------------------------------------------- forms --- */

.field { margin-bottom: 13px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.field .hint { color: var(--text-dim); font-size: 12px; margin-top: 3px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 4px;
  font: inherit; color: var(--text); background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
textarea { min-height: 78px; resize: vertical; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 220px; }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 8px 15px; border-radius: 4px;
  border: 1px solid var(--accent-dark); background: var(--accent-dark); color: #fff;
}
button:hover, .btn:hover { background: #0c3d63; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary, .btn.secondary {
  background: #fff; color: var(--accent-dark); border-color: var(--border);
}
button.secondary:hover { background: #f3f6f9; }
button.danger { background: var(--danger); border-color: var(--danger); }
button.danger:hover { background: #a5301f; }
button.small { padding: 5px 10px; font-size: 12.5px; }

/* --------------------------------------------------------------- table --- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
th {
  background: #f5f7fa; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-dim); font-weight: 700;
}
tbody tr:hover { background: #f7fafc; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }

/* --------------------------------------------------- related lists --- */

.related-lists { margin-top: 18px; }
.rl-tabs {
  display: flex; flex-wrap: wrap; gap: 2px;
  padding: 0 8px; border-bottom: 1px solid var(--border);
  background: #f5f7fa; border-radius: var(--radius) var(--radius) 0 0;
}
.rl-tab {
  border: 0; background: none; cursor: pointer;
  padding: 11px 14px; margin-bottom: -1px;
  font-size: 13px; font-weight: 600; color: var(--text-dim);
  border-bottom: 2px solid transparent;
  display: flex; align-items: center; gap: 7px;
}
.rl-tab:hover { color: var(--accent-dark); background: rgba(255, 255, 255, 0.6); }
.rl-tab.active {
  color: var(--accent-dark); border-bottom-color: var(--accent);
  background: var(--card);
}
.rl-count {
  background: #dde5ec; color: var(--text-dim);
  border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 700;
}
.rl-tab.active .rl-count { background: var(--accent); color: #fff; }
.rl-count.zero { opacity: 0.55; }
.rl-single-title {
  margin: 0; padding: 13px 16px; font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.rl-body { padding: 16px; }
.rl-panel > :last-child { margin-bottom: 0; }
.rl-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* ------------------------------------------------------- list views --- */

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: #eef2f6; color: var(--accent-dark); }
th.sorted { color: var(--accent-dark); }
th .sort-caret { font-size: 9px; margin-left: 5px; }
th.right, td.right { text-align: right; }

/* Right-clickable cells get a whisper of an affordance, not a shout. */
td.filterable { cursor: context-menu; }

.list-chips {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  margin-bottom: 12px; padding: 9px 11px;
  background: #eef3f8; border: 1px solid var(--border); border-radius: var(--radius);
}
.list-chips-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-dim);
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: #fff; border: 1px solid var(--accent);
  color: var(--accent-dark); border-radius: 12px;
  padding: 2px 4px 2px 10px; font-size: 12.5px; font-weight: 600;
}
.chip-exclude { border-color: var(--danger); color: var(--danger); }
.chip-x {
  border: 0; background: none; padding: 0 4px; cursor: pointer;
  color: inherit; font-size: 12px; line-height: 1; opacity: 0.6;
}
.chip-x:hover { opacity: 1; background: none; }

.ctx-menu {
  position: fixed; z-index: 100; min-width: 208px;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 26px rgba(20, 40, 60, 0.22);
  padding: 5px; font-size: 13px;
}
.ctx-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 4px;
  background: none; color: var(--text); font-weight: 500;
  text-align: left; cursor: pointer;
}
.ctx-item:hover { background: #eef3f8; color: var(--accent-dark); }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger:hover { background: #fdecea; color: var(--danger); }
.ctx-icon {
  flex: 0 0 14px; text-align: center; font-size: 11px; opacity: 0.75;
}
.ctx-sep { height: 1px; background: var(--border); margin: 4px 2px; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 11px;
  font-size: 11.5px; font-weight: 700;
  /* Roles are data, so a pill can carry a class no rule below matches. */
  background: #eceff2; color: var(--text-dim);
}
.pill.active { background: #e3f5e9; color: var(--ok); }
.pill.pending { background: #fdf1dc; color: var(--warn); }
.pill.disabled { background: #eceff2; color: var(--text-dim); }
.pill.admin { background: #e5eff8; color: var(--accent-dark); }
.pill.consultant { background: #eaf3ec; color: #2e6f4a; }
.pill.client { background: #f2ecf7; color: #6a4a8f; }
.pill.bookkeeper { background: #fdf0e6; color: #8a5220; }

/* Several roles on one row wrap rather than widening the column. */
.rolepills { display: inline-flex; flex-wrap: wrap; gap: 4px; }

/* ---------------------------------------------------------- time grid --- */

.grid-wrap { overflow-x: auto; }

table.grid { min-width: 940px; }
table.grid th, table.grid td { padding: 7px 8px; vertical-align: middle; }
table.grid th.day, table.grid td.day { width: 86px; text-align: center; padding: 5px 4px; }
table.grid th.day small { display: block; font-weight: 600; color: var(--text-dim); }
table.grid td.day.weekend, table.grid th.day.weekend { background: #f4f7fa; }
table.grid th.day.today { color: var(--accent-dark); }
table.grid td.day.today { box-shadow: inset 0 -2px 0 var(--accent); }
table.grid td.day.future input { background: #fafbfc; color: var(--text-dim); }

.cell { display: flex; flex-direction: column; align-items: stretch; gap: 2px; }
.cell input {
  width: 100%; text-align: center; padding: 6px 3px;
  font-variant-numeric: tabular-nums;
}
.cell input.invalid { border-color: var(--danger); background: #fdf3f2; }
.cell .note-btn {
  border: 0; background: none; padding: 0; cursor: pointer;
  font-size: 11px; line-height: 1.2; color: #b3c3d1;
}
.cell .note-btn:hover { color: var(--accent); background: none; }
.cell .note-btn.has-note { color: var(--accent); font-weight: 700; }

/* Approved time off on the grid: present, counted, but plainly not editable. */
table.grid tr.absence-row td { background: #f7f9fb; color: var(--text-dim); font-style: italic; }
table.grid tr.absence-row .project-cell { font-style: normal; }
table.grid tr.absence-row:hover td { background: #f2f6fa; }

.dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 7px; vertical-align: baseline;
}

.row-total, .col-total {
  text-align: center; font-weight: 700; font-variant-numeric: tabular-nums;
}
table.grid tfoot td { background: #f5f7fa; font-weight: 700; border-top: 2px solid var(--border); }
table.grid tbody tr:hover { background: #f7fafc; }
table.grid .project-cell { min-width: 260px; }
table.grid .project-cell .muted { font-size: 12px; }

.week-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.week-bar .nav-week { display: flex; align-items: center; gap: 8px; }
.week-bar h2 { margin: 0; font-size: 16px; }
.week-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.dirty-flag { color: var(--warn); font-size: 12.5px; font-weight: 600; }

/* ------------------------------------------------------- dashboard KPIs --- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 13px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.kpi .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-dim); font-weight: 700;
}
.kpi .value {
  font-size: 22px; font-weight: 700; margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.kpi .sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.kpi.accent .value { color: var(--accent-dark); }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }

/* A tile that leads somewhere says so, but only once you approach it. */
.kpi-link {
  display: block; text-decoration: none; color: inherit;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}
.kpi-link:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(26, 127, 193, 0.16);
  transform: translateY(-1px);
}
.kpi-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kpi .kpi-go {
  font-size: 11.5px; font-weight: 600; color: var(--accent-dark);
  margin-top: 8px; opacity: 0; transition: opacity 0.12s;
}
.kpi-link:hover .kpi-go, .kpi-link:focus-visible .kpi-go { opacity: 1; }

.chart-hint { font-size: 11.5px; color: var(--text-dim); margin: 0 0 8px; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.chart-box { position: relative; height: 262px; }

.period-bar { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.period-bar .presets { display: flex; gap: 6px; }

/* -------------------------------------------------------------- notices --- */

.notice { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 15px; font-size: 13.5px; }
.notice.error { background: #fdecea; border: 1px solid #f5c6c2; color: #922; }
.notice.ok { background: #e8f6ed; border: 1px solid #bfe3cc; color: #1c6b3f; }
.notice.info { background: #e9f2fa; border: 1px solid #c3dcf0; color: #17527d; }
.notice.warn { background: #fdf4e3; border: 1px solid #f0dcb0; color: #8a5a00; }

/* A notice the user can wave away to reclaim the vertical space. */
.notice.dismissible { position: relative; padding-right: 38px; }
.notice .notice-close {
  position: absolute; top: 6px; right: 7px;
  background: none; border: 0; padding: 2px 6px;
  font-size: 14px; line-height: 1; cursor: pointer;
  color: inherit; opacity: 0.55; font-weight: 700;
}
.notice .notice-close:hover { opacity: 1; background: rgba(0, 0, 0, 0.06); }

.linkbox {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; word-break: break-all;
  background: #f5f7fa; border: 1px solid var(--border); border-radius: 4px;
  padding: 9px 11px; margin: 9px 0;
}

.empty { padding: 34px 16px; text-align: center; color: var(--text-dim); }

/* ---------------------------------------------------------- auth pages --- */

.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 22px;
  background: linear-gradient(160deg, #16324f, #0d1f33);
}
.auth-card {
  background: #fff; border-radius: 9px; padding: 30px;
  width: 100%; max-width: 400px; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.3);
}
.auth-card h1 { margin: 0 0 5px; font-size: 20px; }
.auth-card .sub { color: var(--text-dim); margin: 0 0 20px; font-size: 13.5px; }
.auth-card button[type=submit] { width: 100%; padding: 10px; margin-top: 5px; }
.auth-alt { margin-top: 15px; text-align: center; font-size: 13px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 30, 45, 0.55);
  display: grid; place-items: center; padding: 20px; z-index: 20;
}
.modal {
  background: #fff; border-radius: 8px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 {
  margin: 0; padding: 15px 18px; font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 18px; }
.modal-foot {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 9px;
}

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .nav { width: 100%; flex: none; height: auto; position: relative; }
  .nav-scroll { max-height: 55vh; }
}

/* Elevated administrative session: deliberately conspicuous. The point of a
   time-boxed power is that you can see at a glance that you are holding it. */
.elevation { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.elevation.active {
  background: #fff4e5; border: 1px solid #f0b429; color: #8a5a00;
  border-radius: 999px; padding: 3px 6px 3px 12px;
}
.elevation.active .dot {
  width: 8px; height: 8px; border-radius: 50%; background: #f0b429;
  animation: elevation-pulse 2s ease-in-out infinite;
}
@keyframes elevation-pulse { 50% { opacity: 0.35; } }
.elevation.active .label { font-weight: 600; }

/* Banner on a record that is only editable because of the elevation. */
.override-warning {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #fff4e5; border: 1px solid #f0b429; color: #8a5a00;
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 13px;
}

@media (max-width: 820px) {
  .elevation.active { padding: 3px 6px 3px 10px; }
  /* Shed the duration, never the word "Elevated" — the indicator is the only
     thing stopping a session staying elevated unnoticed. */
  .elevation.active .held { display: none; }
}

/* Permission grant matrix: grouped by module, because that is how someone
   reasons about it rather than as a flat list of permission names. */
.perm-matrix { display: grid; gap: 14px; max-height: 55vh; overflow-y: auto; padding-right: 4px; }
.perm-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.perm-group-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.perm-group-head strong { text-transform: capitalize; }
.perm-group-head .spacer { flex: 1; }
.perm-row { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; font-size: 13px; }
.perm-row code { display: block; font-size: 11px; }

/* Report totals: the line most people actually read. */
.report-total {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 7px 0; border-top: 1px solid var(--border); font-size: 13px;
}
.report-total:first-child { border-top: 0; }
.report-total.ok strong { color: var(--ok); }
.report-total.bad strong { color: var(--danger); }

/* The letterhead on an accounting report: shown on screen so that what you see
   is what prints, and carrying the three things a filed report must state. */
.report-head { margin: 0 0 16px; }
.report-head-company { font-size: 15px; font-weight: 700; }
.report-head-title { font-size: 20px; font-weight: 700; margin-top: 2px; }
.report-head-period { font-size: 13px; color: var(--text-dim); margin-top: 3px; }
.report-head-generated { font-size: 11.5px; color: var(--text-dim); margin-top: 1px; }

@media print {
  /* Paper is not a viewport: drop the chrome and let the report have the page. */
  .nav, .topbar, .no-print { display: none !important; }
  .app { display: block; }
  .main { display: block; }
  .content { padding: 0; }
  html, body { background: #fff; }

  @page { margin: 14mm; }

  body { font-size: 11pt; color: #000; }
  .card {
    border: 0;
    border-radius: 0;
    margin: 0 0 10pt;
    /* A section split mid-way reads as two unrelated tables. */
    break-inside: avoid;
  }
  .card > h2 {
    font-size: 12pt; font-weight: 700; padding: 0 0 3pt;
    border-bottom: 1pt solid #000; margin: 0 0 5pt; background: none;
  }
  .card-body { padding: 0; }

  .report-head { border-bottom: 2pt solid #000; padding-bottom: 6pt; }
  .report-head-company, .report-head-title { color: #000; }
  .report-head-period, .report-head-generated { color: #333; }

  /* A ledger running past one page needs its column headings on every page. */
  thead { display: table-header-group; }
  tr, .report-total { break-inside: avoid; }
  th, td { padding: 3pt 6pt; border-bottom: 0.5pt solid #999; }
  th { background: none; color: #000; border-bottom: 1pt solid #000; }
  .table-wrap { overflow: visible; }

  /* Totals and the balance check are the lines that get read first. */
  .report-total { font-size: 11pt; border-top: 0.5pt solid #666; padding: 3pt 0; }
  .report-total.ok strong, .report-total.bad strong { color: #000; }

  /* Background fills are commonly dropped by printers, so the sales-tax caveat
     keeps a border instead of relying on its tint to stand out. */
  .notice { border: 1pt solid #000 !important; background: none !important; color: #000 !important; }

  /* Screen greys wash out on paper; an empty section must still be readable. */
  .muted, .small.muted, td.muted { color: #333; }

  a { text-decoration: none; color: #000; }
}
