:root {
  --blue-700: #1d4ed8;
  --blue-600: #2563eb;
  --blue-500: #3b82f6;
  --blue-100: #dbeafe;
  --green-600: #16a34a;
  --green-100: #dcfce7;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --amber-600: #d97706;
  --amber-100: #fef3c7;
  --gray-50: #f7f8fa;
  --gray-100: #f1f3f6;
  --gray-200: #e5e7eb;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Sarabun", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
}

a { text-decoration: none; color: inherit; }

/* ---------- Auth / Login ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--blue-700), var(--blue-500));
  padding: 24px;
}
.auth-card {
  background: #fff;
  width: 100%;
  max-width: 380px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 20px 45px rgba(0,0,0,.25);
}
.auth-header {
  background: linear-gradient(160deg, var(--blue-700), var(--blue-500));
  color: #fff;
  padding: 32px 24px 24px;
  text-align: center;
}
.auth-header .icon { font-size: 40px; margin-bottom: 8px; }
.auth-header h1 { font-size: 19px; margin: 0 0 4px; }
.auth-header p { margin: 0; font-size: 13px; opacity: .85; }
.auth-body { padding: 24px; }
.auth-body .field { margin-bottom: 14px; }
.auth-body label { display: block; font-size: 13px; color: var(--gray-700); margin-bottom: 6px; }
.auth-body input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--gray-200);
  border-radius: 10px; font-size: 14px; background: var(--gray-50);
}
.auth-body input:focus { outline: 2px solid var(--blue-500); background: #fff; }
.btn-block { width: 100%; }
.auth-footer { text-align: center; margin-top: 14px; font-size: 12px; }
.auth-footer a { color: var(--blue-600); }
.auth-error {
  background: var(--red-100); color: var(--red-600); border-radius: 10px;
  padding: 10px 12px; font-size: 13px; margin-bottom: 14px;
}

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: #fff; border-right: 1px solid var(--gray-200);
  padding: 18px 12px; flex-shrink: 0;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px;
  border-bottom: 1px solid var(--gray-200); margin-bottom: 14px;
}
.sidebar .brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(160deg, var(--blue-700), var(--blue-500));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.sidebar .brand span { font-size: 14px; font-weight: 700; line-height: 1.3; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; font-size: 14px; color: var(--gray-700); margin-bottom: 2px;
}
.nav-item:hover { background: var(--gray-100); }
.nav-item.active { background: var(--blue-100); color: var(--blue-700); font-weight: 600; }
.nav-section { font-size: 11px; text-transform: uppercase; color: var(--gray-500); margin: 14px 10px 6px; }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-bottom: 1px solid var(--gray-200);
  padding: 14px 24px; position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--blue-100);
  color: var(--blue-700); display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.content { padding: 22px 24px 40px; }

/* ---------- Cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { border-radius: var(--radius); padding: 18px 20px; color: #fff; box-shadow: var(--shadow); }
.stat-card .label { font-size: 13px; opacity: .9; margin-bottom: 6px; }
.stat-card .value { font-size: 22px; font-weight: 700; }
.stat-blue { background: linear-gradient(135deg, var(--blue-600), var(--blue-700)); }
.stat-red  { background: linear-gradient(135deg, #ef4444, var(--red-600)); }
.stat-green{ background: linear-gradient(135deg, #22c55e, var(--green-600)); }

.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { margin: 0; font-size: 16px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; color: var(--gray-500); font-weight: 600; font-size: 12.5px;
  text-transform: uppercase; padding: 10px 12px; border-bottom: 1px solid var(--gray-200);
}
tbody td { padding: 12px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:hover { background: var(--gray-50); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: var(--green-100); color: var(--green-600); }
.badge-danger  { background: var(--red-100); color: var(--red-600); }
.badge-pending { background: var(--amber-100); color: var(--amber-600); }
.badge-info    { background: var(--blue-100); color: var(--blue-700); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px;
  border-radius: 10px; font-size: 13.5px; font-weight: 600; border: none; cursor: pointer;
}
.btn-primary { background: var(--blue-600); color: #fff; }
.btn-primary:hover { background: var(--blue-700); }
.btn-success { background: var(--green-600); color: #fff; }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-amber { background: #f59e0b; color: #fff; }
.btn-outline { background: #fff; color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.approval-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 220px; }
.approval-actions form { display: flex; margin: 0; }
.approval-actions .btn { white-space: nowrap; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 16px; }
.field label { display: block; font-size: 13px; color: var(--gray-700); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--gray-200);
  border-radius: 10px; font-size: 14px; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--blue-500); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Misc ---------- */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; }
