:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #637381;
  --line: #d9e1e7;
  --green: #1f6f5b;
  --green-dark: #155747;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #c2413a;
  --teal-soft: #dff4ef;
  --blue-soft: #e7efff;
  --amber-soft: #fff4dc;
  --red-soft: #ffe8e5;
  --shadow: 0 16px 42px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

body.auth-mode .shell {
  display: block;
  min-height: 100vh;
}

body.auth-mode .sidebar,
body.auth-mode .topbar {
  display: none;
}

body.auth-mode .main,
body.auth-mode .content {
  min-height: 100vh;
}

body.auth-mode .content {
  padding: 0;
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-weight: 800;
}

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

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

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

.nav-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #334155;
  padding: 9px 10px;
  text-align: left;
}

.nav-item span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: #edf2f4;
  color: #52606d;
  font-size: 11px;
  font-weight: 800;
}

.nav-item:hover {
  background: #f0f4f5;
}

.nav-item.active {
  background: var(--teal-soft);
  color: var(--green-dark);
  font-weight: 700;
}

.nav-item.active span {
  background: #ffffff;
  color: var(--green);
}

.main {
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 24px 30px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 247, 0.92);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

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

h1 {
  font-size: clamp(24px, 3vw, 34px);
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.content {
  padding: 24px 30px 40px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 9px 12px;
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}

.primary-button {
  background: var(--green);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--green-dark);
}

.secondary-button {
  background: #ffffff;
  color: var(--green-dark);
  border-color: var(--line);
}

.ghost-button,
.icon-button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

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

.large-action {
  min-height: 46px;
  padding-inline: 18px;
  font-size: 15px;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 22px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-body {
  padding: 18px;
}

.metric-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 122px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}

.metric-card strong {
  font-size: 28px;
}

.metric-card span {
  color: var(--muted);
  font-weight: 650;
}

.metric-card.green {
  border-top: 4px solid var(--green);
}

.metric-card.blue {
  border-top: 4px solid var(--blue);
}

.metric-card.amber {
  border-top: 4px solid var(--amber);
}

.metric-card.red {
  border-top: 4px solid var(--red);
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #52606d;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #f7fafb;
}

td.money {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.empty {
  color: var(--muted);
  padding: 18px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pill.green {
  background: var(--teal-soft);
  color: var(--green-dark);
}

.pill.blue {
  background: var(--blue-soft);
  color: #1d4ed8;
}

.pill.amber {
  background: var(--amber-soft);
  color: #8a5a16;
}

.pill.red {
  background: var(--red-soft);
  color: #a2352f;
}

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

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.field.full {
  grid-column: 1 / -1;
}

label {
  color: #465560;
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5dc;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 11px;
  min-height: 42px;
}

textarea {
  resize: vertical;
  min-height: 84px;
}

select[multiple] {
  min-height: 96px;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.stack {
  display: grid;
  gap: 16px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.notice-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.notice-list li {
  border: 1px solid var(--line);
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

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

.fund-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.fund-row strong,
.fund-row span {
  display: block;
}

.fund-row span {
  color: var(--muted);
  margin-top: 2px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: start center;
  padding: 42px 18px;
  background: rgba(31, 41, 51, 0.42);
  z-index: 30;
  overflow: auto;
}

.modal-backdrop.hidden,
.hidden {
  display: none !important;
}

.modal {
  width: min(860px, 100%);
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(31, 41, 51, 0.28);
  border: 1px solid var(--line);
}

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

.receipt-success {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
  margin-bottom: 16px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 420px;
  border-radius: 8px;
  background: #1f2933;
  color: #ffffff;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  z-index: 50;
}

.loading-panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  color: var(--muted);
}

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

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  max-width: 260px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--ink);
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-panel {
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: 32px 18px;
  background: #edf2f4;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(520px, 100%);
}

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

.auth-brand small {
  color: var(--muted);
  margin-top: 2px;
}

body.app-mode .auth-panel {
  min-height: calc(100vh - 160px);
  padding: 0;
  background: transparent;
  place-items: center;
}

.auth-card {
  width: min(520px, 100%);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-card h2 {
  margin-bottom: 8px;
}

.auth-card p {
  line-height: 1.5;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.role-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.role-box strong {
  display: block;
  margin-bottom: 4px;
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .grid.four,
  .grid.three,
  .role-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .topbar-actions,
  .topbar-actions .primary-button {
    width: 100%;
  }

  .content {
    padding: 18px;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .form-grid,
  .form-grid.three,
  .role-grid {
    grid-template-columns: 1fr;
  }

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

  .form-actions {
    justify-content: stretch;
    flex-direction: column;
  }

  .form-actions button,
  .form-actions a {
    width: 100%;
  }
}
