:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eff3f2;
  --ink: #17211d;
  --muted: #69736f;
  --line: #d8dedb;
  --accent: #087f6f;
  --accent-dark: #065f54;
  --accent-soft: #dcefeb;
  --warning: #a95512;
  --danger: #b3261e;
  --shadow: 0 16px 40px rgba(23, 33, 29, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.shell {
  width: min(1380px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
}

.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 24px; }
.login-screen .auth-panel { width: min(440px, 100%); min-width: 0; padding: 32px; }
.login-screen .auth-form { min-width: 0; }
.login-screen .form-row { display: flex; flex-wrap: wrap; gap: 10px; min-width: 0; }
.login-screen .form-row button { max-width: 100%; white-space: normal; }
.login-screen .auth-form { grid-template-columns: 1fr; gap: 20px; }
.login-logo { display: block; width: min(220px, 100%); height: auto; aspect-ratio: 1; object-fit: contain; margin: 0 auto 16px; }
.sidebar-logo { display: block; width: min(144px, 100%); height: auto; aspect-ratio: 1; object-fit: contain; margin: 0 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.login-screen h1 { font-size: 25px; line-height: 1.25; }
#loginStatus { color: var(--muted); line-height: 1.5; }
.sidebar { border-right: 1px solid var(--line); background: white; padding: 24px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; font-size: 15px; }
.brand svg { width: 22px; height: 22px; color: var(--accent); flex-shrink: 0; }
.sidebar nav button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 6px; background: transparent; text-align: left; font-size: 14px; color: var(--muted); }
.sidebar nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar nav button:hover { background: #f1f4f6; }
.sidebar nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }
.nav-divider { border-top: 1px solid var(--line); margin: 16px 8px; }
.workspace { min-width: 0; padding: 28px; }
.household-picker { max-width: 320px; margin-bottom: 24px; }
.module-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; }
.module-tile { display: flex; align-items: center; gap: 14px; min-height: 92px; padding: 18px; text-align: left; background: white; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); font-size: 15px; font-weight: 700; }
.module-tile:hover { border-color: var(--accent); }
.module-tile svg { width: 24px; height: 24px; flex-shrink: 0; color: var(--accent); }
.module-tile:nth-child(3n+2) svg { color: #a04466; }
.module-tile:nth-child(3n) svg { color: #3275a5; }
.profile-form { max-width: 560px; display: grid; gap: 20px; }
#catalogForm { margin: 20px 0; }
#catalogForm input[type="checkbox"] { width: 20px; height: 20px; min-height: 20px; padding: 0; accent-color: var(--accent); }
.view-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.view-tabs button { display: inline-flex; gap: 8px; align-items: center; padding: 12px 8px; color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent; }
.view-tabs button[aria-selected="true"] { color: var(--accent-dark); border-bottom-color: var(--accent); }
.view-tabs svg { width: 18px; height: 18px; }
.table-scroll { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; background: white; }
th,td { padding: 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
th { font-size: 12px; color: var(--muted); background: #edf1f4; }
td select { min-width: 135px; font-size: 13px; }
.allow-user-form { display: grid; grid-template-columns: minmax(0,1fr) 170px auto; align-items: end; gap: 12px; margin-bottom: 24px; }
.user-search { max-width: 360px; }
.empty-state { padding: 24px 0; color: var(--muted); }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(1.8rem, 2rem, 2.2rem);
  line-height: 1.1;
}

h2 {
  font-size: 1.05rem;
}

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

.icon-button,
.primary-button,
.secondary-button,
.capture-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.icon-button {
  width: 44px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.icon-button svg,
.primary-button svg,
.secondary-button svg,
.capture-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

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

.auth-panel {
  padding: 16px;
  margin-bottom: 16px;
}

.auth-panel.hidden {
  display: none;
}

.auth-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.movement-form {
  display: grid;
  gap: 18px;
  padding: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  min-height: 40px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--accent-dark);
  box-shadow: 0 1px 2px rgba(23, 33, 29, 0.08);
}

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

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

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

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 127, 111, 0.16);
}

.amount-field input {
  font-size: 1.4rem;
  font-weight: 800;
}

.full-width {
  width: 100%;
}

.quick-capture {
  flex-wrap: wrap;
}

.capture-button {
  flex: 1 1 120px;
  background: var(--accent-soft);
  border-color: #b9dcd5;
  color: var(--accent-dark);
  font-weight: 800;
}

.primary-button,
.secondary-button {
  padding: 0 14px;
  font-weight: 800;
}

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

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

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

.footer-actions {
  justify-content: flex-end;
}

.recent {
  margin-top: 16px;
  padding: 16px 0;
}

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

#recentCount {
  min-width: 28px;
  min-height: 28px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
}

#recentList {
  list-style: none;
  padding: 0;
  margin: 0;
}

.recent-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.recent-item:last-child {
  border-bottom: 0;
}

.recent-title {
  color: var(--ink);
  font-weight: 800;
}

.recent-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.85rem;
}

.recent-amount {
  text-align: right;
  font-weight: 900;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(120px);
  max-width: min(480px, calc(100vw - 32px));
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 160ms ease, opacity 160ms ease;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error {
  background: var(--danger);
}

.toast.warning {
  background: var(--warning);
}

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

  .sidebar { padding: 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; overflow-x: auto; gap: 4px; }
  .sidebar nav button { width: auto; white-space: nowrap; }
  #moduleNav { display: flex; }
  .nav-divider { display: none; }
  .brand { padding-bottom: 12px; }
  .workspace { padding: 20px 16px; }
  .module-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .module-tile { flex-direction: column; align-items: flex-start; gap: 10px; min-height: 116px; font-size: 14px; }
  .allow-user-form { grid-template-columns: 1fr; }

  .topbar {
    align-items: flex-start;
  }

  .auth-form,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .footer-actions {
    justify-content: stretch;
  }

  .footer-actions button {
    flex: 1;
  }
}