.flash-success { background: var(--green-100); color: #15803d; }
.flash-danger { background: var(--red-100); color: #b91c1c; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-500); }
.progress { height: 8px; background: var(--gray-100); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--blue-600); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select, .filters input { padding: 8px 12px; border: 1px solid var(--gray-200); border-radius: 8px; font-size: 13.5px; }

/* ---------- Data-entry modal ---------- */
.data-modal {
  display: none; position: fixed; inset: 0; z-index: 20; align-items: center; justify-content: center;
  overflow-y: auto; padding: 24px; background: rgba(17, 24, 39, .48);
}
.data-modal.is-open { display: flex; }
.data-modal-panel { width: min(100%, 540px); max-height: calc(100vh - 48px); overflow-y: auto; background: #fff; border-radius: 8px; box-shadow: 0 18px 48px rgba(17, 24, 39, .22); }
.data-modal .modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: var(--blue-700); color: #fff; }
.data-modal .modal-title { margin: 0; font-size: 17px; }
.data-modal-close { border: 1px solid rgba(255,255,255,.5); border-radius: 5px; padding: 4px 9px; background: transparent; color: #fff; cursor: pointer; }
.data-modal .modal-body { padding: 20px; }
.data-modal .modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--gray-200); }
.data-modal .form-label { display: block; margin-bottom: 6px; color: var(--gray-700); font-size: 13px; font-weight: 600; }
.data-modal .form-control { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--gray-200); border-radius: 6px; font: inherit; }
.data-modal .form-control:focus { outline: 2px solid var(--blue-500); }
@media (max-width: 600px) {
  .data-modal { padding: 12px; }
  .data-modal-panel { max-height: calc(100vh - 24px); }
}

/* ---------- Budget allocation workspace ---------- */
.allocation-page { max-width: 1280px; margin: 0 auto; }
.allocation-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 24px 28px; margin-bottom: 18px; border-radius: 10px;
  color: #fff; background: linear-gradient(115deg, var(--blue-700), var(--blue-500));
}
.allocation-heading h1 { margin: 2px 0 6px; font-size: 25px; line-height: 1.25; }
.allocation-heading p { margin: 0; color: rgba(255,255,255,.78); font-size: 14px; }
.allocation-heading .allocation-eyebrow { color: var(--blue-100); }
.allocation-eyebrow { margin: 0 0 6px; color: var(--blue-700); font-size: 11px; font-weight: 700; }
.allocation-heading-mark {
  display: grid; place-items: center; width: 58px; height: 58px; flex: 0 0 58px;
  border: 1px solid rgba(255,255,255,.28); border-radius: 8px;
  color: var(--blue-100); font-size: 30px; font-weight: 700;
}
.allocation-workspace { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr); gap: 18px; margin-bottom: 22px; }
.allocation-form-panel, .allocation-budget-panel, .allocation-history {
  background: #fff; border: 1px solid var(--gray-200); border-radius: 8px; box-shadow: var(--shadow);
}
.allocation-form-panel { padding: 22px; }
.allocation-panel-heading { display: flex; align-items: center; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid var(--gray-100); }
.allocation-step { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 7px; background: var(--blue-100); color: var(--blue-700); font-size: 12px; font-weight: 700; }
.allocation-panel-heading h2, .allocation-history-heading h2 { margin: 0; font-size: 17px; }
.allocation-panel-heading p { margin: 3px 0 0; color: var(--gray-500); font-size: 12px; }
.allocation-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding-top: 18px; }
.allocation-form .field { min-width: 0; }
.allocation-form .field label { font-size: 12px; }
.allocation-form .field input, .allocation-form .field select { min-height: 43px; border-radius: 7px; }
.allocation-amount-input { position: relative; }
.allocation-amount-input input { padding-right: 54px; }
.allocation-amount-input span { position: absolute; top: 50%; right: 12px; transform: translateY(-50%); color: var(--gray-500); font-size: 12px; }
.allocation-submit { grid-column: 1 / -1; justify-content: center; min-height: 44px; border-radius: 7px; background: var(--blue-600); }
.allocation-submit:hover { background: var(--blue-700); }
.allocation-budget-panel { padding: 22px; color: #fff; background: #172b4d; border-color: #172b4d; }
.allocation-budget-panel .allocation-eyebrow { color: var(--blue-100); }
.allocation-budget-panel h2 { margin: 0 0 24px; font-size: 19px; }
.allocation-budget-total { padding-bottom: 18px; border-bottom: 1px solid rgba(255,255,255,.16); }
.allocation-budget-total span, .allocation-budget-breakdown span { display: block; color: rgba(255,255,255,.68); font-size: 12px; }
.allocation-budget-total strong { display: block; margin-top: 6px; font-size: 27px; font-variant-numeric: tabular-nums; }
.allocation-budget-breakdown { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px 0 10px; }
.allocation-budget-breakdown strong { display: block; margin-top: 6px; font-size: 15px; font-variant-numeric: tabular-nums; }
.allocation-budget-breakdown div:last-child strong { color: #bfdbfe; }
.allocation-progress { height: 7px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.16); }
.allocation-progress div { height: 100%; border-radius: inherit; background: #60a5fa; transition: width .2s ease; }
.allocation-budget-note { margin: 14px 0 0; color: rgba(255,255,255,.66); font-size: 11px; }
.allocation-empty { margin-top: 18px; padding: 14px; border-radius: 7px; background: var(--amber-100); color: #8a5200; font-size: 13px; }
.allocation-history { overflow: hidden; }
.allocation-history-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 20px 22px 14px; }
.allocation-history-heading .allocation-eyebrow { margin-bottom: 4px; }
.allocation-count { padding: 5px 9px; border-radius: 5px; background: var(--blue-100); color: var(--blue-700); font-size: 11px; font-weight: 700; }
.allocation-table-wrap { overflow-x: auto; }
.allocation-table { min-width: 760px; }
.allocation-table thead th { background: var(--gray-50); text-transform: none; white-space: nowrap; }
.allocation-table tbody td { font-size: 13px; }
.allocation-year { display: inline-block; padding: 4px 7px; border-radius: 4px; background: var(--blue-100); color: var(--blue-700); font-size: 12px; font-weight: 700; }
.allocation-no-rows { padding: 28px; text-align: center; color: var(--gray-500); }

@media (max-width: 900px) {
  .allocation-workspace { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .allocation-heading { padding: 20px; }
  .allocation-heading h1 { font-size: 21px; }
  .allocation-heading-mark { width: 44px; height: 44px; flex-basis: 44px; font-size: 23px; }
  .allocation-form { grid-template-columns: 1fr; }
  .allocation-submit { grid-column: auto; }
  .allocation-form-panel, .allocation-budget-panel { padding: 18px; }
  .allocation-history-heading { padding: 18px; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
}

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
}