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

/* ── Design tokens ── */
:root {
  --bg:         #f7f6f3;
  --surface:    #ffffff;
  --surface-2:  #f2f0ec;
  --border:     rgba(0,0,0,0.08);
  --border-md:  rgba(0,0,0,0.13);
  --text:       #1a1a18;
  --text-2:     #6b6a65;
  --text-3:     #9e9d98;
  --green:      #1d8f6a;
  --green-bg:   #e6f5ef;
  --red:        #c94040;
  --red-bg:     #fbeaea;
  --amber:      #b07014;
  --amber-bg:   #fdf3e3;
  --blue:       #2563c0;
  --blue-bg:    #e8effc;
  --purple:     #7c3aed;
  --purple-bg:  #f0ecfa;
  --accent:     #1a1a18;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

/* ── Base ── */
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}
a { text-decoration: none; color: inherit; }

/* ── App shell ── */
.shell { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s;
}
.sidebar-logo {
  padding: 0 20px 24px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.nav-section { flex: 1; }
.nav-label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-3);
  padding: 0 20px;
  margin-bottom: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text-2);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background 0.12s, color 0.12s;
  user-select: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  color: var(--text);
  background: var(--surface-2);
  border-left-color: var(--accent);
  font-weight: 500;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }
.sidebar-bottom {
  margin-top: auto;
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
}
.role-label { font-size: 11px; color: var(--text-3); margin-bottom: 6px; }
.role-select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b6a65' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.role-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--green-bg);
  color: var(--green);
}
.role-badge.viewer { background: var(--blue-bg); color: var(--blue); }

/* ── Main ── */
.main { margin-left: 220px; flex: 1; min-width: 0; }

/* ── Topbar ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title { font-size: 15px; font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.month-select {
  padding: 6px 10px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 600;
}
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text);
}

/* ── Page content ── */
.content { padding: 28px; }
.section-title {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-3);
  margin-bottom: 14px;
}

/* ── Cards ── */
.cards-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card-label { font-size: 12px; color: var(--text-3); margin-bottom: 8px; }
.card-value { font-size: 24px; font-weight: 600; letter-spacing: -0.5px; margin-bottom: 6px; }
.card-sub { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.card-sub.up   { color: var(--green); }
.card-sub.down { color: var(--red);   }
.card-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.card-icon.green  { background: var(--green-bg);  color: var(--green);  }
.card-icon.red    { background: var(--red-bg);    color: var(--red);    }
.card-icon.blue   { background: var(--blue-bg);   color: var(--blue);   }
.card-icon.amber  { background: var(--amber-bg);  color: var(--amber);  }

/* ── Chart cards ── */
.charts-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 14px;
  margin-bottom: 28px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}
.chart-title { font-size: 13px; font-weight: 500; }
.chart-sub   { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.chart-canvas-wrap { position: relative; width: 100%; height: 220px; }
.donut-wrap        { position: relative; width: 100%; height: 200px; }

/* Donut legend */
.donut-legend { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.legend-item  { display: flex; align-items: center; justify-content: space-between; font-size: 12px; }
.legend-left  { display: flex; align-items: center; gap: 7px; }
.legend-dot   { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-name  { color: var(--text-2); }
.legend-val   { font-weight: 500; }

/* ── Transactions table ── */
.tx-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.tx-search {
  flex: 1;
  min-width: 160px;
  padding: 8px 12px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.tx-search:focus { border-color: var(--accent); }
.tx-filter, .tx-sort {
  padding: 8px 10px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b6a65' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}
.add-btn {
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.add-btn:hover { opacity: 0.82; }
.add-btn.hidden { display: none; }

.tx-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th:hover { color: var(--text); }
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody td { padding: 11px 16px; font-size: 13px; vertical-align: middle; }
.tx-cat {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
}
.tx-amount { font-family: 'DM Mono', monospace; font-size: 13px; font-weight: 500; }
.tx-amount.income  { color: var(--green); }
.tx-amount.expense { color: var(--red);   }
.tx-date { color: var(--text-3); font-size: 12px; }
.no-data { text-align: center; padding: 48px; color: var(--text-3); font-size: 13px; }

/* ── Insights ── */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.insight-tag {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 2px 7px;
  border-radius: 20px;
  display: inline-block;
  margin-bottom: 10px;
}
.insight-tag.amber  { background: var(--amber-bg);  color: var(--amber);  }
.insight-tag.blue   { background: var(--blue-bg);   color: var(--blue);   }
.insight-tag.green  { background: var(--green-bg);  color: var(--green);  }
.insight-heading    { font-size: 14px; font-weight: 500; margin-bottom: 5px; }
.insight-body       { font-size: 12.5px; color: var(--text-2); line-height: 1.55; }
.insight-number     { font-size: 28px; font-weight: 600; letter-spacing: -0.5px; margin: 8px 0 4px; }

.monthly-bars     { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.monthly-bar-row  { display: flex; flex-direction: column; gap: 4px; }
.monthly-bar-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); }
.bar-track  { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar-fill   { height: 100%; border-radius: 3px; transition: width 0.5s ease; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 420px;
  max-width: calc(100vw - 40px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.14);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}
.modal-title { font-size: 15px; font-weight: 600; margin-bottom: 20px; }
.form-row    { margin-bottom: 14px; }
.form-label  { font-size: 12px; color: var(--text-2); margin-bottom: 5px; display: block; }
.form-input, .form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-select { appearance: none; cursor: pointer; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn-cancel {
  padding: 8px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-2);
}
.btn-save {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-cancel:hover { background: var(--border); }
.btn-save:hover   { opacity: 0.85; }

/* ── Mobile sidebar overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 90;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.22s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .cards-row     { grid-template-columns: repeat(2, 1fr); }
  .insights-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  .hamburger { display: block; }
  .content { padding: 18px; }
  .cards-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .insights-grid { grid-template-columns: 1fr; }
  .topbar { padding: 12px 18px; }
}
@media (max-width: 480px) {
  .cards-row { grid-template-columns: 1fr; }
}
