:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #1f5eff;
  --primary-dark: #1747c7;
  --positive: #087f5b;
  --negative: #c92a2a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
.topbar {
  height: 66px;
  background: #111827;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5vw;
}
.brand { font-size: 1.1rem; font-weight: 800; }
.topbar nav { display: flex; gap: 22px; }
.topbar nav a { color: #dbeafe; }
.container { width: min(1180px, 92vw); margin: 32px auto 60px; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
h1 { margin: 0 0 6px; font-size: 2rem; }
h2 { margin-top: 28px; }
.muted { color: var(--muted); }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 7px 20px rgba(15, 23, 42, 0.04);
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.stat span { display: block; color: var(--muted); margin-bottom: 8px; }
.stat strong { font-size: 1.55rem; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.btn {
  border: 1px solid var(--border);
  background: white;
  border-radius: 10px;
  padding: 10px 15px;
  display: inline-block;
  cursor: pointer;
  font: inherit;
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn.primary:hover { background: var(--primary-dark); }
.month-nav, .actions, .form-actions { display: flex; gap: 10px; }
.actions { margin: 22px 0; }
.weeks-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.week-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.week-title small { display: block; color: var(--muted); margin-top: 4px; }
.badge {
  padding: 6px 9px;
  border-radius: 999px;
  background: #e8efff;
  color: #1747c7;
  font-size: .8rem;
}
.mini-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 18px 0;
  gap: 8px;
}
.mini-summary div {
  padding: 10px;
  border-radius: 10px;
  background: #f8fafc;
}
.mini-summary span { display: block; font-size: .77rem; color: var(--muted); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-size: .82rem; }
.right { text-align: right; }
.category { display: block; color: var(--muted); font-size: .74rem; }
.empty { padding: 16px 0 0; }
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 22px;
}
.category-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}
.alert { padding: 12px 15px; border-radius: 10px; margin-bottom: 16px; }
.alert.success { background: #d3f9d8; color: #176b34; }
.alert.danger { background: #ffe3e3; color: #9c1c1c; }
.login-wrap {
  min-height: 78vh;
  display: grid;
  place-items: center;
}
.login-card { width: min(430px, 100%); }
label { display: block; font-weight: 650; margin: 14px 0 7px; }
input, select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  background: white;
}
.login-card .btn { width: 100%; margin-top: 20px; }
.form-shell { display: grid; place-items: start center; }
.form-card { width: min(760px, 100%); }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.span-2 { grid-column: 1 / -1; }
.form-actions { justify-content: flex-end; margin-top: 24px; }
.table-wrap { overflow-x: auto; }
.full-table { min-width: 850px; }
.actions-cell { display: flex; gap: 10px; align-items: center; }
.actions-cell form { margin: 0; }
.link, .link-button {
  color: var(--primary);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
}
.danger-link { color: var(--negative); }
.disabled-row { opacity: .5; }

@media (max-width: 800px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .weeks-grid, .two-col { grid-template-columns: 1fr; }
  .mini-summary { grid-template-columns: repeat(2, 1fr); }
  .page-header { align-items: flex-start; flex-direction: column; }
  .topbar { height: auto; padding: 16px 4vw; gap: 12px; flex-direction: column; align-items: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}


.month-adjust-link {
  display: inline-block;
  margin-top: 5px;
  font-size: .78rem;
  color: var(--primary);
  font-weight: 650;
}
.base-amount {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 400;
}
.adjustment-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0;
}
.adjustment-summary div {
  background: #f8fafc;
  border-radius: 10px;
  padding: 12px;
}
.adjustment-summary span {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  margin-bottom: 5px;
}
@media (max-width: 800px) {
  .adjustment-summary { grid-template-columns: 1fr; }
}


.forecast-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 800px) {
  .forecast-grid {
    grid-template-columns: 1fr;
  }
}


.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
}

.section-heading h2 {
  margin: 0;
}

.section-toggle {
  min-width: 92px;
}

.collapsible-section[hidden] {
  display: none;
}

.transaction-row {
  background: var(--category-highlight, transparent);
  transition: background-color .18s ease, transform .18s ease;
}

.transaction-row:hover {
  background: color-mix(
    in srgb,
    var(--category-highlight, transparent) 82%,
    rgba(255, 255, 255, 0.18)
  );
}

.transaction-row td:first-child {
  border-left: 4px solid color-mix(
    in srgb,
    var(--category-highlight, transparent) 55%,
    rgba(71, 85, 105, 0.35)
  );
}

@supports not (background: color-mix(in srgb, white, black)) {
  .transaction-row:hover {
    background: var(--category-highlight, transparent);
  }

  .transaction-row td:first-child {
    border-left: 4px solid rgba(100, 116, 139, 0.22);
  }
}

@media (max-width: 650px) {
  .section-heading {
    align-items: flex-start;
  }
}


.annual-summary {
  margin-bottom: 24px;
}

.annual-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, .85fr);
  gap: 18px;
  align-items: start;
}

.annual-panel h2 {
  margin: 0 0 5px;
}

.annual-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.monthly-chart {
  height: 310px;
  display: grid;
  grid-template-columns: repeat(12, minmax(38px, 1fr));
  gap: 8px;
  align-items: end;
  padding: 30px 4px 0;
  border-bottom: 1px solid var(--border);
}

.monthly-bar-column {
  min-width: 0;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr 28px;
  align-items: end;
  justify-items: center;
  text-align: center;
}

