:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #6b7280;
  --line: #d8dee6;
  --primary: #176b5b;
  --primary-ink: #ffffff;
  --accent: #aa4f20;
  --danger: #b42318;
  --warn-bg: #fff4d6;
  --sidebar: #18212b;
  --sidebar-ink: #e9edf2;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 232px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 20px;
}

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

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background: #e2b84a;
  color: #18212b;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small,
.account small,
.page-header p,
.muted {
  color: var(--muted);
}

.sidebar .brand small,
.account small {
  color: #aeb8c4;
}

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

.nav a {
  color: var(--sidebar-ink);
  padding: 9px 10px;
  border-radius: 6px;
}

.nav a.active,
.nav a:hover {
  background: #263444;
  text-decoration: none;
}

.account {
  margin-top: auto;
  display: grid;
  gap: 7px;
}

.content {
  margin-left: 232px;
  padding: 24px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

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

h1 { font-size: 28px; }
h2 { font-size: 17px; margin-bottom: 12px; }
p { margin: 4px 0 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
}

.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)); }
.full-width { grid-column: 1 / -1; }

.metrics {
  display: grid;
  grid-template-columns: repeat(8, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 19px;
  overflow-wrap: anywhere;
}

.metric.warn { background: var(--warn-bg); }

.filters {
  display: grid;
  grid-template-columns: repeat(8, minmax(128px, 1fr));
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 5px;
  color: #344054;
  font-size: 12px;
  min-width: 0;
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #c8d0da;
  border-radius: 6px;
  padding: 8px 9px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

textarea { resize: vertical; }

.checks {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
}

.checks label,
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 7px;
}

.checks input,
.checkbox-line input {
  width: auto;
}

.filter-actions,
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid #c8d0da;
  border-radius: 6px;
  padding: 8px 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

button:hover,
.button:hover {
  text-decoration: none;
  border-color: #9aa7b5;
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.ghost {
  background: transparent;
  color: inherit;
}

.full { width: 100%; }

.table-wrap {
  width: 100%;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

.payments-table { min-width: 1780px; }
.audit-table { min-width: 1180px; }

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

th {
  position: sticky;
  top: 0;
  background: #eef2f6;
  color: #344054;
  font-size: 12px;
  z-index: 1;
}

td.num,
th.num {
  text-align: right;
  white-space: nowrap;
}

.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.comment { max-width: 280px; overflow-wrap: anywhere; color: #344054; }
.empty { text-align: center; color: var(--muted); padding: 22px; }

tr.negative td { background: #fff0ee; }
tr.cancelled td { color: #8a94a3; text-decoration: line-through; }

.status {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: 999px;
  background: #e7eef5;
  color: #344054;
  font-size: 12px;
}

.status.active { background: #e8f5ee; color: #176b5b; }
.status.edited { background: #fff4d6; color: #8a5a00; }
.status.cancelled { background: #f7d7d4; color: var(--danger); }

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.edit-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

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

.calc-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.calc-strip span {
  background: #f1f4f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
}

.calc-strip strong {
  display: block;
  margin-top: 3px;
}

.flash {
  border-radius: var(--radius);
  padding: 11px 13px;
  margin-bottom: 14px;
  background: #e8f5ee;
  border: 1px solid #b9ddca;
  color: #104b3f;
}

.flash.error {
  background: #fff0ee;
  border-color: #f4bbb5;
  color: var(--danger);
}

pre {
  max-width: 420px;
  max-height: 260px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(23, 107, 91, .15), transparent 36%),
    linear-gradient(315deg, rgba(170, 79, 32, .12), transparent 34%),
    var(--bg);
}

.login-panel {
  width: min(420px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 18px 50px rgba(24, 33, 43, .12);
}

.login-brand { margin-bottom: 4px; }

@media (max-width: 1280px) {
  .metrics { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
  .filters { grid-template-columns: repeat(4, minmax(128px, 1fr)); }
  .grid.three { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar {
    position: static;
    width: auto;
  }
  .content {
    margin-left: 0;
    padding: 16px;
  }
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid.two,
  .edit-grid {
    grid-template-columns: 1fr;
  }
  .metrics,
  .filters,
  .form-grid,
  .calc-strip {
    grid-template-columns: 1fr;
  }
  .page-header {
    display: grid;
  }
}
