:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --line: #dfe5ee;
  --text: #172033;
  --muted: #65758b;
  --sidebar: #08111f;
  --sidebar-raised: #101d30;
  --gold: #f2b233;
  --green: #14946e;
  --red: #d6543e;
  --blue: #315fba;
  --purple: #6f4fc6;
  --shadow: 0 12px 34px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  margin: 0;
  min-height: 100vh;
}

a {
  color: var(--blue);
  text-decoration: none;
}

button,
.button {
  align-items: center;
  background: var(--text);
  border: 0;
  border-radius: 7px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 750;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

button.secondary,
.button.secondary {
  background: #edf1f7;
  color: var(--text);
}

button.small,
.button.small {
  font-size: 12px;
  min-height: 30px;
  padding: 0 10px;
}

button.danger {
  background: var(--red);
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  color: var(--text);
  min-height: 38px;
  padding: 0 10px;
  width: 100%;
}

textarea {
  font: inherit;
  min-height: 86px;
  padding: 10px;
  resize: vertical;
}

input[type="file"] {
  padding: 8px 10px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 750;
  gap: 6px;
}

.sidebar {
  background: linear-gradient(180deg, #08111f, #0b1526 58%, #050914);
  color: #fff;
  display: flex;
  flex: 0 0 260px;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
  position: sticky;
  top: 0;
}

.brand {
  align-items: center;
  color: #fff;
  display: flex;
  gap: 12px;
}

.brand-logo {
  align-items: center;
  background: #050914;
  border: 1px solid rgba(242, 178, 51, 0.22);
  border-radius: 8px;
  display: flex;
  height: 48px;
  justify-content: center;
  padding: 6px;
  width: 58px;
}

.brand-logo img,
.login-logo {
  display: block;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 18px;
  letter-spacing: 0;
}

.brand small {
  color: #9fb0c7;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a,
.logout {
  border-radius: 7px;
  color: #ccd7e7;
  font-weight: 750;
  padding: 10px 12px;
}

.nav a.active,
.nav a:hover,
.logout:hover {
  background: var(--sidebar-raised);
  color: #fff;
}

.sidebar-user {
  align-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding: 10px;
}

.avatar {
  align-items: center;
  background: var(--gold);
  border-radius: 7px;
  color: #1b1200;
  display: flex;
  font-weight: 900;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.sidebar-user strong,
.sidebar-user small {
  display: block;
}

.sidebar-user small {
  color: #9fb0c7;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 24px;
}

.page-head {
  align-items: flex-end;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 20px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 16px;
}

.period-filter,
.toolbar {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.period-filter label {
  min-width: 104px;
}

.toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  padding: 12px;
}

.toolbar select {
  max-width: 190px;
}

.toolbar input[type="search"] {
  max-width: 280px;
}

.kpi-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

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

.kpi {
  display: grid;
  gap: 5px;
  min-height: 116px;
  padding: 16px;
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi strong {
  font-size: 25px;
  line-height: 1.1;
}

.kpi small {
  color: var(--muted);
}

.kpi.income {
  border-top: 4px solid var(--green);
}

.kpi.expense {
  border-top: 4px solid var(--red);
}

.kpi.net {
  border-top: 4px solid var(--blue);
}

.dashboard-grid,
.source-grid,
.two-col {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.8fr);
  margin-bottom: 18px;
}

.source-grid {
  grid-template-columns: repeat(4, minmax(210px, 1fr));
}

.two-col {
  align-items: start;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  min-width: 0;
  padding: 16px;
}

.panel.wide {
  min-height: 390px;
}

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

.panel-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

#cashflowChart {
  min-height: 310px;
}

.stats-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.stats-list div {
  align-items: center;
  border-bottom: 1px solid #edf1f7;
  display: flex;
  justify-content: space-between;
  padding-bottom: 10px;
}

.stats-list dt {
  color: var(--muted);
  font-weight: 750;
}

.stats-list dd {
  font-weight: 850;
  margin: 0;
}

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

table {
  border-collapse: collapse;
  min-width: 100%;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid #edf1f7;
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

td small {
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.truncate {
  display: block;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.truncate.long {
  max-width: 520px;
}

.empty {
  color: var(--muted);
  padding: 28px 8px;
  text-align: center;
}

.pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 850;
  padding: 4px 9px;
}

.pill.income {
  background: rgba(20, 148, 110, 0.12);
  color: var(--green);
}

.pill.expense {
  background: rgba(214, 84, 62, 0.12);
  color: var(--red);
}

.pill.neutral {
  background: rgba(101, 117, 139, 0.14);
  color: var(--muted);
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.flash {
  background: #fff7df;
  border: 1px solid #f2d596;
  border-radius: 8px;
  color: #5b4308;
  padding: 10px 12px;
}

.auth-page {
  align-items: center;
  display: grid;
  justify-content: center;
}

.auth-page .main {
  padding: 0;
}

.login-shell {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  padding: 24px;
  width: min(420px, calc(100vw - 32px));
}

.login-logo {
  background: #050914;
  border-radius: 8px;
  max-height: 78px;
  padding: 10px;
}

.login-panel h1 {
  font-size: 24px;
}

.form-panel {
  display: grid;
  gap: 12px;
}

.users-layout {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

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

.user-row {
  border: 1px solid #edf1f7;
  border-radius: 8px;
  padding: 10px;
}

.user-row form {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(130px, 1fr) 112px minmax(150px, 1fr);
}

.user-row button {
  width: 100%;
}

.user-row strong,
.user-row small {
  display: block;
}

.user-row small {
  color: var(--muted);
}

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

.actions-cell .button,
.actions-cell form {
  margin-left: 6px;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

@media (max-width: 1100px) {
  .kpi-grid,
  .dashboard-grid,
  .source-grid,
  .two-col,
  .users-layout {
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-grid .wide {
    grid-column: 1 / -1;
  }

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

@media (max-width: 760px) {
  body {
    display: block;
  }

  .sidebar {
    min-height: auto;
    position: static;
  }

  .main {
    padding: 16px;
  }

  .page-head {
    align-items: stretch;
    display: grid;
  }

  .kpi-grid,
  .dashboard-grid,
  .source-grid,
  .two-col,
  .users-layout {
    grid-template-columns: 1fr;
  }

  .period-filter label,
  .toolbar select,
  .toolbar input[type="search"] {
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  .period-filter,
  .toolbar {
    align-items: stretch;
    display: grid;
  }

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