/* style.css - Professional Responsive Design */

/* ========================================= */
/* 1. GLOBAL VARIABLES & RESET               */
/* ========================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f2f6f9;
  --card: #ffffff;
  --muted: #6c7a86;
  --accent: #2a9d8f;   /* Teal Green */
  --accent-2: #264653; /* Dark Navy */
  --danger: #e63946;   /* Red */
  --shadow: 0 10px 30px rgba(20, 30, 40, 0.08);
  --max-width: 1200px;
}

/* Global Transitions */
button, .card, #list li, input, select {
  transition: all 0.3s ease;
}

body {
  font-family: 'Poppins', "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, #eef6f9, #f7fbfc);
  color: #122023;
  min-height: 100vh;
  padding: 28px;
  -webkit-font-smoothing: antialiased;
  /* Safe Area for Mobile */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ========================================= */
/* 2. LAYOUT STRUCTURE                       */
/* ========================================= */
.page {
  display: flex;
  gap: 24px;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  align-items: flex-start;
  justify-content: center;
}

.panel {
  flex: 0 0 240px;
  background: linear-gradient(180deg, #1f2a35, #264653);
  color: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.left-panel h2 { font-size: 18px; margin-top: 0; }
.left-panel p { font-size: 14px; margin-top: 2px; }

.container {
  flex: 1 1 500px;
  max-width: 700px;
}

.container h1 {
  font-size: 26px;
  color: var(--accent-2);
  margin-bottom: 20px;
}

/* ========================================= */
/* 3. SUMMARY CARDS                          */
/* ========================================= */
.balance-container {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.card {
  flex: 1 1 180px;
  background: var(--card);
  padding: 16px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(18, 30, 40, 0.05);
  text-align: center;
  cursor: default;
}

.summary-card p {
  font-size: 14px;
  font-weight: 600;
  margin-top: 6px;
}

.summary-card {
  text-align: left;
}

.summary-card h4 {
  margin-bottom: 12px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
}

.summary-row span {
  color: var(--muted);
  font-weight: 600;
}

.summary-row strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-2);
}

.card:hover {
  box-shadow: 0 10px 30px rgba(20, 30, 40, 0.12);
  transform: translateY(-2px);
}

.card h4 {
  font-size: 16px;
  color: #333333;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.card .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-2);
}

.card .value-income { color: #2ea44f; }
.card .value-expense { color: var(--danger); }

/* ========================================= */
/* 4. UNIFIED FORM STYLES                    */
/* ========================================= */
.form-card, .filter-card {
  background: var(--card);
  padding: 20px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.form-card h3, .filter-card h3 {
  font-size: 18px;
  margin-bottom: 15px;
  color: var(--accent-2);
}

/* Shared Input Styles */
.row input, .row select, 
.filter-group input, .filter-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  color: #122023;
  min-width: 0;
  background: #fff;
  box-shadow: 0 1px 4px rgba(18, 30, 40, 0.02);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
}

/* Shared Focus State */
.row input:focus, .row select:focus,
.filter-group input:focus, .filter-group select:focus {
  border-color: var(--accent); 
  box-shadow: 0 0 0 4px rgba(42, 157, 143, 0.15); 
  outline: none;
  transform: translateY(-1px); 
}

/* Top Form Layout */
.row {
  display: flex;
  gap: 15px;
  margin-bottom: 15px;
  align-items: flex-end;
}
.row > div { flex: 1 1 0; min-width: 120px; }
.row label {
  display: block;
  font-size: 14px;
  color: var(--accent-2);
  font-weight: 600;
  margin-bottom: 5px;
  width: 100%;
}

/* Bottom Filter Layout */
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  align-items: start;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

.filter-group label {
  font-size: 14px;
  color: var(--accent-2);
  font-weight: 600;
  margin-left: 2px;
}

/* Button Containers */
.form-actions, .filter-actions {
  grid-column: 1 / -1; 
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}
.form-actions button, .filter-actions button { flex: 0 0 auto; white-space: nowrap; }

/* ========================================= */
/* 5. BUTTONS                                */
/* ========================================= */
button {
  padding: 10px 15px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  font-family: 'Poppins', sans-serif;
}
button:active { transform: scale(0.98); }
button:hover { background: var(--accent-2); }

button.secondary { background: #f4f6f7; color: var(--accent-2); }
button.secondary:hover { background: #e5e9ec; }
button.danger { background: var(--danger); }

/* ========================================= */
/* 6. TRANSACTION LIST                       */
/* ========================================= */
.history { margin-top: 20px; }
.history h3 {
  font-size: 18px;
  margin-bottom: 15px;
  color: var(--accent-2);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

#list { list-style: none; }
#list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, #fbfbfb);
  box-shadow: 0 6px 16px rgba(18, 30, 40, 0.04);
  border-left: 6px solid transparent;
  animation: slideIn 0.3s ease forwards;
}

#list li:hover {
  background: var(--bg);
  box-shadow: 0 8px 20px rgba(18, 30, 40, 0.06);
  cursor: pointer;
}

#list li.income { border-left-color: #2ea44f; }
#list li.expense { border-left-color: var(--danger); }

.tx-left { display: flex; gap: 10px; align-items: center; }
.tx-desc { font-weight: 600; color: #122023; }
.tx-meta { font-size: 13px; color: var(--muted); }

.tx-amount { font-weight: 700; }
#list .tx-amount.income { color: #2ea44f; }
#list .tx-amount.expense { color: var(--danger); }

.delete-btn, .edit-btn {
  background: none; border: none; padding: 0 4px; font-size: 14px; font-weight: 700; cursor: pointer; opacity: 0.7;
}
.delete-btn { color: var(--danger); }
.edit-btn { color: var(--accent); }
.delete-btn:hover, .edit-btn:hover { opacity: 1; transform: scale(1.1); }

/* ========================================= */
/* 7. CHARTS & EXPORT                        */
/* ========================================= */
.analytics { display: flex; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.chart-card {
  flex: 1 1 320px;
  min-height: 260px;
  background: #fff;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 8px 22px rgba(18, 30, 40, 0.04);
}

.export-row { display: flex; gap: 10px; margin-top: 12px; justify-content: flex-end; flex-wrap: wrap; }
.export-row button { background: #f4f6f7; color: var(--accent-2); border: 1px solid rgba(18, 30, 40, 0.04); padding: 10px 12px; }
.export-row button#clear-all { background: var(--danger); color: #fff; border: none; }

/* Sidebar & Utility */
.members { list-style: none; padding-left: 6px; text-align: left; }
.small-note { font-size: 13px; color: var(--muted); margin-top: 8px; }
.muted { color: var(--muted); }
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* ========================================= */
/* 8. DATE INPUT FIX (Placeholder Trick)     */
/* ========================================= */
input[type="date"]:invalid::-webkit-datetime-edit { color: transparent; }
input[type="date"]:invalid::before {
  content: attr(placeholder);
  color: #6c7a86;
  margin-right: 5px;
}
input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer; opacity: 0.6; transition: 0.3s;
}
input[type="date"]:hover::-webkit-calendar-picker-indicator { opacity: 1; }

/* ========================================= */
/* 9. DARK MODE STYLES                       */
/* ========================================= */
.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.theme-btn { background: #264653; font-size: 12px; padding: 8px 12px; }

body.dark-mode { background: #121212; color: #e0e0e0; }
body.dark-mode .card, body.dark-mode .form-card, body.dark-mode .filter-card,
body.dark-mode .chart-card, body.dark-mode .panel {
  background: #1e1e1e; color: #ffffff; box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
body.dark-mode input, body.dark-mode select { background: #2d2d2d; border-color: #444; color: #fff; }
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3, body.dark-mode h4, 
body.dark-mode .card h4, body.dark-mode label, body.dark-mode .tx-desc { color: #ffffff; }

body.dark-mode .muted, body.dark-mode .tx-meta { color: #aaaaaa; }
body.dark-mode #list li { background: #2d2d2d; border: 1px solid #333; }
body.dark-mode #list li:hover { background: #383838; }
body.dark-mode .chart-card canvas { filter: brightness(0.9); }
body.dark-mode input[type="date"]:invalid::before { color: #aaaaaa; }
body.dark-mode input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }
body.dark-mode .small-note { color: #bbb; }

/* ========================================= */
/* 10. PDF PRINT STYLES                      */
/* ========================================= */
.printing { background: white !important; padding: 20px !important; font-family: 'Poppins', sans-serif !important; }
.printing .delete-btn, .printing .edit-btn, .printing .export-container-split, .printing .small-note { display: none !important; }
.printing .tx-desc { color: #000 !important; font-weight: 800 !important; font-size: 14px !important; }
.printing .tx-meta { color: #444 !important; font-weight: 600 !important; }
.printing h4 { color: #000 !important; }
.printing .value-income, .printing .tx-amount.income { color: #2ea44f !important; font-weight: 800 !important; }
.printing .value-expense, .printing .tx-amount.expense { color: #e63946 !important; font-weight: 800 !important; }
.printing #list li { box-shadow: none; border: 1px solid #ddd; margin-bottom: 5px; break-inside: avoid; }
.printing .chart-card { box-shadow: none; border: 1px solid #ddd; height: 300px !important; page-break-inside: avoid; }
.printing {
  page-break-inside: avoid;
}

.printing .chart-card,
.printing #list li {
  break-inside: avoid;
  page-break-inside: avoid;
}
.printing .chip,
.printing .quick-chips,
.printing .filter-card,
.printing .form-card,
.printing .budget-card {
  display: none !important;
}
/* ========================================= */
/* 11. TOAST NOTIFICATIONS                   */
/* ========================================= */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 280px;
  padding: 16px 20px;
  background: #fff;
  color: #333;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  border-left: 6px solid #333;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 600;
  animation: slideInRight 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, fadeOut 0.5s ease 3s forwards;
}

.toast.success { border-left-color: #2ea44f; }
.toast.error { border-left-color: #e63946; }
.toast.info { border-left-color: #2a9d8f; }

body.dark-mode .toast { background: #2d2d2d; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }

@keyframes slideInRight {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
  to { opacity: 0; pointer-events: none; }
}

/* ========================================= */
/* 12. MOBILE & iPHONE OPTIMIZATIONS         */
/* ========================================= */
@media (max-width: 980px) {
  .page { flex-direction: column; align-items: stretch; gap: 15px; } 
  .panel { width: 100%; max-width: 100%; flex: 1 1 auto; margin-bottom: 10px; }
  .container { width: 100%; max-width: 100%; }
}

@media (max-width: 768px) {
  body { padding: 10px; }
  
  .header-row { margin-bottom: 15px; gap: 10px; }
  .header-row h1 { font-size: 22px; line-height: 1.2; }
  .theme-btn { white-space: nowrap; padding: 8px 12px; font-size: 12px; flex-shrink: 0; }
  
  .balance-container { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .card:first-child { grid-column: 1 / -1; background: #f8fcfd; }
  .card { padding: 12px; }
  .card h4 { font-size: 12px; }
  .card .value { font-size: 20px; }

  .row { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
  .row > div { width: 100%; }
  
  .form-actions, .filter-actions { flex-direction: column; }
  .form-actions button, .filter-actions button { width: 100%; padding: 12px; }
  
  .form-card, .filter-card { padding: 15px; }
  .chart-card { height: 220px; width: 100%; flex: 1 1 100%; }
  
  .tx-left { flex-direction: column; align-items: flex-start; gap: 2px; }
  .tx-meta { font-size: 11px; }
  #list li { padding: 10px; }

  /* iPhone Fix 1: Stop Zoom */
  .row input, .row select, 
  .filter-group input, .filter-group select {
    font-size: 16px !important; 
    max-width: 100%;
  }

  /* Grid Fix: Stack inputs on mobile */
  .filters {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {

  .summary-card {
    padding: 14px;
  }

  .summary-card h4 {
    font-size: 14px;
    margin-bottom: 10px;
    text-align: center;
  }

  .summary-row {
    padding: 6px 0;
  }

  .summary-row span {
    font-size: 13px;
  }

  .summary-row strong {
    font-size: 14px;
  }
}
@media (max-width: 768px) {
  .summary-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .summary-row:not(:last-child) {
    border-bottom: 1px solid rgba(0,0,0,0.05);
  }

  body.dark-mode .summary-row:not(:last-child) {
    border-bottom: 1px solid rgba(255,255,255,0.08);
  }
}

/* iPhone Fix 2: Flatten iOS Styles */
input[type="date"], input[type="text"], input[type="number"], select {
  -webkit-appearance: none;
  appearance: none;
  border-radius: 6px;
}

/* iPhone Fix 3: Date Picker */
input[type="date"] {
  min-height: 42px;
  background-color: #fff;
}

/* ========================================= */
/* 13. IMPROVEMENTS (Refactored Inline CSS)  */
/* ========================================= */

/* Replaces inline style for the Budget Card */
.budget-card {
  margin-bottom: 20px;
  text-align: left;
  padding: 15px;
}

/* Flex header for budget items */
.budget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

/* Small buttons for budget controls */
.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-remove {
  padding: 4px 8px;
  font-size: 12px;
  background: var(--danger);
}

/* The Budget Bar Container */
.budget-bar-container {
  background: #e0e0e0;
  border-radius: 20px;
  height: 18px;
  width: 100%;
  overflow: hidden;
  position: relative;
}

/* The dynamic bar itself */
#budget-bar {
  background: var(--accent);
  height: 100%;
  width: 0%;
  transition: width 0.6s ease, background-color 0.4s ease;
}

/* Bottom text row for budget */
.budget-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}

/* ========================================= */
/* 14. EMPTY STATE (No Data Design)          */
/* ========================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  
  /* Dashed border suggests "fill me in" */
  border: 2px dashed #cbd5e1; 
  border-radius: 12px;
  background-color: rgba(255, 255, 255, 0.5);
  margin-bottom: 15px;
  
  /* Animation */
  animation: fadeIn 0.5s ease-in-out;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.8;
  filter: grayscale(100%);
  transition: transform 0.3s ease;
}

.empty-state:hover .empty-icon {
  transform: scale(1.1) rotate(10deg);
  filter: grayscale(0%);
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-2);
  margin-bottom: 5px;
}

.empty-desc {
  font-size: 13px;
  color: var(--muted);
  max-width: 250px;
  line-height: 1.5;
}

/* Dark Mode Adjustment */
body.dark-mode .empty-state {
  border-color: #444;
  background-color: rgba(255, 255, 255, 0.02);
}

/* ========================================= */
/* 15. CUSTOM MODAL STYLES                   */
/* ========================================= */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-box {
  background: var(--card);
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 400px;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-align: center;
}

.modal-overlay.active .modal-box {
  transform: translateY(0);
}

.modal-box h3 { margin-bottom: 10px; color: var(--accent-2); }
.modal-box p { color: var(--muted); margin-bottom: 20px; font-size: 14px; }

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* ========================================= */
/* 16. DARK MODE FIX FOR MODAL               */
/* ========================================= */
body.dark-mode .modal-box {
  background: #1e1e1e;
  border: 1px solid #333;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

body.dark-mode .modal-box h3 { color: #ffffff !important; }
body.dark-mode .modal-box p { color: #b0b0b0; }

body.dark-mode .modal-actions .secondary {
  background: #2d2d2d;
  color: #fff;
  border: 1px solid #444;
}

body.dark-mode .modal-actions .secondary:hover {
  background: #383838;
}

/* ========================================= */
/* 17. DATE FILTER BUTTONS FIX               */
/* ========================================= */
.filter-date-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.filter-date-row button { flex: 1; }

@media (max-width: 768px) {
  .filter-date-row { flex-direction: column; }
}

/* ========================================= */
/* 18. SPLIT BUTTON LAYOUT                   */
/* ========================================= */
.export-container-split {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
  margin-top: 25px;
  padding-top: 20px;
  border-top: 1px solid rgba(0,0,0,0.05);
}

.left-actions, .right-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

body.dark-mode .export-container-split {
  border-top: 1px solid rgba(255,255,255,0.1);
}

@media (max-width: 600px) {
  .export-container-split {
    flex-direction: column;
    align-items: stretch;
  }
  
  .left-actions, .right-actions {
    flex-direction: column;
    width: 100%;
  }
  
  .export-container-split button {
    width: 100%;
  }
}

/* Quick Add Chips */
.quick-chips {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.chip-label { font-size: 12px; color: var(--muted); font-weight: 600; }

.chip {
  background: #eef2f5;
  color: var(--accent-2);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.chip:hover {
  background: var(--accent);
  color: white;
  transform: translateY(-2px);
}

.pdf-hidden {
  display: none;
}

body.dark-mode .chip { background: #333; color: #fff; }
body.dark-mode .chip:hover { background: var(--accent); }
