:root {
  --ink: #172026;
  --muted: #63737f;
  --line: #d8e0e5;
  --surface: #ffffff;
  --page: #f4f7f4;
  --nav: #102c30;
  --brand: #0f766e;
  --brand-strong: #0b5f59;
  --accent: #e8872f;
  --danger: #b42318;
  --success: #157f3b;
  --shadow: rgba(30, 43, 50, 0.08);
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--brand-strong);
  font-weight: 800;
  text-decoration: none;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

.sidebar {
  background: var(--nav);
  color: #eaf3f1;
  padding: 18px;
}

.app-logo {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
  align-items: center;
  color: #fff;
  margin-bottom: 24px;
}

.app-logo span,
.auth-brand span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.app-logo em {
  grid-column: 2;
  color: #b7c8c7;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  margin-top: -9px;
}

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

.side-nav a {
  border-radius: 8px;
  color: #c8d7d5;
  padding: 11px 12px;
}

.side-nav a.active,
.side-nav a:hover {
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
}

.main-shell {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 86px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 18px 28px;
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
}

.content {
  display: grid;
  gap: 20px;
  padding: 28px;
}

.page-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.filters {
  display: flex;
  width: min(620px, 100%);
  gap: 10px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 16px;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 20px;
}

.metric-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px var(--shadow);
}

.metric-card {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.metric-card span,
.detail-list dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

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

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

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

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

.metric-card .metric-date {
  font-size: 20px;
}

.panel {
  padding: 20px;
}

.panel.narrow {
  max-width: 840px;
}

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

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.table-actions {
  width: 1%;
  white-space: nowrap;
}

.table-action-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.table-action-buttons form {
  margin: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #eef3f2;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
}

.badge.income,
.badge.paid,
.badge.posted {
  background: #e7f6ee;
  color: var(--success);
}

.badge.expense,
.badge.unpaid {
  background: #fff0ec;
  color: var(--danger);
}

.badge.partial {
  background: #fff7e8;
  color: #9a5a00;
}

.badge.pending {
  background: #fff7e8;
  color: #9a5a00;
}

.money-in {
  color: var(--success);
  font-weight: 900;
}

.money-out {
  color: var(--danger);
  font-weight: 900;
}

.empty-state {
  color: var(--muted);
  margin: 0;
}

.data-form {
  display: grid;
  gap: 18px;
}

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

.data-form label,
.form-grid label {
  display: grid;
  gap: 7px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.check-row {
  display: flex !important;
  align-items: center;
  align-self: end;
  min-height: 44px;
  gap: 9px !important;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.line-items {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfc;
}

.line-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.line-items-header h3 {
  margin-bottom: 0;
}

.cash-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 12px;
}

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

.permission-group {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 14px;
}

.permission-group legend {
  color: var(--ink);
  font-weight: 900;
  padding: 0 6px;
}

.permission-option {
  display: grid !important;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 10px !important;
  color: var(--ink);
}

.permission-option input {
  width: 18px;
  min-height: 18px;
  margin-top: 3px;
}

.permission-option small {
  display: block;
  color: var(--muted);
  font-weight: 700;
  margin-top: 2px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 900;
}

.button.primary {
  background: var(--brand);
  color: #fff;
}

.button.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.button.danger {
  background: #fff0ec;
  border-color: #ffc9c0;
  color: var(--danger);
}

.flash {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px 14px;
  font-weight: 800;
}

.flash.success {
  border-color: #bce4cb;
  color: var(--success);
}

.flash.error {
  border-color: #ffc9c0;
  color: var(--danger);
}

.flash.warning {
  border-color: #f7d99c;
  color: #8a5a00;
}

.detail-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
}

.detail-list dd {
  margin: 0;
  font-weight: 800;
}

.audit-json {
  max-width: 520px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  padding: 10px;
  white-space: pre-wrap;
}

.icon-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 4px auto;
  background: var(--ink);
}

.auth-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  background: linear-gradient(135deg, #0f766e 0%, #223235 56%, #e8872f 100%);
  padding: 22px;
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1.15fr);
  width: min(960px, 100%);
  min-height: 520px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.22);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(16, 44, 48, 0.72);
  color: #fff;
  padding: 40px;
}

.auth-brand h1 {
  font-size: 42px;
}

.auth-brand p {
  margin-bottom: 0;
  color: #f3d7bd;
  font-size: 18px;
  font-weight: 800;
}

.auth-panel {
  display: grid;
  align-content: center;
  background: #fff;
  padding: 40px;
}

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

  .sidebar {
    display: none;
  }

  body.nav-open .sidebar {
    display: block;
  }

  .icon-button {
    display: block;
  }

  .topbar,
  .page-actions,
  .filters,
  .user-menu {
    align-items: stretch;
    flex-direction: column;
  }

  .content {
    padding: 16px;
  }

  .status-grid,
  .panel-grid,
  .form-grid,
  .cash-grid,
  .permission-grid,
  .auth-card {
    grid-template-columns: 1fr;
  }

  .auth-card {
    min-height: auto;
  }
}
