/* ============================================================
   QB Time Dashboard — Dark Theme
   ============================================================ */

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #273549;
  --border:    #334155;
  --primary:   #0ea5e9;
  --primary-h: #38bdf8;
  --success:   #22c55e;
  --warn:      #f59e0b;
  --danger:    #ef4444;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --radius:    0.5rem;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Header ---- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
}
.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
  white-space: nowrap;
}

/* ---- Tab navigation ---- */
.tab-nav { display: flex; gap: 0.25rem; }
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}
.tab-btn:hover { color: var(--text); background: var(--surface2); }
.tab-btn.active { color: var(--primary); background: rgba(14,165,233,0.12); font-weight: 600; }

/* ---- Sync indicator ---- */
.sync-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--primary);
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Main ---- */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ---- Tab panels ---- */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Section header ---- */
.section-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.section-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

/* ---- Inline filter ---- */
.inline-filter {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.inline-filter label,
.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

/* ---- Inputs / Selects ---- */
input[type="date"],
input[type="number"],
input[type="password"],
input[type="text"],
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 0.75);
  color: var(--text);
  font-size: 0.875rem;
  padding: 0.4rem 0.6rem;
  outline: none;
  transition: border-color 0.15s;
}
input[type="date"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="text"]:focus,
select:focus { border-color: var(--primary); }
input[type="number"],
input[type="password"],
input[type="text"] { width: 100%; }

/* ---- Buttons ---- */
.btn {
  background: var(--primary);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-h); }
.btn:active { opacity: 0.85; }
.btn.btn-sm { padding: 0.35rem 0.85rem; font-size: 0.8rem; }
.btn.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn.btn-danger { background: #dc2626; }
.btn.btn-danger:hover { background: #b91c1c; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- Summary cards ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}
.card-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.card-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---- Charts ---- */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}
.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.chart-box h3 { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---- Chart header row (title + filter button) ---- */
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.chart-header h3 { margin-bottom: 0; }

/* Multiple filter buttons side by side */
.chart-filters-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* ---- Chart filter dropdown ---- */
.chart-filter { position: relative; }

.chart-filter-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 0.75);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.28rem 0.65rem;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chart-filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.chart-filter-btn.has-filter {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(14,165,233,0.1);
}

.chart-filter-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 5px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
  min-width: 210px;
  max-width: 290px;
  z-index: 200;
  overflow: hidden;
}
.chart-filter-panel.hidden { display: none; }

.filter-panel-actions {
  display: flex;
  gap: 0.75rem;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.filter-panel-actions button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
}
.filter-panel-actions button:hover { text-decoration: underline; }

.filter-item-list {
  max-height: 230px;
  overflow-y: auto;
  padding: 0.35rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.filter-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.32rem 0.8rem;
  font-size: 0.82rem;
  transition: background 0.1s;
  user-select: none;
}
.filter-item:hover { background: var(--surface2); }
.filter-item input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}
.filter-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-wide { grid-column: 1 / -1; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap-tall { height: 280px; }

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th {
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.65rem 0.9rem;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.data-table td {
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.9rem;
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface2); }
.empty-msg { color: var(--text-muted); font-style: italic; text-align: center; padding: 2rem !important; }

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.page-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 0.6);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  transition: border-color 0.15s, color 0.15s;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: rgba(14,165,233,0.15); border-color: var(--primary); color: var(--primary); font-weight: 700; }
.page-info { font-size: 0.8rem; color: var(--text-muted); margin-left: 0.5rem; }

/* ---- Card panel (config/sync sections) ---- */
.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card-panel h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.4rem; }
.hint { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; }
.panel-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.panel-header-row h3 { margin-bottom: 0; }

