:root {
  color-scheme: dark;
  /* Carbon Mint – dark mode, glowing mint */
  --bg: #020309; /* deep anthracite */
  --bg-elevated: #050816; /* dark cards */
  --border-subtle: #111827;
  --text-main: #e5f0ff;
  --text-muted: #6b7280;
  --accent: #22e3a1; /* mint */
  --accent-soft: rgba(34, 227, 161, 0.16);
  --highlight: #0ea5e9; /* cyan highlight for charts */
  --danger: #fb7185; /* soft rose */
  --danger-soft: rgba(251, 113, 133, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(34, 227, 161, 0.08), transparent 55%),
    radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.16), transparent 55%),
    linear-gradient(160deg, #020309, #020617 55%, #020309);
  color: var(--text-main);
}

.app {
  max-width: 1120px;
  margin: 32px auto 40px;
  padding: 0 24px 32px;
  animation: app-fade-in 0.6s ease-out;
}

.app-header {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 2rem;
  letter-spacing: 0.03em;
}

.app-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

@keyframes app-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  background:
    radial-gradient(circle at top left, rgba(34, 227, 161, 0.14), transparent 60%),
    linear-gradient(145deg, rgba(5, 12, 30, 0.96), rgba(2, 6, 23, 0.96));
  border-radius: 16px;
  padding: 18px 18px 16px;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(18px);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  transform-origin: top left;
  animation: card-pop-in 0.4s ease-out;
  transition: transform 0.18s ease-out, box-shadow 0.18s ease-out, border-color 0.18s ease-out;
}

.card::before {
  content: "";
  position: absolute;
  inset: -1px;
  background: radial-gradient(circle at top left, rgba(34, 227, 161, 0.22), transparent 70%);
  opacity: 0.35;
  pointer-events: none;
}

.card:hover {
  transform: translateY(-3px) scale(1.01);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.9);
  border-color: rgba(34, 227, 161, 0.45);
}

@keyframes card-pop-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.card-header-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.layout-two-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 18px;
  align-items: flex-start;
}

@media (max-width: 900px) {
  .layout-two-columns {
    grid-template-columns: minmax(0, 1fr);
  }
}

.expense-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 14px;
  align-items: flex-end;
}

@media (max-width: 900px) {
  .expense-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .expense-form {
    grid-template-columns: minmax(0, 1fr);
  }
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row-wide {
  grid-column: span 2;
}

@media (max-width: 640px) {
  .form-row-wide {
    grid-column: span 1;
  }
}

label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

input,
select,
button {
  font-family: inherit;
}

input,
select {
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.96);
  color: var(--text-main);
  padding: 8px 12px;
  font-size: 0.9rem;
  outline: none;
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease,
    background 0.12s ease,
    transform 0.08s ease-out;
}

input::placeholder {
  color: var(--text-muted);
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(34, 227, 161, 0.6);
  background: rgba(15, 23, 42, 1);
  transform: translateY(-1px);
}

.btn-primary {
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #22e3a1, #0ea5e9);
  color: #021014;
  padding: 9px 18px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(56, 189, 248, 0.26);
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    filter 0.12s ease,
    background-position 0.18s ease;
  background-size: 200% 200%;
  background-position: 0% 50%;
}

.btn-primary:hover {
  transform: translateY(-1px) translateZ(0);
  box-shadow: 0 14px 30px rgba(34, 227, 161, 0.5);
  filter: brightness(1.05);
  background-position: 100% 50%;
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 8px 18px rgba(0, 200, 83, 0.35);
}

.summary {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.9rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: radial-gradient(circle at top left, rgba(34, 227, 161, 0.14), transparent 70%);
  border: 1px solid rgba(34, 227, 161, 0.4);
}

.summary strong {
  font-size: 0.95rem;
}

.table-wrapper {
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(15, 23, 42, 0.9), transparent 70%),
    linear-gradient(135deg, #020617, #020617);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.table-wrapper:hover {
  border-color: rgba(88, 86, 214, 0.24);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

thead {
  background: rgba(15, 23, 42, 0.98);
}

th,
td {
  padding: 8px 10px;
}

th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:nth-child(even) {
  background: rgba(15, 23, 42, 0.85);
}

tbody tr:nth-child(odd) {
  background: rgba(15, 23, 42, 0.95);
}

tbody tr:hover {
  background: rgba(15, 23, 42, 1);
  transition: background 0.12s ease;
}

.align-right {
  text-align: right;
}

.delete-btn {
  border-radius: 999px;
  border: none;
  background: var(--danger-soft);
  color: var(--danger);
  padding: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

.delete-btn:hover {
  background: rgba(248, 113, 113, 0.2);
}

.empty-state {
  margin: 10px 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.reminder-banner {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 999px;
  background: radial-gradient(circle at top left, rgba(234, 179, 8, 0.18), transparent 70%);
  border: 1px solid rgba(234, 179, 8, 0.55);
  color: #fef9c3;
  font-size: 0.85rem;
  display: none;
}

.time-range-toggle {
  display: inline-flex;
  padding: 2px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--border-subtle);
}

.toggle-btn {
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.toggle-btn.active {
  background: linear-gradient(135deg, #22e3a1, #0ea5e9);
  color: #021014;
}

.analytics-summary {
  display: flex;
  justify-content: flex-start;
  gap: 18px;
  margin-bottom: 10px;
  font-size: 0.85rem;
}

.analytics-summary span {
  color: var(--text-muted);
  display: block;
}

.badge-category {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #e5f0ff;
}

.badge-category-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
}

.badge-Fuel {
  background: linear-gradient(135deg, #0ea5e9, #22e3a1);
}

.badge-Food {
  background: linear-gradient(135deg, #fb923c, #f97316);
}

.badge-Travel {
  background: linear-gradient(135deg, #6366f1, #0ea5e9);
}

.badge-Groceries {
  background: linear-gradient(135deg, #22c55e, #a3e635);
}

.badge-Bills {
  background: linear-gradient(135deg, #f97316, #dc2626);
}

.badge-Shopping {
  background: linear-gradient(135deg, #ec4899, #8b5cf6);
}

.badge-Rolling {
  background: linear-gradient(135deg, #14b8a6, #0f766e);
}

.badge-Other {
  background: linear-gradient(135deg, #6b7280, #4b5563);
}

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 900px) {
  .charts {
    grid-template-columns: minmax(0, 1fr);
  }
}

.chart-card h3 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.chart-card canvas {
  width: 100%;
  max-height: 260px;
  animation: chart-fade-in 0.5s ease-out;
}

@keyframes chart-fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile 2-Layer Tables */
@media (max-width: 640px) {
  table, thead, tbody, th, td, tr {
    display: block;
  }
  
  thead {
    display: none;
  }
  
  tbody tr {
    display: grid;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-subtle);
    gap: 10px;
    position: relative;
    background: transparent !important;
  }
  
  tbody tr:last-child {
    border-bottom: none;
  }

  td {
    padding: 0 !important;
    border: none !important;
    text-align: left;
    display: flex;
    align-items: center;
  }

  /* Expenses Table Layout */
  #expense-tbody tr {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "date category"
      "desc amount";
  }
  #expense-tbody .td-date { grid-area: date; font-weight: 500; font-size: 0.95rem; }
  #expense-tbody .td-date::before { content: "Date: "; margin-right: 6px; opacity: 0.6; font-size: 0.85rem; font-weight: normal; }
  
  #expense-tbody .td-category { grid-area: category; justify-content: flex-end; padding-right: 60px !important; }
  #expense-tbody .td-category::before { content: "Category: "; margin-right: 6px; opacity: 0.6; font-size: 0.85rem; font-weight: normal; }
  
  #expense-tbody .td-desc { grid-area: desc; color: var(--text-muted); font-size: 0.9rem; border-top: 1px dashed rgba(255, 255, 255, 0.15); padding-top: 12px !important; margin-top: 6px; }
  #expense-tbody .td-desc::before { content: "Desc: "; margin-right: 6px; opacity: 0.6; font-size: 0.85rem; font-weight: normal; }
  
  #expense-tbody .td-amount { grid-area: amount; justify-content: flex-start; font-weight: 600; font-size: 1.05rem; margin-left: 12px; border-top: 1px dashed rgba(255, 255, 255, 0.15); padding-top: 12px !important; margin-top: 6px; }
  #expense-tbody .td-amount::before { content: "Amount: "; margin-right: 6px; opacity: 0.6; font-size: 0.85rem; font-weight: normal; }
  
  /* Debts Table Layout */
  #debt-tbody tr {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "name type"
      "amount amount"
      "given return";
  }
  #debt-tbody .td-name { grid-area: name; font-weight: 600; font-size: 0.82rem; }
  #debt-tbody .td-name::before { content: "Person: "; margin-right: 6px; opacity: 0.6; font-size: 0.8rem; font-weight: normal; }
  
  #debt-tbody .td-type { grid-area: type; color: var(--text-muted); font-size: 0.82rem; justify-content: flex-end; padding-right: 50px !important; }
  #debt-tbody .td-type::before { content: "Type: "; margin-right: 6px; opacity: 0.6; font-size: 0.8rem; font-weight: normal; }
  
  #debt-tbody .td-amount { 
    grid-area: amount; 
    justify-content: center; 
    text-align: center;
    font-weight: 600; 
    padding: 8px 0 !important; 
    margin: 4px 0;
    color: var(--text-main);
  }
  #debt-tbody .td-amount::before { 
    content: ""; 
    flex: 1; 
    border-bottom: 1px dashed rgba(255, 255, 255, 0.15); 
    margin-right: 12px; 
  }
  #debt-tbody .td-amount::after { 
    content: ""; 
    flex: 1; 
    border-bottom: 1px dashed rgba(255, 255, 255, 0.15); 
    margin-left: 12px; 
  }
  
  #debt-tbody .td-given { grid-area: given; font-size: 0.85rem; color: var(--text-muted); }
  #debt-tbody .td-return { grid-area: return; font-size: 0.85rem; color: var(--text-muted); justify-content: flex-start; }
  
  #debt-tbody .td-given::before { content: "Given: "; margin-right: 4px; opacity: 0.8; }
  #debt-tbody .td-return::before { content: "Return: "; margin-right: 4px; opacity: 0.8; }

  /* Generic Actions Wrapper */
  td.td-actions {
    position: absolute;
    top: 14px;
    right: 0;
    grid-area: unset !important;
    display: block;
    width: auto;
  }
}