.monthly-bar-value {
  font-size: .68rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.monthly-bar-track {
  width: min(44px, 84%);
  height: 100%;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  border-radius: 8px 8px 0 0;
  background: #edf2f7;
  overflow: hidden;
}

.monthly-bar {
  width: 100%;
  min-height: 2px;
  border-radius: 8px 8px 0 0;
  background: rgba(31, 94, 255, .65);
}

.monthly-bar-column strong {
  font-size: .78rem;
  padding-top: 7px;
}

.annual-table-wrap {
  margin-top: 24px;
  overflow-x: auto;
}

.annual-table {
  min-width: 580px;
}

.category-chart-layout {
  display: grid;
  gap: 26px;
  justify-items: center;
}

.category-donut {
  width: min(250px, 72vw);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e5e7eb;
}

.category-donut-center {
  width: 58%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--card);
  display: grid;
  place-content: center;
  text-align: center;
  border: 1px solid var(--border);
}

.category-donut-center span {
  color: var(--muted);
  font-size: .8rem;
}

.category-donut-center strong {
  margin-top: 4px;
  font-size: 1.05rem;
}

.annual-category-list {
  width: 100%;
}

.annual-category-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  gap: 9px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.category-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--annual-category-color, #94a3b8);
}

.annual-category-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.annual-category-item small {
  min-width: 42px;
  text-align: right;
  color: var(--muted);
}

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

@media (max-width: 700px) {
  .monthly-chart {
    height: 260px;
    gap: 4px;
  }

  .monthly-bar-value {
    display: none;
  }

  .monthly-bar-column {
    grid-template-rows: 1fr 28px;
  }

  .monthly-bar-track {
    width: min(24px, 82%);
  }
}


.highest-expense-highlight {
  min-width: 190px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
}

.highest-expense-highlight span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: .78rem;
}

.highest-expense-highlight strong {
  font-size: .95rem;
}

.monthly-bar-track {
  cursor: help;
  transition: background-color .18s ease;
}

.monthly-bar-track:hover {
  background: #dfe7f2;
}

.monthly-bar {
  transition: opacity .18s ease, transform .18s ease;
  transform-origin: bottom;
}

.monthly-bar-track:hover .monthly-bar {
  opacity: .88;
  transform: scaleX(1.06);
}

.chart-help {
  margin: 10px 0 0;
  font-size: .78rem;
  text-align: center;
}

@media (max-width: 700px) {
  .annual-panel-heading {
    flex-direction: column;
  }

  .highest-expense-highlight {
    width: 100%;
  }

  .monthly-bar-track {
    width: min(30px, 86%);
  }
}


.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, .75fr) minmax(0, 1.6fr);
  gap: 18px;
  align-items: start;
}

.admin-layout h2,
.admin-permissions-help h2 {
  margin-top: 0;
}

.admin-create-button {
  width: 100%;
  margin-top: 20px;
}

.admin-users-panel {
  min-width: 0;
}

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

.admin-user-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #fbfdff;
}

.revoked-user {
  opacity: .7;
  background: #f8fafc;
}

.admin-user-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.admin-user-header > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.access-status {
  padding: 5px 9px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
}

.active-access {
  color: #176b34;
  background: #d3f9d8;
}

.revoked-access {
  color: #9c1c1c;
  background: #ffe3e3;
}

.admin-user-actions {
  display: grid;
  gap: 13px;
  margin-top: 12px;
}

.inline-admin-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
}

.danger-button {
  color: white;
  background: var(--negative);
  border-color: var(--negative);
}

.restore-button {
  color: white;
  background: var(--positive);
  border-color: var(--positive);
}

.admin-permissions-help {
  margin-top: 18px;
}

.permission-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.permission-grid p {
  margin-bottom: 0;
}

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

@media (max-width: 620px) {
  .inline-admin-form {
    grid-template-columns: 1fr;
  }

  .inline-admin-form .btn {
    width: 100%;
  }
}


.control-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-selector label {
  margin: 0;
  color: #bfdbfe;
  font-size: .78rem;
}

.control-selector select {
  width: auto;
  min-width: 150px;
  padding: 7px 9px;
  border-color: #374151;
  background: #1f2937;
  color: white;
}

.logout-form {
  margin: 0;
}

.nav-button {
  padding: 0;
  border: 0;
  background: none;
  color: #dbeafe;
  cursor: pointer;
  font: inherit;
}

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

.admin-top-grid h2,
.admin-section h2 {
  margin-top: 0;
}

.admin-section {
  margin-top: 18px;
}

.admin-help {
  margin-bottom: 0;
}

.control-permission-block {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.control-permission-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.permission-table {
  min-width: 650px;
}

.permission-grid {
  grid-template-columns: repeat(3, 1fr);
}

.no-access-card {
  width: min(680px, 100%);
  margin: 80px auto;
}

@media (max-width: 980px) {
  .topbar nav {
    flex-wrap: wrap;
  }

  .admin-top-grid,
  .permission-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .control-selector {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
  }

  .control-selector select {
    width: 100%;
  }
}


.brand-area {
  display: flex;
  align-items: center;
  gap: 18px;
}

.logged-user {
  padding-left: 18px;
  border-left: 1px solid rgba(255, 255, 255, .25);
  color: #bfdbfe;
  font-size: .84rem;
}

.logged-user strong {
  color: white;
}

.control-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.control-title-group strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .brand-area {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .logged-user {
    padding-left: 0;
    border-left: 0;
  }

  .control-permission-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .control-permission-heading form,
  .control-permission-heading .btn {
    width: 100%;
  }
}
