/* MindKraft Farm Venture - Finance Manager */
:root {
  --primary: #1E446A;
  --primary-light: #2B649B;
  --primary-dark: #0E2130;
  --accent: #D4A96A;
  --accent-dark: #956E46;
  --bg: #F5F4F1;
  --sidebar-bg: #0E2130;
  --white: #ffffff;
  --gray-100: #f1f3f5;
  --gray-200: #e9ecef;
  --gray-400: #ced4da;
  --gray-600: #6c757d;
  --gray-800: #343a40;
  --success: #1E446A;
  --danger: #c0392b;
  --warning: #956E46;
  --info: #2B649B;
  --text: #102539;
  --card-shadow: 0 2px 16px rgba(30,68,106,0.10);
  --radius: 8px;
  --radius-sm: 4px;
  --sidebar-width: 248px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

/* SIDEBAR */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: white;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.3;
}
.sidebar-logo p { font-size: 11px; opacity: 0.7; margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.5;
  padding: 12px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: all 0.2s;
  font-size: 13px;
  opacity: 0.8;
  border-left: 3px solid transparent;
}
.nav-item:hover:not(.active) { background: rgba(255,255,255,0.07); opacity: 1; }
.nav-item.active {
  background: rgba(212, 169, 106, 0.15);
  color: #D4A96A;
  border-left: 3px solid #D4A96A;
  opacity: 1;
}
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.75;
}
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
  opacity: 1;
}

/* ── LOGIN ───────────────────────────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-box {
  background: white;
  border-radius: 16px;
  padding: 44px 40px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
  text-align: center;
}
.login-logo { margin-bottom: 4px; display: flex; justify-content: center; }
.login-subtitle {
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin-bottom: 32px;
  opacity: 0.75;
}
.login-box .form-group { text-align: left; margin-bottom: 16px; }
.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 18px;
  text-align: left;
}
.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  cursor: pointer;
  padding: 7px 12px;
  margin-top: 10px;
  font-family: 'DM Sans', sans-serif;
  transition: color 0.2s, border-color 0.2s;
  width: 100%;
  justify-content: center;
}
.logout-btn:hover { color: rgba(255,255,255,0.85); border-color: rgba(255,255,255,0.3); }
.logout-btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 11px;
  opacity: 0.5;
}

/* MAIN CONTENT */
#main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#topbar {
  background: white;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

#topbar h1 { font-size: 18px; font-weight: 600; color: var(--primary-dark); }
#topbar .topbar-right { display: flex; align-items: center; gap: 12px; }

.date-badge {
  background: var(--gray-100);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--gray-600);
}

#mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--primary-dark);
}

/* PAGE CONTENT */
.page { display: none; padding: 24px; animation: fadeIn 0.3s; }
.page.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

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

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-left: 4px solid var(--primary-light);
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card.income { border-left-color: #1E446A; }
.stat-card.expense { border-left-color: #c0392b; }
.stat-card.profit { border-left-color: #956E46; }
.stat-card.balance { border-left-color: #0E2130; }

.stat-label { font-size: 12px; color: var(--gray-600); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--primary-dark); }
.stat-value.positive { color: #1E446A; }
.stat-value.negative { color: #c0392b; }
.stat-sub { font-size: 11px; color: var(--gray-600); }

/* GRID LAYOUTS */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* CARDS */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--primary-dark); }
.card-body { padding: 20px; }

/* TABLES */
.table-responsive { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--gray-100);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-800);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 2px solid var(--gray-200);
}
tbody tr { border-bottom: 1px solid var(--gray-200); transition: background 0.15s; }
tbody tr:hover { background: var(--gray-100); }
tbody td { padding: 10px 12px; color: var(--gray-800); }
tbody tr:last-child { border-bottom: none; }

.amount-positive { color: var(--success); font-weight: 600; }
.amount-negative { color: var(--danger); font-weight: 600; }

/* BADGES */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: #d8f3dc; color: #2d6a4f; }
.badge-red { background: #fde8e8; color: #c0392b; }
.badge-orange { background: #fef3e2; color: #d97706; }
.badge-blue { background: #e0f0ff; color: #1e6bb8; }

/* FORMS */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 12px; font-weight: 600; color: var(--gray-800); }
input, select, textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--gray-400);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: border-color 0.2s;
  font-family: inherit;
  background: white;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(64,145,108,0.1);
}
textarea { resize: vertical; min-height: 70px; }

/* BUTTONS */
.btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost {
  background: var(--gray-100);
  color: var(--gray-800);
  border: 1px solid var(--gray-200);
}

/* SECTION HEADERS */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-title { font-size: 20px; font-weight: 700; color: var(--primary-dark); }
.section-sub { font-size: 13px; color: var(--gray-600); margin-top: 2px; }

/* CYCLE TRACKER */
.cycle-bar-wrapper {
  background: var(--gray-200);
  border-radius: 20px;
  height: 12px;
  overflow: hidden;
  margin: 10px 0;
}
.cycle-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-light), var(--accent));
  border-radius: 20px;
  transition: width 0.5s;
}