/* ---- Form helpers ---- */
.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}
.form-row label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.btn-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* ---- Toggle switches ---- */
.toggle-list { display: flex; flex-direction: column; gap: 0.75rem; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 0.6rem 0.8rem;
  border-radius: calc(var(--radius) * 0.75);
  transition: background 0.12s;
}
.toggle-row:hover { background: var(--surface2); }
.toggle-row span { font-size: 0.9rem; }
.toggle-row small { display: block; color: var(--text-muted); font-size: 0.76rem; }
.toggle { display: none; }
.toggle-slider {
  position: relative;
  width: 42px; height: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-shrink: 0;
  transition: background 0.2s;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 16px; height: 16px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle:checked + .toggle-slider { background: rgba(14,165,233,0.25); border-color: var(--primary); }
.toggle:checked + .toggle-slider::after { transform: translateX(18px); background: var(--primary); }

/* ---- Token status ---- */
.token-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: calc(var(--radius) * 0.75);
  border: 1px solid var(--border);
  background: var(--surface2);
}
.token-status::before { content: '●'; font-size: 0.7rem; }
.token-status.ok { color: var(--success); border-color: rgba(34,197,94,0.3); }
.token-status.ok::before { color: var(--success); }
.token-status.warn { color: var(--warn); border-color: rgba(245,158,11,0.3); }
.token-status.warn::before { color: var(--warn); }
.token-status.err { color: var(--danger); border-color: rgba(239,68,68,0.3); }
.token-status.err::before { color: var(--danger); }

/* ---- Alerts ---- */
.alert {
  padding: 0.65rem 0.9rem;
  border-radius: calc(var(--radius) * 0.75);
  font-size: 0.85rem;
  margin-top: 0.75rem;
}
.alert-success { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.3); color: #86efac; }
.alert-error { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }
.alert-info { background: rgba(14,165,233,0.1); border: 1px solid rgba(14,165,233,0.25); color: #7dd3fc; }
.hidden { display: none !important; }

/* ---- Status badges ---- */
.badge {
  display: inline-block;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-error   { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-running { background: rgba(14,165,233,0.15); color: var(--primary); }
.badge-active  { background: rgba(34,197,94,0.1); color: var(--success); }
.badge-inactive { background: rgba(148,163,184,0.1); color: var(--text-muted); }

/* ---- Toast notifications ---- */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 999;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.85rem;
  min-width: 260px;
  max-width: 380px;
  padding: 0.75rem 1rem;
  animation: slide-in 0.2s ease;
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--danger); }
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .chart-grid { grid-template-columns: 1fr; }
  .chart-wide { grid-column: auto; }
  .header-inner { gap: 1rem; }
  .logo { font-size: 0.95rem; }
}

/* ============================================================
   Rate Sheet selector bar
   ============================================================ */
.rs-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}
.rs-bar-label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.rs-default-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  letter-spacing: 0.04em;
}
.rs-override-badge {
  display: inline-block;
  color: var(--primary);
  font-size: 0.65rem;
  margin-left: 0.3rem;
  vertical-align: middle;
}

/* ============================================================
   Staff & Rates — column visibility bar
   ============================================================ */
.col-vis-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.9rem;
  font-size: 0.8rem;
}
.col-vis-label { color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.72rem; }
.col-vis-bar label { display: flex; align-items: center; gap: 0.3rem; cursor: pointer; color: var(--text-muted); }
.col-vis-bar label:hover { color: var(--text); }
.col-vis-bar input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; }

/* ============================================================
   Staff modal
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1rem;
}
.modal-backdrop.hidden { display: none; }

.modal,
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.25);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  width: 100%;
  max-width: 620px;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: calc(var(--radius) * 0.5);
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }
.modal-body { padding: 1.25rem 1.5rem; overflow-y: auto; }

/* Jobcode filter modal tree */
#jcfm-tree { background: var(--surface); }
#jcfm-tree .jcfm-node { border-bottom: 1px solid transparent; }
#jcfm-tree .jcfm-node:hover > div { background: var(--surface2); }
#jcfm-tree .jcfm-toggle {
  display: inline-block;
  width: 1.1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  flex-shrink: 0;
}
.modal-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Form grid inside modal */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.25rem;
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.form-field-wide { grid-column: 1 / -1; }
.req { color: var(--danger); }

/* ============================================================
   Cost Report — customize panel
   ============================================================ */
