/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy: #1a2744;
  --navy-dark: #111b33;
  --navy-light: #243359;
  --orange: #e8700a;
  --orange-light: #f5a842;
  --red: #d32f2f;
  --green: #2e7d32;
  --gray-bg: #f4f6fa;
  --gray-border: #dde3ee;
  --gray-text: #6b7a99;
  --white: #ffffff;
  --text: #1e2a45;
  --shadow: 0 2px 12px rgba(26,39,68,0.10);
  --shadow-lg: 0 4px 24px rgba(26,39,68,0.16);
  --radius: 10px;
  --radius-sm: 6px;
}

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

/* ===== TYPOGRAPHY ===== */
h1, h2, h3 { font-weight: 700; line-height: 1.2; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.1rem; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--navy-light); }
.btn-orange { background: var(--orange); color: var(--white); }
.btn-orange:hover { background: #c9600a; }
.btn-ghost { background: transparent; color: var(--navy); border: 1.5px solid var(--navy); }
.btn-ghost:hover { background: var(--navy); color: var(--white); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { background: #b71c1c; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 14px 32px; font-size: 15px; }

/* ===== INPUTS ===== */
.input {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid var(--gray-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.18s;
  outline: none;
}
.input:focus { border-color: var(--navy); }
.input-group { display: flex; gap: 8px; align-items: center; }

/* ===== NAVBAR ===== */
.navbar {
  background: var(--navy);
  color: var(--white);
  padding: 0 32px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.navbar-brand .logo-box {
  width: 36px;
  height: 36px;
  background: var(--orange);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
}
.navbar-right { display: flex; align-items: center; gap: 12px; }
.navbar-user {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
}
.navbar-user span { color: var(--white); font-weight: 600; }

/* ===== CARD ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ===== PAGE WRAPPER ===== */
.page-wrapper { padding: 28px 32px; max-width: 1400px; margin: 0 auto; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { color: var(--navy); }
.page-title-sub { font-size: 13px; color: var(--gray-text); margin-top: 2px; }

/* ===== ALERT ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: #fde8e8; color: var(--red); border: 1px solid #f5c6c6; }
.alert-success { background: #e8f5e9; color: var(--green); border: 1px solid #c8e6c9; }
.alert-warning { background: #fff3e0; color: #e65100; border: 1px solid #ffcc80; }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 60%, var(--navy-light) 100%);
}
.login-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.3);
  padding: 48px 44px;
  width: 420px;
  max-width: 95vw;
}
.login-header { text-align: center; margin-bottom: 36px; }
.login-logo {
  width: 72px;
  height: 72px;
  background: var(--navy);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 4px 16px rgba(26,39,68,0.25);
}
.login-logo svg { width: 38px; height: 38px; fill: var(--white); }
.login-header h1 { font-size: 1.6rem; color: var(--navy); margin-bottom: 4px; }
.login-header p { color: var(--gray-text); font-size: 13.5px; }
.login-form .field { margin-bottom: 18px; }
.login-form label { display: block; font-size: 13px; font-weight: 600; color: var(--navy); margin-bottom: 6px; }
.login-form .input { padding: 11px 14px; font-size: 14.5px; }
.login-form .btn-primary { width: 100%; padding: 13px; font-size: 15px; margin-top: 8px; }
.login-footer { text-align: center; margin-top: 20px; font-size: 12px; color: var(--gray-text); }

/* ===== WORKSPACE PAGE ===== */
.workspace-page {
  min-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.workspace-title { text-align: center; margin-bottom: 40px; }
.workspace-title h2 { color: var(--navy); font-size: 1.8rem; }
.workspace-title p { color: var(--gray-text); margin-top: 6px; }
.entity-buttons {
  display: flex;
  gap: 28px;
  margin-bottom: 32px;
  flex-wrap: wrap;
  justify-content: center;
}
.entity-btn {
  background: var(--white);
  border: 2.5px solid var(--gray-border);
  border-radius: 16px;
  padding: 36px 52px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  min-width: 220px;
  box-shadow: var(--shadow);
}
.entity-btn:hover {
  border-color: var(--navy);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}
.entity-btn .entity-code {
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
}
.entity-btn .entity-name {
  font-size: 13px;
  color: var(--gray-text);
  margin-top: 8px;
  font-weight: 500;
}
.workspace-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ===== CONTRACTS PAGE ===== */
.contracts-table {
  width: 100%;
  border-collapse: collapse;
}
.contracts-table th {
  background: var(--navy);
  color: var(--white);
  padding: 12px 16px;
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.contracts-table th:first-child { border-radius: 8px 0 0 0; }
.contracts-table th:last-child { border-radius: 0 8px 0 0; }
.contracts-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--gray-border);
  vertical-align: middle;
}
.contracts-table tr:hover td { background: #f8f9fd; }
.contracts-table tr:last-child td { border-bottom: none; }
.school-name { font-weight: 600; color: var(--navy); }
.action-buttons { display: flex; gap: 8px; }
.entity-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.badge-bgt { background: #e3eeff; color: var(--navy); }
.badge-hit { background: #fff3e0; color: var(--orange); }
.add-contract-bar {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: center;
}
.add-contract-bar .input { max-width: 340px; }

/* ===== ENTRY PAGE ===== */
.entry-header-banner {
  background: var(--navy);
  color: var(--white);
  border-radius: var(--radius);
  padding: 18px 24px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.entry-school-name { font-size: 1.2rem; font-weight: 700; }
.entry-mode-badge {
  padding: 5px 16px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.mode-budget { background: var(--orange); color: var(--white); }
.mode-actual-exp { background: #7c3aed; color: var(--white); }
.mode-actual-rev { background: var(--green); color: var(--white); }
.entry-total-amount { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px; }
.entry-total-label { font-size: 12px; color: rgba(255,255,255,0.65); }

/* Budget annual input */
.budget-annual-bar {
  background: #fff8f0;
  border: 2px solid var(--orange);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.budget-annual-bar label { font-weight: 600; color: var(--orange); font-size: 14px; white-space: nowrap; }
.budget-annual-bar .input {
  max-width: 200px;
  border-color: var(--orange);
  font-size: 15px;
  font-weight: 600;
}
.budget-annual-bar .input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(232,112,10,0.15); }
.budget-annual-hint { font-size: 12px; color: var(--orange); }

/* Entry table */
.entry-table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.entry-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  min-width: 1100px;
}
.entry-table th {
  background: var(--navy);
  color: var(--white);
  padding: 10px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.entry-table th.col-category { text-align: left; padding-left: 16px; min-width: 160px; }
.entry-table td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--gray-border);
  text-align: center;
  vertical-align: middle;
}
.entry-table td.cell-category {
  text-align: left;
  padding-left: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.entry-table .section-header td {
  background: #f0f3fa;
  color: var(--navy);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 16px;
  border-bottom: 2px solid var(--gray-border);
}
.entry-table .row-total td {
  background: var(--navy);
  color: var(--white);
  font-weight: 700;
  font-size: 13px;
  padding: 9px 6px;
  border-bottom: none;
}
.entry-table .row-total td.cell-category { padding-left: 16px; }

.amount-input {
  width: 82px;
  padding: 5px 6px;
  border: 1.5px solid var(--gray-border);
  border-radius: 4px;
  font-size: 12.5px;
  text-align: right;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s;
  outline: none;
}
.amount-input:focus { border-color: var(--navy); background: #f5f8ff; }
.amount-input:disabled { background: #f4f6fa; color: var(--gray-text); cursor: not-allowed; }

.cell-value { font-size: 13px; font-weight: 500; }
.lock-banner {
  background: #fff3e0;
  border: 1.5px solid #ffb74d;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #e65100;
  font-weight: 500;
  display: none;
}
.lock-banner.show { display: block; }

.entry-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

/* Year selector */
.year-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}
.year-selector select {
  padding: 7px 12px;
  border: 1.5px solid var(--gray-border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text);
  background: var(--white);
  cursor: pointer;
  outline: none;
}

/* ===== DASHBOARD PAGE ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.kpi-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--navy);
}
.kpi-card.kpi-orange { border-top-color: var(--orange); }
.kpi-card.kpi-purple { border-top-color: #7c3aed; }
.kpi-card.kpi-green { border-top-color: var(--green); }
.kpi-card.kpi-delta { border-top-color: var(--navy); }
.kpi-card.kpi-red { border-top-color: var(--red); }
.kpi-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--gray-text); margin-bottom: 8px; }
.kpi-value { font-size: 1.55rem; font-weight: 800; color: var(--navy); letter-spacing: -0.5px; }
.kpi-value.negative { color: var(--red); }
.kpi-value.positive { color: var(--green); }

.dash-table {
  width: 100%;
  border-collapse: collapse;
}
.dash-table th {
  background: var(--navy);
  color: var(--white);
  padding: 11px 16px;
  text-align: right;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
.dash-table th:first-child { text-align: left; border-radius: 8px 0 0 0; }
.dash-table th:nth-child(2) { text-align: left; }
.dash-table th:last-child { border-radius: 0 8px 0 0; }
.dash-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--gray-border);
  text-align: right;
  vertical-align: middle;
  font-size: 13.5px;
}
.dash-table td:first-child { text-align: left; }
.dash-table td:nth-child(2) { text-align: left; }
.dash-table tr:hover td { background: #f8f9fd; }
.dash-table .row-grand-total td {
  background: #f0f3fa;
  font-weight: 800;
  font-size: 14px;
  color: var(--navy);
  border-top: 2px solid var(--navy);
  border-bottom: none;
}
.dash-table .row-grand-total td:first-child { border-radius: 0 0 0 8px; }
.dash-table .row-grand-total td:last-child { border-radius: 0 0 8px 0; }
.delta-neg { color: var(--red); font-weight: 700; }
.delta-pos { color: var(--green); font-weight: 700; }

.dash-filters {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* ===== LOADING ===== */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.loading-overlay.show { display: flex; }
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== DASHBOARD — NEGATIVE DELTA KPI CARD ===== */
.kpi-card.kpi-delta-negative {
  background: var(--red);
  border-top-color: #b71c1c;
}
.kpi-card.kpi-delta-negative .kpi-label { color: rgba(255,255,255,0.85); }
.kpi-card.kpi-delta-negative .kpi-value { color: var(--white); }

/* ===== DASHBOARD — TABLE ROW NEGATIVE DELTA ===== */
.dash-table tr.row-negative td {
  background: #fde8e8;
}
.dash-table tr.row-negative:hover td {
  background: #fad4d4;
}
.dash-table tr.row-negative .delta-neg {
  font-weight: 800;
}

/* ===== DASHBOARD — SEARCH BAR ===== */
.search-bar-wrapper {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.search-input-group {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  border: 1.5px solid var(--gray-border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  box-shadow: var(--shadow);
  max-width: 480px;
  transition: border-color 0.18s;
}
.search-input-group:focus-within {
  border-color: var(--navy);
}
.search-icon { flex-shrink: 0; color: var(--gray-text); }
.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  min-width: 0;
}
.search-input::placeholder { color: var(--gray-text); }
.search-info {
  font-size: 12.5px;
  font-weight: 500;
  padding-left: 4px;
  min-height: 18px;
}

/* ===== DASHBOARD — MONTHLY CHART ===== */
.chart-wrapper {
  position: relative;
  height: 360px;
  width: 100%;
}

/* ===== ENTITY SELECT BUTTON HINT ===== */
.entity-btn-hint {
  font-size: 12px;
  color: var(--navy);
  margin-top: 10px;
  font-weight: 600;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.entity-btn:hover .entity-btn-hint { opacity: 1; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .page-wrapper { padding: 16px; }
  .navbar { padding: 0 16px; }
  .chart-wrapper { height: 280px; }
}
@media (max-width: 500px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .entity-btn { min-width: 160px; padding: 24px 32px; }
  .entity-btn .entity-code { font-size: 2rem; }
  .search-input-group { max-width: 100%; }
}
