/* ==========
   RESET DASAR
   ========== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  background: #f3f4f6;
  color: #111827;
  -webkit-font-smoothing: antialiased;
}

/* ==========
   LAYOUT UMUM
   ========== */

.app-header {
  background: linear-gradient(135deg, #0ea5e9, #22c55e);
  color: #f9fafb;
  padding: 1.5rem 1.25rem;
  text-align: center;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.25);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  font-size: 1.4rem;
  margin: 0 0 0.25rem;
}

.app-header .subtitle {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
}

.app-main {
  max-width: 1100px;
  margin: 1.25rem auto 2rem;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Kartu umum */
.card {
  background: #ffffff;
  border-radius: 1rem;
  padding: 1.25rem 1.25rem 1.5rem;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

/* FOOTER */
.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: #6b7280;
  padding: 1rem;
}

/* ==========
   FORM STYLING
   ========== */

.form-card h2,
.list-card h2 {
  margin-top: 0;
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.75rem;
}

.form-group label {
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
  color: #374151;
}

.form-group input,
.form-group select {
  border-radius: 0.75rem;
  border: 1px solid #d1d5db;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background-color 0.15s ease;
  background-color: #f9fafb;
}

.form-group input:focus,
.form-group select:focus {
  border-color: #0ea5e9;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.25);
  background-color: #ffffff;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ERROR FORM */
.form-error {
  color: #b91c1c;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  min-height: 1rem;
}

/* Tombol */
.btn {
  border-radius: 999px;
  border: none;
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: background-color 0.15s ease, transform 0.08s ease,
    box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #22c55e);
  color: #f9fafb;
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.4);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(14, 165, 233, 0.5);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.4);
}

.btn-secondary {
  background: #f9fafb;
  color: #111827;
  border: 1px solid #d1d5db;
}

.btn-secondary:hover {
  background: #e5e7eb;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* ==========
   LIST & TABEL
   ========== */

.list-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.total-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 999px;
  background: #f3f4f6;
  padding: 0.35rem 0.75rem;
  font-size: 0.9rem;
  min-width: 0;
}

.total-wrapper span {
  color: #4b5563;
  margin-right: 0.5rem;
}

.total-wrapper strong {
  color: #111827;
}

/* Bungkus tabel agar bisa scroll horizontal di layar kecil */
.table-wrapper {
  margin-top: 0.5rem;
}

/* STATE KOSONG */
.empty-state {
  text-align: center;
  color: #6b7280;
  font-size: 0.9rem;
  margin: 1rem 0 0;
}

/* ==========
   TAMPILAN MOBILE: CARD VIEW
   ==========
   - Di mobile, tiap baris pengeluaran tampil seperti kartu.
   - Di layar lebih besar, kita pakai tabel klasik (lihat media query).
*/

.expense-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

/* Sembunyikan header di mobile; kita akan pakai label via CSS */
.expense-table thead {
  display: none;
}

/* Setiap baris jadi card */
.expense-table tr {
  display: block;
  background: #f9fafb;
  border-radius: 0.9rem;
  margin-bottom: 0.75rem;
  padding: 0.65rem 0.75rem;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.05);
}

/* Tiap cell tampil sebagai baris sendiri */
.expense-table td {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  align-items: center;
  padding: 0.2rem 0;
  border: none;
}

/* Label kiri untuk menjelaskan kolom */
.expense-table td::before {
  content: attr(data-label);
  font-weight: 500;
  color: #6b7280;
  margin-right: 0.25rem;
}

/* Kolom aksi (hapus) disesuaikan */
.expense-table td.action-cell {
  margin-top: 0.35rem;
}

.expense-table td.action-cell::before {
  content: "";
}

/* Tombol hapus kecil */
.btn-delete {
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 999px;
  border: none;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.08s ease;
}

.btn-delete:hover {
  background: #fecaca;
}

/* ==========
   BREAKPOINT: TABLET & DESKTOP
   ========== */

@media (min-width: 640px) {
  .app-main {
    padding: 0 1.5rem 1.75rem;
  }

  .app-header h1 {
    font-size: 1.6rem;
  }

  .form-row {
    flex-direction: row;
  }

  .form-row .form-group {
    flex: 1;
  }
}

@media (min-width: 900px) {
  .app-main {
    flex-direction: row;
    align-items: flex-start;
  }

  .form-card {
    flex: 0 0 40%;
  }

  .list-card {
    flex: 1;
  }

  .list-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .total-wrapper {
    min-width: 200px;
  }

  /* TABEL KLASIK DI LAYAR LEBIH BESAR */
  .expense-table {
    border-radius: 0.75rem;
    overflow: hidden;
  }

  .expense-table thead {
    display: table-header-group;
    background: #f3f4f6;
  }

  .expense-table tr {
    display: table-row;
    background: transparent;
    border-radius: 0;
    margin-bottom: 0;
    padding: 0;
    box-shadow: none;
  }

  .expense-table th,
  .expense-table td {
    display: table-cell;
    padding: 0.55rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
  }

  .expense-table th {
    font-size: 0.8rem;
    font-weight: 600;
    color: #6b7280;
  }

  .expense-table tbody tr:nth-child(even) {
    background: #f9fafb;
  }

  /* Hilangkan label data-label di desktop */
  .expense-table td::before {
    content: none;
  }

  .expense-table td.action-cell {
    text-align: center;
    width: 1%;
    white-space: nowrap;
  }

  .btn-delete {
    padding: 0.3rem 0.9rem;
  }
}