.customize-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.customize-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.25rem;
}
.customize-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}
.ck-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.84rem;
  cursor: pointer;
  padding: 0.18rem 0;
  color: var(--text);
}
.ck-row input { accent-color: var(--primary); cursor: pointer; }

/* Cost table column visibility */
.cost-col-title,
.cost-col-rate_type,
.cost-col-hourly_rate,
.cost-col-hours,
.cost-col-cost,
.cost-col-cost_pct { transition: display 0s; }

/* ============================================================
   Pivot table: User × Job Code
   ============================================================ */
.pivot-scroll {
  overflow-x: auto;
  overflow-y: visible;
}
.pivot-table {
  min-width: 500px;
  white-space: nowrap;
}
/* Sticky first column */
.pivot-sticky {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
  white-space: normal;
  min-width: 160px;
  max-width: 220px;
}
.pivot-table thead .pivot-sticky {
  background: var(--surface2);
}
.pivot-table tbody tr:hover .pivot-sticky { background: var(--surface2); }

/* Total column / row */
.pivot-total-col {
  font-weight: 700;
  background: rgba(14,165,233,0.07);
  border-left: 1px solid var(--border);
}
.pivot-table thead .pivot-total-col { background: rgba(14,165,233,0.14); }

/* Footer totals row */
.pivot-footer td {
  border-top: 2px solid var(--border);
  font-weight: 700;
  background: var(--surface2);
}
.pivot-footer .pivot-sticky { background: var(--surface2); }

/* Rate type badges in staff table */
.rt-billable { color: var(--success); }
.rt-overhead { color: var(--warn); }
.rt-mixed    { color: var(--primary); }
.rt-unknown  { color: var(--text-muted); }

/* ============================================================
   Invoice tab
   ============================================================ */

.invoice-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 820px) {
  .invoice-form-grid { grid-template-columns: 1fr; }
}

/* Inline edit inputs inside invoice tables */
.inv-cell-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 0.875rem;
  padding: 0.2rem 0.25rem;
  outline: none;
  font-family: var(--font);
  transition: border-color 0.15s;
}
.inv-cell-input:focus {
  border-bottom-color: var(--primary);
  background: var(--surface2);
  border-radius: 2px 2px 0 0;
}
input[type="number"].inv-cell-input { text-align: right; }

.inv-amount-cell {
  text-align: right;
  white-space: nowrap;
  font-weight: 600;
  color: var(--text);
}

.inv-textarea {
  width: 100%;
  resize: vertical;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font);
  line-height: 1.5;
  outline: none;
}
.inv-textarea:focus { border-color: var(--primary); }

/* ============================================================
   Theme colour pickers (Configuration tab)
   ============================================================ */

.theme-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.theme-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.theme-row span {
  min-width: 10rem;
  font-size: 0.875rem;
  color: var(--text);
}

.theme-row input[type="color"] {
  width: 2.5rem;
  height: 1.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  cursor: pointer;
  padding: 0.1rem;
}

/* ============================================================
   Print / PDF (Cost Report)
   ============================================================ */

