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

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --line: #dce3ef;
  --text: #142033;
  --muted: #5b6880;
  --primary: #1f4d8f;
  --primary-soft: #e9f0fb;
  --positive: #1f8a5b;
  --positive-soft: #e8f7ef;
  --negative: #c73a3a;
  --negative-soft: #fdecec;
  --neutral-soft: #eef2f8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(15, 30, 58, 0.08);
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: linear-gradient(180deg, #edf2fa 0%, #f8fafd 100%);
  color: var(--text);
}

.app-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0f1e35;
  color: #dfe7f5;
  padding: 22px 16px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.03em;
  background: linear-gradient(135deg, #2f6bc0 0%, #4f89dc 100%);
  color: #fff;
}

.brand-title {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: #aebbd2;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-link {
  color: #c9d4e8;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.2s ease, color 0.2s ease;
}

.side-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.side-link.active {
  background: rgba(79, 137, 220, 0.22);
  color: #fff;
}

.main-area {
  padding: 20px;
  display: grid;
  gap: 16px;
}

.topbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-left h1 {
  margin: 0;
  font-size: 1.35rem;
}

.topbar-left p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.topbar-right {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.control-group {
  display: grid;
  gap: 4px;
}

.control-group label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-group select,
.control-group input[type='date'] {
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  border-radius: 9px;
  font: inherit;
  color: var(--text);
  padding: 0 10px;
  min-width: 150px;
}

.profile-chip {
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

.profile-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--positive);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.metric-value {
  margin: 8px 0 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.metric-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.status-badge {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.74rem;
  font-weight: 700;
}

.status-badge.positive {
  color: var(--positive);
  background: var(--positive-soft);
}

.status-badge.negative {
  color: var(--negative);
  background: var(--negative-soft);
}

.status-badge.neutral {
  color: #3d516f;
  background: var(--neutral-soft);
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
}

.health-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.health-score {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.health-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.health-scale {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.health-label {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.health-label.good {
  color: var(--positive);
  background: var(--positive-soft);
}

.health-label.average {
  color: #956715;
  background: #fff4de;
}

.health-label.poor {
  color: var(--negative);
  background: var(--negative-soft);
}

.health-note {
  margin: 0;
  width: 100%;
  color: var(--muted);
  font-size: 0.8rem;
}

.expense-chart-list {
  display: grid;
  gap: 10px;
}

.expense-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  gap: 10px;
  align-items: center;
}

.expense-cat {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-track {
  height: 8px;
  border-radius: 999px;
  background: #edf2fb;
  overflow: hidden;
}

.expense-fill {
  height: 100%;
  background: linear-gradient(90deg, #1f4d8f 0%, #5a87cb 100%);
}

.expense-amt {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
}

.chart-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.trend-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end;
  gap: 8px;
  min-height: 190px;
}

.trend-bar-wrap {
  display: grid;
  justify-items: center;
  gap: 6px;
}

.trend-profit {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 700;
}

.trend-bar {
  width: 100%;
  max-width: 28px;
  border-radius: 8px 8px 4px 4px;
  background: #dce5f4;
}

.trend-bar.positive {
  background: linear-gradient(180deg, #5e9f7d 0%, #1f8a5b 100%);
}

.trend-bar.negative {
  background: linear-gradient(180deg, #df7c7c 0%, #c73a3a 100%);
}

.trend-label {
  font-size: 0.68rem;
  color: var(--muted);
}

.segmented-control {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.btn-segment {
  border: none;
  background: #f2f6fd;
  color: var(--muted);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
}

.btn-segment.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.top-expenses-list {
  display: grid;
  gap: 8px;
}

.insights-list {
  display: grid;
  gap: 8px;
}

.insight-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
  padding: 10px;
}

.insight-label {
  display: inline-flex;
  margin-bottom: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 8px;
  border-radius: 999px;
}

.insight-msg {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
}

.alerts-list {
  display: grid;
  gap: 8px;
}

.alert-item {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 10px;
  background: #f8fafc;
}

.alert-item.high {
  background: #fff1f1;
  border-color: #f2c2c2;
}

.alert-item.medium {
  background: #fff9ec;
  border-color: #f2ddb1;
}

.alert-item.low {
  background: #eef6ff;
  border-color: #c9ddf8;
}

.alert-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.alert-title {
  font-size: 0.84rem;
  font-weight: 700;
}

.alert-severity {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.05);
}

.alert-message {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.top-expense-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
}

.top-left {
  display: grid;
  gap: 2px;
}

.top-cat {
  font-size: 0.82rem;
  font-weight: 700;
}

.top-share {
  font-size: 0.74rem;
  color: var(--muted);
}

.top-amt {
  font-size: 0.82rem;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

.txn-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.txn-table th,
.txn-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.8rem;
}

.txn-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.txn-type {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.txn-type.sale {
  background: var(--positive-soft);
  color: var(--positive);
}

.txn-type.expense {
  background: var(--negative-soft);
  color: var(--negative);
}

.txn-status {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.txn-status.approved {
  color: var(--positive);
}

.txn-status.pending {
  color: #b57d18;
}

.txn-status.rejected {
  color: var(--negative);
}

.comparison-table td {
  vertical-align: middle;
}

.compare-biz {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.best-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
}

.best-dot.best {
  background: var(--positive);
}

.best-tag {
  margin-left: 6px;
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--positive);
}

.perf-badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
}

.table-empty {
  display: none;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.table-empty.show {
  display: block;
}

@media (max-width: 1080px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 12px;
  }

  .side-nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .side-link {
    text-align: center;
    font-size: 0.8rem;
  }
}

@media (max-width: 820px) {
  .kpi-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .topbar-right {
    width: 100%;
  }

  .control-group {
    flex: 1;
    min-width: 140px;
  }

  .control-group select,
  .control-group input[type='date'] {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .main-area {
    padding: 12px;
  }

  .topbar {
    padding: 12px;
  }

  .side-nav {
    grid-template-columns: 1fr 1fr;
  }

  .trend-chart {
    min-height: 160px;
  }

  .expense-row {
    grid-template-columns: 90px 1fr auto;
  }
}

/* ── Sidebar footer: user chip + logout ─────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
}
.side-nav {
  flex: 1;
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  margin-bottom: 8px;
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg,#2f6bc0,#4f89dc);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.user-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #e2eaf5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 0.72rem;
  color: #7d93b8;
  text-transform: capitalize;
}
.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.25);
  color: #fca5a5;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.logout-btn:hover {
  background: rgba(239,68,68,0.2);
  border-color: rgba(239,68,68,0.45);
}

/* Role badge in topbar profile chip */
.role-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-badge.admin { background: rgba(79,137,220,0.18); color: #7db3f5; }
.role-badge.staff { background: rgba(100,200,120,0.15); color: #86efac; }
