:root {
  --navy: #1E3A5F;
  --navy-dark: #142a45;
  --red: #D7263D;
  --red-light: #FBE4E7;
  --blue-light: #E5EEF7;
  --green: #1E8E3E;
  --green-light: #E4F5E8;
  --bg: #FFFFFF;
  --surface: #F7F8FA;
  --border: #E4E7EC;
  --text: #1F2937;
  --text-muted: #6B7280;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Kanit', 'Prompt', sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--navy);
  color: #fff;
  padding: 24px 12px;
  display: flex;
  flex-direction: column;
}

.brand {
  font-size: 20px;
  font-weight: 600;
  padding: 0 12px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin-bottom: 16px;
}

.brand span { color: var(--red); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-family: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s ease;
}

.nav-item:hover { background: rgba(255,255,255,0.08); }

.nav-item.active {
  background: var(--red);
  color: #fff;
  font-weight: 600;
}

.nav-icon { font-size: 18px; }

/* ---------- Main ---------- */

.main {
  padding: 24px 32px 48px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

#page-title { font-size: 24px; font-weight: 600; margin: 0; }

.period-picker {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
}

.period-picker select {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: var(--navy);
  font-weight: 600;
}

.panel { display: none; }
.panel.active { display: block; }

/* ---------- Cards / KPI ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  border-top: 3px solid var(--navy);
}

.kpi-card.accent-red { border-top-color: var(--red); }

.kpi-label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--navy); }
.kpi-value.negative { color: var(--red); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; }
  .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card h3 { margin-top: 0; font-size: 16px; color: var(--navy); }

/* ---------- Bars ---------- */

.bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 90px;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
}

.bar-track {
  background: var(--blue-light);
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
}

.bar-fill { background: var(--navy); height: 100%; }
.expense-breakdown .bar-fill { background: var(--red); }
.bar-value { text-align: right; font-weight: 600; }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 13px; }

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

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.tag-blue { background: var(--blue-light); color: var(--navy); }
.tag-red { background: var(--red-light); color: var(--red); }
.tag-green { background: var(--green-light); color: var(--green); }

.btn-link {
  background: none;
  border: none;
  color: var(--navy);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}

.btn-link:hover { color: var(--red); }

/* ---------- Forms ---------- */

form.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  align-items: end;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text-muted); }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--navy);
  outline-offset: 1px;
}

textarea { resize: vertical; min-height: 60px; }

.btn-primary {
  background: var(--navy);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  height: fit-content;
}

.btn-primary:hover { background: var(--navy-dark); }

.btn-primary.red { background: var(--red); }
.btn-primary.red:hover { background: #b31d31; }

/* ---------- Issues ---------- */

.issue-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.issue-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.issue-actions { margin-top: 10px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--navy);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.25s ease;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }
