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

:root {
  /* Army / Gold palette */
  --bg:          #1A1F14;
  --bg-2:        #22281B;
  --bg-3:        #2D3322;
  --border:      #3D4D2D;
  --text:        #F9F5EE;
  --text-muted:  #7A9068;
  --accent:      #C9A84C;
  --accent-hover:#E8C86A;

  /* Semantic colours — kept for income/expense/asset readability */
  --green:       #4ade80;
  --green-bg:    rgba(74,222,128,0.12);
  --red:         #f87171;
  --red-bg:      rgba(248,113,113,0.12);
  --blue:        #C9A84C;
  --blue-bg:     rgba(201,168,76,0.12);
  --purple:      #a3e635;
  --purple-bg:   rgba(163,230,53,0.12);
  --yellow:      #fbbf24;

  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,0.5);
}

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

.app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  gap: 8px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.logo-star {
  color: var(--accent);
  font-size: 16px;
  flex-shrink: 0;
}

.logo-text {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 18px;
  letter-spacing: 1px;
  color: #fff;
  line-height: 1;
}

.logo-two { color: var(--accent); }

/* Back to website button — sits above the app nav */
.nav-item-back {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  background: rgba(201,168,76,0.1);
  border: 1px solid rgba(201,168,76,0.2);
  margin-bottom: 10px;
  transition: all 0.15s;
}
.nav-item-back:hover {
  background: rgba(201,168,76,0.18);
  border-color: rgba(201,168,76,0.4);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}

.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: rgba(201,168,76,0.15); color: var(--accent); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.net-worth-card {
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nw-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.nw-value { font-size: 20px; font-weight: 700; color: var(--green); }

/* ── Main ── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  background: var(--bg);
}

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary { background: var(--accent); color: #1A1F14; font-weight: 700; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--bg-3); color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-icon { padding: 6px; background: transparent; color: var(--text-muted); }
.btn-icon:hover { color: var(--text); background: var(--bg-3); }
.btn-danger { background: var(--red-bg); color: var(--red); border: none; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 12px; }

.header-actions { display: flex; align-items: center; gap: 8px; }

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

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

.card-header h3 { font-size: 14px; font-weight: 600; color: var(--text); }

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-card.income { border-left: 3px solid var(--green); }
.stat-card.expense { border-left: 3px solid var(--red); }
.stat-card.asset { border-left: 3px solid var(--blue); }
.stat-card.balance { border-left: 3px solid var(--purple); }

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-card.income .stat-icon { background: var(--green-bg); color: var(--green); }
.stat-card.expense .stat-icon { background: var(--red-bg); color: var(--red); }
.stat-card.asset .stat-icon { background: var(--blue-bg); color: var(--blue); }
.stat-card.balance .stat-icon { background: var(--purple-bg); color: var(--purple); }

.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }

/* ── Charts ── */
.charts-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-card canvas { max-height: 220px; }

.category-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Transaction List ── */
.transaction-list { display: flex; flex-direction: column; }

.tx-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.tx-item:last-child { border-bottom: none; }

.tx-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.tx-icon.income { background: var(--green-bg); }
.tx-icon.expense { background: var(--red-bg); }

.tx-details { flex: 1; min-width: 0; }
.tx-desc { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.tx-cat {
  display: inline-block;
  background: var(--bg-3);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 6px;
}

.tx-amount {
  font-weight: 700;
  font-size: 14px;
  text-align: right;
  flex-shrink: 0;
}

.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--red); }

.tx-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.tx-item:hover .tx-actions { opacity: 1; }

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

.empty-state svg { opacity: 0.3; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ── Filters ── */
.filters-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.input-sm, .select-sm {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.input-sm:focus, .select-sm:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(201,168,76,0.2); }
.input-sm::placeholder { color: var(--text-muted); }

/* ── Assets ── */
.assets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.asset-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.asset-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.asset-type-badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.asset-type-badge.cash { background: var(--green-bg); color: var(--green); }
.asset-type-badge.investment { background: var(--blue-bg); color: var(--blue); }
.asset-type-badge.property { background: var(--purple-bg); color: var(--purple); }
.asset-type-badge.vehicle { background: rgba(245,158,11,0.12); color: var(--yellow); }
.asset-type-badge.liability { background: var(--red-bg); color: var(--red); }
.asset-type-badge.other { background: var(--bg-3); color: var(--text-muted); }

.asset-name { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.asset-value { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.asset-value.positive { color: var(--green); }
.asset-value.negative { color: var(--red); }

.asset-actions {
  display: flex;
  gap: 4px;
  margin-top: 12px;
}

/* ── Summary Table ── */
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.summary-table th {
  text-align: left;
  padding: 10px 14px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.summary-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.summary-table tr:last-child td { border-bottom: none; }
.summary-table tr:hover td { background: var(--bg-3); }

.amount-positive { color: var(--green); font-weight: 600; }
.amount-negative { color: var(--red); font-weight: 600; }
.amount-neutral { color: var(--text-muted); }

.month-label { font-weight: 600; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  animation: modal-in 0.2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.modal-header h2 { font-size: 17px; font-weight: 700; }

.modal-close {
  background: var(--bg-3);
  border: none;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.modal-close:hover { background: var(--red-bg); color: var(--red); }

.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.optional { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-muted); }

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(201,168,76,0.15); }
textarea { resize: vertical; }
select option { background: var(--bg-2); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

/* ── Mobile Nav (hidden on desktop) ── */
.mobile-nav { display: none; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Utility ── */
.text-green { color: var(--green); }
.text-red { color: var(--red); }

/* ── Tablet ── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}

/* ── Mobile ── */
@media (max-width: 640px) {
  body { overflow: hidden; }

  .app { flex-direction: column; height: 100dvh; }

  /* Hide sidebar, show mobile nav */
  .sidebar { display: none; }

  .main {
    flex: 1;
    padding: 16px;
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Mobile bottom nav */
  .mobile-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    z-index: 100;
  }

  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 8px;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav-item.active { color: var(--accent); }

  .mobile-nav-add {
    width: 48px;
    height: 48px;
    background: var(--accent);
    color: #1A1F14 !important;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-bottom: 2px;
    box-shadow: 0 4px 12px rgba(201,168,76,0.4);
  }

  .mobile-nav-add span { display: none; }

  .mobile-nav-back {
    color: var(--accent) !important;
  }

  /* Page header */
  .page-header {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
  }

  .page-header h1 { font-size: 20px; }

  /* Hide the desktop "+ Add" button on dashboard/transactions on mobile */
  #open-add-modal,
  #open-add-modal-2 { display: none; }

  /* Stats: 2 columns on mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }

  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-icon { width: 34px; height: 34px; }
  .stat-value { font-size: 17px; }
  .stat-label { font-size: 10px; }

  /* Charts stack */
  .charts-row {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 14px;
  }

  .card { padding: 14px; margin-bottom: 12px; }
  .card-header { margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }

  /* Constrain chart heights on mobile */
  .chart-card canvas { max-height: 180px; }
  #category-chart { max-height: 200px; width: 200px !important; margin: 0 auto; display: block; }

  /* Transaction items */
  .tx-item { padding: 10px 0; gap: 10px; }
  .tx-icon { width: 32px; height: 32px; font-size: 13px; }
  .tx-actions { opacity: 1; }
  .tx-amount { font-size: 13px; }

  /* Filters: horizontal scroll */
  .filters-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    gap: 6px;
    scrollbar-width: none;
  }
  .filters-bar::-webkit-scrollbar { display: none; }
  .input-sm, .select-sm { white-space: nowrap; flex-shrink: 0; font-size: 12px; padding: 6px 8px; }
  #filter-search { min-width: 120px; }

  /* Assets */
  .assets-grid { grid-template-columns: 1fr; gap: 10px; }
  .asset-value { font-size: 20px; }

  /* Summary table: scroll horizontally */
  #summary-table-wrapper { overflow-x: auto; padding: 0; }
  .summary-table { min-width: 380px; }
  .summary-table th, .summary-table td { padding: 10px 10px; }

  /* Modal: slide up from bottom */
  .modal-overlay { align-items: flex-end; }

  .modal {
    border-radius: 18px 18px 0 0;
    max-width: 100%;
    width: 100%;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
    max-height: 92dvh;
    overflow-y: auto;
  }

  .form-row { grid-template-columns: 1fr; gap: 0; }

  /* Asset modal */
  #open-asset-modal { font-size: 13px; padding: 8px 12px; }
}
