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

:root {
  --primary:      #4f46e5;
  --primary-hover:#4338ca;
  --primary-light:#eef2ff;
  --success:      #10b981;
  --success-bg:   #ecfdf5;
  --success-border:#a7f3d0;
  --danger:       #ef4444;
  --danger-bg:    #fef2f2;
  --danger-border:#fecaca;
  --warning:      #f59e0b;
  --warning-bg:   #fffbeb;
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --border-light: #f1f5f9;
  --text:         #1e293b;
  --text-secondary:#64748b;
  --text-muted:   #94a3b8;
  --radius:       8px;
  --radius-sm:    4px;
  --shadow:       0 1px 3px rgba(0,0,0,.08),0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07),0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 24px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.logo {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -.3px;
  white-space: nowrap;
}
.logo span { color: var(--text-secondary); font-weight: 400; }
nav { display: flex; gap: 4px; align-items: center; }
.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-link:hover { color: var(--text); background: var(--bg); }
.nav-link.active { color: var(--primary); background: var(--primary-light); }

/* ── Layout ── */
.main { padding: 28px 24px; max-width: 1300px; margin: 0 auto; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }
.page-header .sub { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-group label { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Inputs ── */
select, input[type="text"], input[type="password"],
input[type="number"], input[type="email"], textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 11px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger   { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost    { background: none; border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  background: var(--bg);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
thead th.right { text-align: right; }
thead th.center { text-align: center; }
tbody tr { border-bottom: 1px solid var(--border-light); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafbfd; }
tbody td { padding: 10px 14px; vertical-align: middle; }
tbody td.right { text-align: right; }
tbody td.center { text-align: center; }
tbody td.mono { font-variant-numeric: tabular-nums; }

/* ── Colored department cells ── */
td.cell-over {
  background: var(--danger-bg) !important;
  color: #991b1b;
}
td.cell-ok {
  background: var(--success-bg) !important;
  color: #065f46;
}
td.diff-over {
  background: var(--danger-bg) !important;
  color: #991b1b;
}
td.diff-under {
  background: var(--success-bg) !important;
  color: #065f46;
}
td.cell-warn {
  background: var(--warning-bg) !important;
  color: #92400e;
}

.cell-hours {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}
.cell-hours .h-main { font-weight: 600; font-variant-numeric: tabular-nums; }
.cell-hours .h-diff { font-size: 12px; font-variant-numeric: tabular-nums; }
.cell-hours .h-budget { font-size: 11px; color: var(--text-muted); }

/* ── Status badges ── */
.over-badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.badge-over   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid var(--danger-border); }
.badge-under  { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.badge-zero   { background: var(--bg);         color: var(--text-muted); }
.badge-ok     { background: var(--success-bg); color: var(--success); }
.badge-neutral{ background: var(--bg);         color: var(--text-muted); }

/* ── Client link ── */
.client-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color .15s;
}
.client-link:hover { color: var(--primary); }
.client-link .arrow { opacity: 0; transition: opacity .15s; }
.client-link:hover .arrow { opacity: 1; }

/* ── Expandable AM row ── */
.expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: inherit;
  font-size: 13.5px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  transition: color .15s;
}
.expand-btn .chevron {
  width: 14px; height: 14px;
  transition: transform .2s;
  flex-shrink: 0;
  color: var(--text-muted);
}
.expand-btn.open .chevron { transform: rotate(90deg); }
.am-detail-row td { padding: 8px 14px 8px 38px !important; background: var(--primary-light) !important; }
.am-detail-inner { display: flex; flex-wrap: wrap; gap: 6px 20px; align-items: center; }
.am-detail-item { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-secondary); }
.am-detail-item strong { color: var(--text); font-variant-numeric: tabular-nums; }
.am-tag { font-size: 10.5px; padding: 2px 6px; border-radius: 99px; font-weight: 600; }
.am-tag-mgr { background: var(--primary-light); color: var(--primary); }
.am-tag-fl  { background: #fef9c3; color: #854d0e; }

/* ── Inline edit ── */
.inline-input {
  width: 75px;
  text-align: right;
  padding: 4px 7px;
  border: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  background: #fff;
  color: var(--text);
  outline: none;
}
.inline-input:focus { box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.save-indicator {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  white-space: nowrap;
}
.save-indicator.saving { background: var(--primary-light); color: var(--primary); }
.save-indicator.saved  { background: var(--success-bg); color: var(--success); }
.save-indicator.error  { background: var(--danger-bg); color: var(--danger); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md), 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 440px;
  animation: modal-in .15s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(.97) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  padding: 20px 24px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
}
.modal-close:hover { color: var(--text); background: var(--bg); }
.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
  padding: 16px 24px 20px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.field input, .field select { width: 100%; }
.field .hint { font-size: 12px; color: var(--text-muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Stats row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 11.5px; color: var(--text-secondary); font-weight: 500; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 5px; }
.stat-card .value { font-size: 20px; font-weight: 700; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.stat-card .value.over  { color: var(--danger); }
.stat-card .value.under { color: var(--success); }

/* ── States ── */
.state-box { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.state-box .icon { font-size: 36px; margin-bottom: 12px; }
.state-box h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.state-box p { font-size: 13.5px; max-width: 380px; margin: 0 auto 16px; }
.state-box a { color: var(--primary); }

.loading-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 40px; color: var(--text-secondary); font-size: 14px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
}
.alert-danger  { background: var(--danger-bg);  color: #991b1b; border: 1px solid var(--danger-border); }
.alert-success { background: var(--success-bg); color: #065f46; border: 1px solid var(--success-border); }
.alert-info    { background: var(--primary-light); color: #3730a3; border: 1px solid #c7d2fe; }

/* ── Settings ── */
.settings-grid { display: grid; gap: 24px; }
.code-block {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 16px 18px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12.5px;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
}
.code-block-wrap { position: relative; }
.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 12px;
  padding: 4px 10px;
  background: rgba(255,255,255,.1);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.copy-btn:hover { background: rgba(255,255,255,.2); }

/* ── Back link ── */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-secondary); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  padding: 5px 10px 5px 6px;
  border-radius: var(--radius);
  transition: all .15s;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--text); background: var(--border); }

/* ── Detail month rows ── */
.month-future td { color: var(--text-muted); }
.month-current td:first-child { font-weight: 700; }

/* ── Entry modal (per-employee) ── */
.entry-section { margin-bottom: 16px; }
.entry-section:last-child { margin-bottom: 0; }
.entry-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.entry-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-light);
}
.entry-row:last-child { border-bottom: none; }
.entry-name { flex: 1; font-size: 13.5px; font-weight: 500; }
.emp-hours-input {
  width: 72px;
  text-align: right;
  padding: 5px 8px;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.entry-unit { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; min-width: 30px; }
.fl-calc { font-size: 11px; color: var(--warning); white-space: nowrap; }
.entry-totals {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.entry-totals strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ── AM breakdown sub-row ── */
.am-breakdown-row td {
  padding: 6px 14px 6px 36px !important;
  background: var(--primary-light) !important;
  border-bottom: 1px solid #e0e7ff !important;
}
.am-breakdown-row:last-of-type td { border-bottom: none !important; }
.am-breakdown-inner { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: center; }
.am-breakdown-item { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-secondary); }
.am-breakdown-item .emp-hours { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.fl-divider { font-size: 11px; color: var(--warning); }

/* ── Confirm dialog ── */
.confirm-text { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }
.confirm-text strong { color: var(--text); }

/* ── Responsive ── */
@media (max-width: 700px) {
  .main { padding: 16px 12px; }
  .header-inner { padding: 0 12px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .modal { max-width: 100%; }
}

/* ── Alert warn ── */
.alert-warn { background: var(--warning-bg); color: #92400e; border: 1px solid #fde68a; }
.badge-warn { background: var(--warning-bg); color: #92400e; border: 1px solid #fde68a; }

/* ── Role badges ── */
.role-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 7px; border-radius: 99px; font-size: 10.5px; font-weight: 700;
  white-space: nowrap; flex-shrink: 0; letter-spacing: .2px;
}
.role-am     { background: var(--primary-light); color: var(--primary); }
.role-adv    { background: #fef9c3; color: #854d0e; }
.role-fl     { background: #f0fdf4; color: #166534; }
.role-ignore { background: var(--bg); color: var(--text-muted); }

/* ── Nav user ── */
.nav-user { display: flex; align-items: center; gap: 8px; margin-left: 10px; padding-left: 14px; border-left: 1px solid var(--border); }
.nav-user-email { font-size: 12px; color: var(--text-muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Login page ── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px; max-width: 400px; width: 100%;
  box-shadow: var(--shadow-md);
}
.login-logo { font-size: 22px; font-weight: 800; color: var(--primary); text-align: center; margin-bottom: 6px; letter-spacing: -.3px; }
.login-logo span { color: var(--text-secondary); font-weight: 400; }
.login-subtitle { text-align: center; font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }

/* ── Client type badges ── */
.type-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.4;
}
.type-retainer { background: var(--bg); color: var(--text-secondary); }
.type-project  { background: #fef9c3; color: #854d0e; border: 1px solid #fde68a; }

/* ── Sortable table headers ── */
thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color .15s;
}
thead th.sortable:hover { color: var(--primary); }
.sort-ind { font-size: 11px; opacity: .5; }
thead th.sortable:hover .sort-ind { opacity: 1; }

/* ── Adjustment / correction badge ── */
.adj-badge {
  font-size: 10.5px;
  color: var(--primary);
  font-weight: 600;
  white-space: nowrap;
  background: var(--primary-light);
  border-radius: 99px;
  padding: 1px 6px;
  margin-left: 4px;
}

/* ── Bulk action bar ── */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--primary-light);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--primary);
  flex-wrap: wrap;
}
.bulk-bar #bulkCount { margin-right: 4px; }

/* ── Utilization bars ── */
.util-bar-cell { padding: 8px 10px !important; }
.util-bar-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 72px; }
.util-bar-track { width: 100%; height: 5px; background: var(--border); border-radius: 99px; overflow: hidden; }
.util-bar-fill { height: 100%; border-radius: 99px; }
.util-bar-fill.low    { background: var(--success); }
.util-bar-fill.medium { background: var(--warning); }
.util-bar-fill.high   { background: var(--danger); }
.util-bar-label { font-size: 10px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.hidden { display: none !important; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.font-mono { font-variant-numeric: tabular-nums; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Utilization clickable month cell ── */
td.util-month-clickable {
  cursor: pointer;
  transition: background .15s;
}
td.util-month-clickable:hover {
  background: var(--primary-light) !important;
}
td.util-month-clickable:hover .util-bar-fill.low    { background: var(--primary); }
td.util-month-clickable:hover .util-bar-fill.medium { background: var(--primary); }
td.util-month-clickable:hover .util-bar-fill.high   { background: var(--primary); }

/* ── Diff column colors (overview) ── */
td.diff-over  { background: var(--danger-bg)  !important; color: #991b1b; }
td.diff-under { background: var(--success-bg) !important; color: #065f46; }
