:root {
  --brand-primary: #2ec4b6;
  --brand-navy: #1b2a4a;
  --brand-warning: #f4a261;
  --brand-warning-bg: #fff4e6;
  --brand-danger: #e63946;
  --brand-danger-bg: #fde8ea;
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #2d3748;
  --muted: #718096;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }

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

a { color: var(--brand-primary); }

.app-shell { min-height: 100vh; }

.topbar {
  background: var(--brand-navy);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }

.topbar nav a {
  color: #cbd5e0;
  text-decoration: none;
  margin-right: 16px;
}

.topbar nav a.active { color: #fff; font-weight: 600; }

.content { max-width: 1400px; margin: 0 auto; padding: 24px; }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.alert {
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.alert-warning { background: var(--brand-warning-bg); border: 1px solid #f6d365; }
.alert-danger { background: var(--brand-danger-bg); border: 1px solid #f5b5bb; }
.alert-info { background: #ebf8ff; border: 1px solid #bee3f8; }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th { background: #edf2f7; font-weight: 600; white-space: nowrap; }
tr:hover td { background: #fafbfc; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-active { background: #e6fffa; color: #234e52; }
.badge-agreed { background: var(--brand-warning-bg); color: #9a6700; border: 1px solid #f6d365; }
.badge-inactive { background: #edf2f7; color: var(--muted); }
.badge-conflict { background: var(--brand-danger-bg); color: #9b1c1c; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  display: inline-block;
  background: var(--brand-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
}

.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.active { box-shadow: inset 0 0 0 2px var(--brand-navy); }

.cache-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 24px;
  background: #edf2f7;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.btn-sm { padding: 5px 12px; font-size: 12px; }

.muted { color: var(--muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.low-balance { color: var(--brand-danger); font-weight: 600; }

.loading {
  text-align: center;
  padding: 48px;
  color: var(--muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

.week-grid-section { margin-bottom: 28px; }
.week-grid-section h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--brand-navy);
}
.week-grid-section .week-badge {
  font-size: 13px;
  color: var(--muted);
  font-weight: normal;
  margin-left: 8px;
}

table.week-grid { font-size: 12px; min-width: 900px; }
table.week-grid th,
table.week-grid td {
  padding: 6px 8px;
  text-align: center;
  border: 1px solid var(--border);
}
table.week-grid th.row-head,
table.week-grid td.row-head {
  text-align: left;
  min-width: 200px;
  max-width: 320px;
  background: #fff;
  font-weight: 500;
}
table.week-grid td.row-head-child {
  padding-left: 36px;
  font-weight: 400;
  font-size: 11px;
  color: #4a5568;
}
.grid-expand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-right: 10px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #f7fafc;
  color: var(--brand-navy);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  flex-shrink: 0;
}
.grid-expand:hover { background: #edf2f7; }
.grid-expand-spacer {
  display: inline-block;
  width: 15px;
  margin-right: 10px;
  flex-shrink: 0;
}
.row-head-label { vertical-align: middle; margin-left: 0; }
.row-head-title {
  display: block;
  margin-top: 6px;
  font-weight: 600;
}
.row-head-with-toggle .grid-expand-all {
  display: block;
  margin: 0 auto;
}
a.grid-entity-link {
  color: var(--brand-navy);
  text-decoration: none;
}
a.grid-entity-link.low-balance {
  color: var(--brand-danger);
  font-weight: 600;
}
a.grid-entity-link:hover { text-decoration: underline; }
table.week-grid tr.grid-child-row td {
  background: #f8fafc;
}
table.week-grid thead th {
  background: #4a5568;
  color: #fff;
  font-weight: 600;
}
table.week-grid thead tr.subhead th {
  background: #718096;
  font-size: 11px;
  font-weight: 500;
}
table.week-grid th.week-summary,
table.week-grid td.week-summary {
  background: #edf2f7;
  font-weight: 600;
}
table.week-grid tr.totals td {
  background: #e2e8f0;
  font-weight: 700;
}
table.week-grid tr.status-row td {
  background: #fff;
  color: var(--brand-danger);
  font-weight: 600;
  text-align: left;
}
table.week-grid .ok { color: #276749; font-weight: 700; }
table.week-grid td.num-empty { color: #cbd5e0; }

table.week-grid td.grid-drill.clickable,
table.week-grid td.grid-drill:not(:empty) {
  cursor: pointer;
}
table.week-grid td.grid-drill:hover:not(:empty) {
  background: #e6fffa;
}
table.week-grid td.grid-drill.active {
  box-shadow: inset 0 0 0 2px var(--brand-primary);
}

.grid-detail {
  margin-top: 12px;
  padding: 12px 14px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
}
table.week-grid-tasks {
  width: 100%;
  font-size: 13px;
}
table.week-grid-tasks th,
table.week-grid-tasks td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