@media print {
  .app-header,
  .tab-nav,
  .sync-indicator,
  .section-header .inline-filter,
  .section-header .btn-row,
  #cost-export-bar,
  #cost-customize-toggle,
  #cost-customize,
  .chart-filter,
  .filter-panel-actions,
  .pagination,
  .modal-backdrop {
    display: none !important;
  }

  body { background: #fff; color: #000; }

  .app-main { padding: 0; max-width: 100%; }

  .tab-panel { display: none !important; }
  #tab-cost.tab-panel { display: block !important; }

  .card { border: 1px solid #ccc; background: #f9f9f9; }
  .card-value { color: #000; }
  .card-label { color: #555; }

  .data-table th { background: #ddd; color: #000; }
  .data-table td { color: #000; border-color: #ccc; }

  .chart-box,
  #cost-chart-ujc-box { break-inside: avoid; }

  /* ── Projects tab: print staff hours report ─── */
  .printing-projects #tab-cost.tab-panel { display: none !important; }
  .printing-projects #tab-projects.tab-panel { display: block !important; }

  /* Hide everything except staff hours */
  .printing-projects #tab-projects .section-header,
  .printing-projects #tab-projects .proj-tree-panel,
  .printing-projects #tab-projects #jc-detail-empty,
  .printing-projects #tab-projects #proj-alert,
  .printing-projects #jc-detail-print,
  .printing-projects #jc-detail-active-badge,
  .printing-projects #jc-detail-content > .card-panel,
  .printing-projects #jc-detail-content > .cards { display: none !important; }

  /* Show only the staff hours section full-width */
  .printing-projects #tab-projects .proj-layout { display: block !important; }
  .printing-projects #tab-projects .proj-right-panel {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 !important;
  }
  .printing-projects #jc-detail-content { display: block !important; }
  .printing-projects .bud-section { border: none !important; }
  .printing-projects .bud-section-hdr { margin-bottom: .5rem; }
  .printing-projects #jc-rate-sheet-select,
  .printing-projects #jc-rate-sheet-saving,
  .printing-projects label[for="jc-rate-sheet-select"] { display: none !important; }
  .printing-projects .bud-staff-scroll { overflow: visible !important; max-height: none !important; }
  .printing-projects .bud-staff-table { font-size: 9pt; width: 100%; }
  .printing-projects .bud-staff-table th,
  .printing-projects .bud-staff-table td { padding: .25rem .4rem; }
}

/* ============================================================
   Login / Setup pages
   ============================================================ */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 22rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.auth-card h1 {
  font-size: 1.2rem;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.auth-card h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.25rem;
}

.auth-card .hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.auth-card .form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.auth-card input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.auth-card input:focus { border-color: var(--primary); }

.auth-card .auth-submit {
  width: 100%;
  margin-top: 0.5rem;
}

.auth-error {
  background: rgba(239,68,68,0.12);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
}

/* ---- Header user info ---- */

.header-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.header-username {
  color: var(--text-muted);
}

.role-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.role-admin  { background: rgba(14,165,233,0.15); color: var(--primary); }
.role-viewer { background: rgba(148,163,184,0.15); color: var(--text-muted); }

/* ================================================================
   Projects tab
   ================================================================ */

.proj-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 700px) {
  .proj-layout { grid-template-columns: 1fr; }
}

.proj-tree-panel {
  max-height: calc(100vh - 10rem);
  overflow-y: auto;
  position: sticky;
  top: 1rem;
}

/* Right panel: scrolls independently; contains card-panels + tables */
.proj-right-panel {
  min-width: 0;   /* allow grid child to shrink below content size */
  overflow: hidden;
}

.proj-tree-client-row {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .45rem .75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
}
.proj-tree-client-row:hover { background: var(--surface-alt); }

.proj-tree-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 .2rem;
  transition: transform .15s;
  font-size: .8rem;
  flex-shrink: 0;
}
.proj-tree-toggle.open { transform: rotate(90deg); }

.proj-tree-client-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.proj-tree-client-edit {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 .25rem;
  font-size: .8rem;
  opacity: 0;
  flex-shrink: 0;
}
.proj-tree-client-row:hover .proj-tree-client-edit { opacity: 1; }

.proj-tree-children { background: rgba(0,0,0,.12); }
.proj-tree-children.collapsed { display: none; }

.proj-tree-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .75rem .4rem 2rem;
  cursor: pointer;
  font-size: .85rem;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255,255,255,.03);
}
.proj-tree-item:hover { background: rgba(14,165,233,.08); color: var(--text); }
.proj-tree-item.selected {
  background: rgba(14,165,233,.15);
  color: var(--primary);
  font-weight: 500;
}

.proj-tree-add-project {
  display: block;
  padding: .35rem .75rem .35rem 2rem;
  font-size: .8rem;
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  width: 100%;
}
.proj-tree-add-project:hover { color: var(--primary); }

.proj-detail-panel { min-height: 12rem; }

.proj-breadcrumb {
  font-size: .75rem;
  color: var(--text-muted);
  margin: 0 0 .25rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.proj-detail-grid {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: .45rem .75rem;
  font-size: .875rem;
  align-items: start;
}

.proj-detail-label {
  text-transform: uppercase;
  font-size: .7rem;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding-top: .15rem;
}

.badge-closed   { background: rgba(245,158,11,.12); color: #f59e0b; }
.badge-archived { background: rgba(148,163,184,.1);  color: var(--text-muted); }

/* ================================================================
   Budgeting tab
   ================================================================ */

.num { text-align: right; }
td.num { text-align: right; }

.bud-project-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: .75rem;
  flex-wrap: wrap;
}

.bud-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.bud-section-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: .75rem;
  flex-wrap: wrap;
}

.bud-section-title {
  margin: 0 0 .15rem;
  font-size: .95rem;
  font-weight: 600;
}

.bud-section-sub {
  margin: 0;
  font-size: .78rem;
  color: var(--text-muted);
}

/* Wide scrollable staff hours table */
.bud-staff-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.bud-staff-table {
  min-width: 100%;
  white-space: nowrap;
  border-collapse: collapse;
}

/* Sticky first column (Description) */
.bud-staff-table thead th:first-child,
.bud-staff-table tbody td:first-child,
.bud-staff-table tfoot td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-width: 11rem;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bud-week-th   { font-size: .78rem; font-weight: 500; white-space: nowrap; }
.bud-week-cell { font-size: .88rem; }

.bud-progress-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.bud-progress-track {
  flex: 1;
  height: 7px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.bud-progress-bar {
  height: 100%;
  border-radius: 999px;
  transition: width .25s;
}
.bud-progress-bar.ok   { background: #22c55e; }
.bud-progress-bar.warn { background: #f59e0b; }
.bud-progress-bar.over { background: #ef4444; }

.bud-progress-pct       { font-size: .8rem; white-space: nowrap; min-width: 2.8rem; text-align: right; color: var(--text-muted); }
.bud-progress-pct.warn  { color: #f59e0b; font-weight: 600; }
.bud-progress-pct.over  { color: #ef4444; font-weight: 600; }

.text-danger  { color: #ef4444; font-weight: 600; }
.text-success { color: #22c55e; }
.text-muted   { color: var(--text-muted); }

.select-sm {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .875rem;
  padding: .3rem .5rem;
}

/* ── Job Codes tree ─────────────────────────────────────────── */

.jc-tree-root {
  list-style: none;
  margin: 0;
  padding: 0;
}

.jc-parent-row {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem .75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.jc-parent-row:hover { background: var(--surface-alt); }
.jc-parent-row.selected { background: rgba(14,165,233,.12); color: var(--primary); }

.jc-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .85rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
  transition: transform .15s;
  padding: 0;
}
.jc-toggle.open { transform: rotate(90deg); }

.jc-parent-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .9rem;
}

.jc-inactive-label {
  font-size: .72rem;
  color: var(--text-muted);
  opacity: .65;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 .3rem;
  flex-shrink: 0;
}

.jc-children {
  list-style: none;
  margin: 0;
  padding: 0;
  background: rgba(0,0,0,.12);
}
.jc-children.collapsed { display: none; }

.jc-child-row {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .75rem;          /* left-padding set dynamically per depth via inline style */
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.04);
  font-size: .875rem;
}
.jc-child-row:hover { background: rgba(14,165,233,.08); }
.jc-child-row.selected { background: rgba(14,165,233,.15); color: var(--primary); }

.jc-child-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.jc-no-children {
  padding: .4rem .75rem .4rem 2.25rem;
  font-size: .8rem;
  color: var(--text-muted);
  font-style: italic;
}

.jc-tree-search-none {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
}

/* ── Staff table: budgeted vs unbudgeted sections ──────────────── */

tr.staff-section-label td {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  background: rgba(255,255,255,.04);
  padding: .35rem .75rem;
  border-top: 1px solid var(--border);
}

tr.staff-unbudgeted td {
  opacity: .65;
}

tr.staff-unbudgeted td:first-child::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 1em;
  background: var(--text-muted);
  border-radius: 2px;
  margin-right: .4rem;
  vertical-align: middle;
  opacity: .5;
}

/* ── Staff filter buttons ───────────────────────────────────── */
.jc-filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Job code favorites ─────────────────────────────────────── */
.jc-star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .95rem;
  color: var(--text-muted);
  padding: 0 .15rem;
  flex-shrink: 0;
  line-height: 1;
  opacity: .4;
  transition: opacity .15s, color .15s;
}
.jc-star-btn:hover,
.jc-star-btn.active { opacity: 1; }
.jc-star-btn.active  { color: #f59e0b; }

.jc-fav-divider {
  height: 1px;
  background: var(--border);
  margin: .25rem .5rem;
  list-style: none;
}

/* ── AI Chat bubbles ──────────────────────────────────────── */
.chat-msg { display: flex; }
.chat-user { justify-content: flex-end; }
.chat-assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 85%;
  padding: .75rem 1rem;
  border-radius: .5rem;
  font-size: 1rem;
  line-height: 1.6;
  word-wrap: break-word;
}
.chat-assistant .chat-bubble {
  max-width: 100%;
}
.chat-bubble:not(.chat-rich) { white-space: pre-wrap; }
.chat-user .chat-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: .15rem;
}
.chat-assistant .chat-bubble {
  background: var(--surface2);
  color: var(--text);
  border-bottom-left-radius: .15rem;
}
.chat-typing {
  opacity: 0.6;
  font-style: italic;
}

/* ── Rich markdown content inside assistant bubbles ───────── */
.chat-rich { overflow-x: auto; }
.chat-rich > :first-child { margin-top: 0; }
.chat-rich > :last-child  { margin-bottom: 0; }

.chat-rich h1, .chat-rich h2, .chat-rich h3,
.chat-rich h4, .chat-rich h5, .chat-rich h6 {
  margin: .6rem 0 .3rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
.chat-rich h1 { font-size: 1.3rem; }
.chat-rich h2 { font-size: 1.15rem; }
.chat-rich h3 { font-size: 1.05rem; }

.chat-rich p { margin: .35rem 0; }

.chat-rich ul, .chat-rich ol {
  margin: .35rem 0;
  padding-left: 1.4rem;
}
.chat-rich li { margin: .15rem 0; }
.chat-rich li::marker { color: var(--text-muted); }

.chat-rich strong { font-weight: 600; color: var(--text); }
.chat-rich em { font-style: italic; }

.chat-rich a {
  color: var(--primary);
  text-decoration: underline;
}

/* Inline code */
.chat-rich code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: .25rem;
  padding: .1rem .3rem;
  font-size: .82rem;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* Code blocks */
.chat-rich pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .375rem;
  padding: .6rem .75rem;
  margin: .5rem 0;
  overflow-x: auto;
  font-size: .82rem;
  line-height: 1.5;
}
.chat-rich pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* Tables */
.chat-rich table {
  border-collapse: collapse;
  width: 100%;
  margin: .5rem 0;
  font-size: .95rem;
}
.chat-rich th, .chat-rich td {
  border: 1px solid var(--border);
  padding: .3rem .5rem;
  text-align: left;
}
.chat-rich th {
  background: var(--surface);
  font-weight: 600;
  color: var(--text);
}
.chat-rich tr:nth-child(even) {
  background: rgba(255,255,255,.03);
}

/* Blockquotes */
.chat-rich blockquote {
  border-left: 3px solid var(--primary);
  margin: .5rem 0;
  padding: .25rem .75rem;
  color: var(--text-muted);
}

/* Horizontal rules */
.chat-rich hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: .6rem 0;
}

/* Images (if Claude ever returns any) */
.chat-rich img {
  max-width: 100%;
  border-radius: .375rem;
}

#cost-chat-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: .375rem;
  padding: .6rem 1rem;
  font-size: 1rem;
}
#cost-chat-input:focus {
  outline: none;
  border-color: var(--primary);
}