/* MODAL */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white;
  border-radius: var(--radius);
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: slideUp 0.3s;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--gray-600);
  line-height: 1;
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ALERTS */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success { background: #d8f3dc; color: #1b4332; }
.alert-danger { background: #fde8e8; color: #7d1128; }
.alert-info { background: #e0f0ff; color: #1e4d7b; }

/* CHART CONTAINERS */
.chart-container {
  position: relative;
  height: 250px;
  width: 100%;
}

/* FILTER BAR */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar input, .filter-bar select {
  padding: 7px 12px;
  font-size: 13px;
}

/* PROGRESS */
.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
}
.progress-bar-wrap { background: var(--gray-200); border-radius: 4px; height: 8px; flex: 1; margin: 0 10px; }
.progress-bar { height: 100%; border-radius: 4px; background: var(--primary-light); }

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-600);
}
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; }

/* REPORT PRINT */
@media print {
  #sidebar, #topbar, .no-print { display: none !important; }
  #main { margin: 0; }
  .page { display: block !important; padding: 0; }
  body { background: white; }
}

/* RESPONSIVE */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: none; }
  #main { margin-left: 0; }
  #mobile-menu-btn { display: block; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .page { padding: 16px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* UTILITY */
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--gray-600); }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
hr { border: none; border-top: 1px solid var(--gray-200); margin: 16px 0; }

/* TOAST */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--primary-dark);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: slideUp 0.3s;
  max-width: 300px;
}
.toast.error { background: var(--danger); }

/* ── RECEIPT UPLOAD ────────────────────────────────────────────── */
.receipt-drop-zone {
  border: 2px dashed var(--gray-400);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--gray-100);
  position: relative;
}
.receipt-drop-zone:hover { border-color: var(--primary); background: #f0f7f4; }
.receipt-drop-zone input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.receipt-drop-label { font-size: 13px; color: var(--gray-600); pointer-events: none; }
.receipt-drop-label span { display: block; font-size: 22px; margin-bottom: 4px; }

.receipt-preview-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  margin-top: 8px;
}
.receipt-preview-wrap img {
  width: 52px; height: 52px; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.receipt-preview-meta { flex: 1; min-width: 0; }
.receipt-preview-meta .receipt-filename {
  font-size: 12px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}
.receipt-preview-meta .receipt-filesize { font-size: 11px; color: var(--gray-600); }

/* Receipt viewer modal */
.receipt-viewer-img { max-width: 100%; max-height: 70vh; border-radius: var(--radius-sm); display: block; margin: 0 auto; }
.receipt-pdf-box { text-align: center; padding: 30px; }
.receipt-pdf-box .pdf-icon { font-size: 56px; }

/* 📎 badge in table */
.btn-receipt {
  background: #e0f0ff; color: #1e6bb8;
  border: none; border-radius: 6px;
  padding: 4px 8px; font-size: 12px; cursor: pointer;
  transition: background 0.15s;
}
.btn-receipt:hover { background: #c0ddff; }
