:root {
  --ink: #172026;
  --muted: #66737c;
  --line: #d9e0e4;
  --paper: #f6f7f5;
  --surface: #ffffff;
  --teal: #167a7f;
  --gold: #c28a20;
  --red: #bc4b51;
  --green: #3d7d4f;
  --shadow: 0 18px 44px rgba(23, 32, 38, 0.09);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); font-family: Arial, Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; }
textarea { min-height: 88px; resize: vertical; }
.hidden, .role-hidden { display: none !important; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3 { margin: 0; line-height: 1.08; }
h1 { max-width: 15rem; font-size: 1.08rem; }
h2 { font-size: clamp(1.8rem, 4vw, 2.85rem); }
h3 { font-size: 1.05rem; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef1ef; }
.login-card { width: min(430px, 100%); display: grid; gap: 18px; padding: 26px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 104px; height: auto; display: block; flex: 0 0 auto; }
.login-card .brand { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.login-card label, .data-form label { display: grid; gap: 6px; color: var(--muted); font-size: .78rem; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: .85rem; }

.app-shell { display: grid; grid-template-columns: 292px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 28px; padding: 24px; border-right: 1px solid var(--line); background: #eef1ef; }
.nav-list { display: grid; gap: 8px; }
.nav-item { min-height: 42px; display: flex; align-items: center; padding: 0 14px; border-radius: 8px; color: #496472; text-decoration: none; font-weight: 800; }
.nav-item:hover, .nav-item.active { background: var(--surface); color: var(--ink); box-shadow: 0 8px 24px rgba(23, 32, 38, .06); }
.side-note { margin-top: auto; display: grid; gap: 4px; color: var(--muted); }
.side-note strong { color: var(--ink); }
.workspace { min-width: 0; padding: 26px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { width: min(390px, 42vw); }

.primary-button, .secondary-button, .danger-button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 8px; padding: 0 14px; font-weight: 800; cursor: pointer; }
.primary-button { background: var(--teal); color: #fff; }
.secondary-button { border-color: var(--line); background: var(--surface); color: #496472; }
.danger-button { border-color: #efc6c9; background: #f7dddf; color: var(--red); }
.small-button { min-height: 32px; padding: 0 10px; font-size: .78rem; }
.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric, .panel { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.metric { min-height: 126px; display: flex; flex-direction: column; justify-content: space-between; padding: 18px; }
.metric span, .metric small { color: var(--muted); }
.metric strong { font-size: clamp(1.35rem, 2vw, 1.85rem); }
.negative { color: var(--red); }
.positive { color: var(--green); }
.entry-grid, .dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .8fr); gap: 14px; align-items: start; margin-bottom: 14px; }
.panel { padding: 18px; min-width: 0; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.data-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.wide-field { grid-column: 1 / -1; }

.timeline, .cash-chart, .cash-gap-list, .remarks-list { display: grid; gap: 14px; }
.timeline-row, .cash-row { display: grid; grid-template-columns: minmax(150px, 220px) minmax(260px, 1fr) 86px; gap: 14px; align-items: center; }
.project-name strong, .cash-label strong, .gap-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-name span, .cash-label span, .gap-row span, .muted { color: var(--muted); font-size: .82rem; }
.track, .cash-bar-track, .gap-track, .mini-track { overflow: hidden; border-radius: 999px; background: #edf1f2; }
.track { position: relative; height: 18px; }
.bar { position: absolute; top: 0; bottom: 0; left: var(--offset); width: var(--width); min-width: 10px; border-radius: 999px; background: var(--teal); }
.bar.watch { background: var(--gold); }
.bar.at-risk { background: var(--red); }
.bar.completed { background: var(--green); }
.bar.on-hold { background: var(--muted); }
.progress-pill, .status { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; padding: 6px 10px; font-size: .78rem; font-weight: 800; background: #dceff0; color: var(--teal); }
.progress-rings { display: grid; grid-template-columns: repeat(2, minmax(120px, 1fr)); gap: 14px; }
.ring-card { display: grid; justify-items: center; gap: 10px; padding: 14px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfb; text-align: center; }
.ring { width: 104px; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; background: radial-gradient(circle at center, #fff 57%, transparent 58%), conic-gradient(var(--ring-color) calc(var(--value) * 1%), #e8edef 0); }
.cash-panel, .remarks-panel, .table-panel { grid-column: 1 / -1; }
.cash-row { grid-template-columns: minmax(150px, 220px) minmax(260px, 1fr) 130px; }
.cash-bars { display: grid; gap: 7px; }
.cash-bar-track { height: 13px; }
.cash-bar { height: 100%; border-radius: 999px; }
.cash-bar.disbursed { background: var(--gold); }
.cash-bar.collected { background: var(--teal); }
.cash-net { justify-self: end; font-weight: 800; }
.gap-row { display: grid; gap: 8px; }
.gap-track { height: 10px; }
.gap-bar { width: var(--gap); height: 100%; border-radius: 999px; background: var(--red); }
.gap-bar.positive { background: var(--green); }
.remarks-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.remark-row { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfb; }
.remark-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.remark-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.remark-grid span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.remark-grid p { margin: 0; line-height: 1.4; }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 1120px; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .76rem; letter-spacing: .06em; text-transform: uppercase; }
.mini-progress { display: grid; grid-template-columns: 54px minmax(92px, 1fr); gap: 10px; align-items: center; }
.mini-track { height: 8px; }
.mini-fill { width: var(--value); height: 100%; border-radius: 999px; background: var(--teal); }
.table-remark { display: block; max-width: 360px; color: var(--muted); font-size: .82rem; line-height: 1.35; }
.table-remark + .table-remark { margin-top: 6px; }
.table-remark strong { color: var(--ink); }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.empty, .empty-cell { color: var(--muted); text-align: center; }

.users-section { display: grid; gap: 0; }
.users-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 0; }
.retention-list { display: grid; gap: 10px; }
.retention-row { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfb; }
.retention-amount { font-weight: 700; font-size: 1.05rem; color: var(--teal); }
.retention-pct { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.retention-billings { font-size: .78rem; color: var(--muted); margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px; }
.retention-billing-tag { background: #eef6f6; color: var(--teal); border-radius: 4px; padding: 2px 6px; font-size: .72rem; }
.retention-total-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-top: 2px solid var(--line); margin-top: 4px; }
.dash-section { display: flex; flex-direction: column; gap: 14px; }
.dash-kpi-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.dash-charts-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 14px; }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
}
.print-report { display: none; }

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body > * { display: none !important; }
  .print-report { display: block !important; font-family: Arial, Helvetica, sans-serif; font-size: 11pt; color: #172026; }
  .pr-header { display: flex; align-items: center; gap: 16px; padding-bottom: 14px; border-bottom: 2px solid #167a7f; margin-bottom: 18px; }
  .pr-logo { width: 72px; height: auto; }
  .pr-brand h1 { font-size: 15pt; margin: 0 0 2px; }
  .pr-brand p { margin: 0; font-size: 9pt; color: #66737c; }
  .pr-meta { margin-left: auto; text-align: right; font-size: 9pt; color: #66737c; }
  .pr-meta strong { display: block; font-size: 11pt; color: #172026; }
  .pr-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 20px; }
  .pr-kpi { border: 1px solid #d9e0e4; border-radius: 6px; padding: 10px 12px; }
  .pr-kpi span { display: block; font-size: 8pt; color: #66737c; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
  .pr-kpi strong { font-size: 13pt; }
  .pr-kpi small { display: block; font-size: 8pt; color: #66737c; margin-top: 2px; }
  .pr-section-title { font-size: 10pt; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: #66737c; margin: 18px 0 8px; border-bottom: 1px solid #d9e0e4; padding-bottom: 4px; }
  .pr-table { width: 100%; border-collapse: collapse; font-size: 9pt; margin-bottom: 4px; }
  .pr-table th { background: #f6f7f5; text-align: left; padding: 5px 8px; font-size: 8pt; text-transform: uppercase; letter-spacing: .04em; color: #66737c; border-bottom: 1px solid #d9e0e4; }
  .pr-table td { padding: 5px 8px; border-bottom: 1px solid #eef0ef; vertical-align: top; }
  .pr-table tr:last-child td { border-bottom: none; }
  .pr-badge { display: inline-block; padding: 2px 7px; border-radius: 12px; font-size: 8pt; font-weight: 700; }
  .pr-badge.on-track { background: #d1fae5; color: #065f46; }
  .pr-badge.watch { background: #fef3c7; color: #92400e; }
  .pr-badge.at-risk { background: #fee2e2; color: #991b1b; }
  .pr-badge.completed { background: #dbeafe; color: #1e40af; }
  .pr-badge.on-hold { background: #f3f4f6; color: #374151; }
  .pr-progress-bar { display: flex; align-items: center; gap: 6px; }
  .pr-progress-track { flex: 1; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; }
  .pr-progress-fill { height: 100%; background: #167a7f; border-radius: 3px; }
  .pr-net-pos { font-weight: 700; }
  .pr-net-pos.pos { color: #065f46; }
  .pr-net-pos.neg { color: #991b1b; }
  .pr-footer { margin-top: 24px; padding-top: 8px; border-top: 1px solid #d9e0e4; font-size: 8pt; color: #66737c; display: flex; justify-content: space-between; }
  @page { margin: 16mm 14mm; size: A4 landscape; }
}

@media (max-width: 820px) {
  .workspace { padding: 16px; }
  .topbar, .entry-grid, .dashboard-grid, .kpi-grid, .data-form, .remarks-list, .remark-grid, .progress-rings { grid-template-columns: 1fr; }
  .topbar { display: grid; }
  .search { width: 100%; }
  .timeline-row, .cash-row { grid-template-columns: 1fr; }
  .dash-kpi-row { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .dash-charts-grid { grid-template-columns: 1fr; }
}
