:root {
  --bg: #f7f0e4;
  --panel: #fffaf2;
  --panel-strong: #fff4e0;
  --ink: #2c1a12;
  --muted: #7b6558;
  --line: #ead9c2;
  --primary: #8f241b;
  --primary-2: #b95d20;
  --accent: #c99a39;
  --ok: #28745b;
  --warn: #b7791f;
  --danger: #a82d2d;
  --shadow: 0 14px 45px rgba(72, 39, 19, 0.12);
}

* {
  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 {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: wait;
  opacity: 0.68;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(201, 154, 57, 0.75);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(140deg, rgba(44, 26, 18, 0.88), rgba(143, 36, 27, 0.54)),
    radial-gradient(circle at 25% 20%, rgba(201, 154, 57, 0.42), transparent 32%),
    linear-gradient(45deg, #2c1a12, #8f241b);
}

.login-card {
  width: min(440px, 100%);
  background: rgba(255, 250, 242, 0.96);
  border: 1px solid rgba(234, 217, 194, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-card h1 {
  margin: 6px 0 8px;
  font-size: 34px;
}

.stack {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdfa;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(185, 93, 32, 0.14);
}

.primary,
.secondary,
.ghost,
.danger,
.icon-button {
  border-radius: 7px;
  min-height: 38px;
  padding: 9px 13px;
  font-weight: 800;
}

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

.secondary {
  background: #efe0ca;
  color: var(--ink);
}

.ghost {
  background: transparent;
  color: var(--primary);
}

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

.icon-button {
  width: 40px;
  background: #efe0ca;
  color: var(--ink);
}

.demo-users {
  display: grid;
  gap: 6px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 13px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: #2c1a12;
  color: #fff6eb;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #2c1a12;
  font-weight: 900;
}

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

.brand small {
  display: block;
  color: #dcc8ad;
}

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

.nav-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 7px;
  background: transparent;
  color: #f6e8d6;
  text-align: left;
}

.nav-button.active,
.nav-button:hover {
  background: rgba(255, 246, 235, 0.12);
}

.workspace {
  min-width: 0;
}

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

.topbar h2,
.section-title h3,
.card h3 {
  margin: 0;
}

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

.session-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.content {
  padding: 24px 26px 36px;
}

.notice {
  margin: 18px 26px 0;
  padding: 12px 14px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.notice.info {
  border-color: rgba(185, 93, 32, 0.35);
}

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

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

.two-col {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

.card,
.table-card,
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(72, 39, 19, 0.06);
}

.card {
  padding: 18px;
}

.kpi {
  display: grid;
  gap: 8px;
}

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

.kpi strong {
  font-size: 26px;
}

.section-title,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar {
  margin-bottom: 14px;
}

.toolbar .filters {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

.table-card {
  overflow: hidden;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #fff4e0;
}

tr:last-child td {
  border-bottom: 0;
}

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

.form-actions,
.quick-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-actions {
  justify-content: space-between;
  margin-top: 16px;
}

.quick-actions > div {
  margin-right: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #efe0ca;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.badge.ok {
  background: rgba(40, 116, 91, 0.13);
  color: var(--ok);
}

.badge.warn {
  background: rgba(183, 121, 31, 0.14);
  color: var(--warn);
}

.badge.danger {
  background: rgba(168, 45, 45, 0.13);
  color: var(--danger);
}

.mini-chart {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 110px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  background: #ead9c2;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-2), var(--accent));
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.tab {
  white-space: nowrap;
}

.tab.active {
  background: var(--primary);
  color: white;
}

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

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

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(44, 26, 18, 0.48);
}

.modal {
  width: min(1040px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

#income-form .table-card {
  width: 100%;
}

#income-form table {
  min-width: 0;
}

#income-form th:first-child,
#income-form td:first-child {
  width: 42%;
}

#income-form input[data-income-payment="true"] {
  width: 100%;
}

.error-message {
  min-height: 18px;
  color: var(--danger);
  font-weight: 800;
}

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

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

  .sidebar {
    position: fixed;
    z-index: 10;
    width: 276px;
    transform: translateX(-100%);
    transition: transform 160ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .kpi-grid,
  .two-col {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    padding: 14px;
  }

  .content {
    padding: 16px 14px 28px;
  }

  .modal-root {
    padding: 10px;
  }

  .modal {
    width: 100%;
    padding: 16px;
  }

  .kpi-grid,
  .two-col,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .session-pill {
    max-width: 180px;
  }

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

  .quick-actions,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

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