:root {
  color-scheme: light;
  --bg: #eef2ef;
  --panel: #ffffff;
  --panel-alt: #f8faf9;
  --line: #cfd8d2;
  --line-strong: #9cafaa;
  --text: #17201c;
  --muted: #5d6d66;
  --accent: #1f6f62;
  --accent-strong: #154f48;
  --warn: #8f5a18;
  --total: #edf7ff;
  --history-pane-width: minmax(460px, 1.1fr);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

.menu-view,
.entry-view,
.login-view {
  height: 100vh;
  overflow: auto;
  background: var(--panel);
}

.entry-view {
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.login-view {
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login-panel {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  display: grid;
  gap: 16px;
}

.security-panel {
  width: min(620px, calc(100vw - 32px));
}

.qr-panel {
  min-height: 226px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-alt);
}

.qr-image {
  width: 208px;
  height: 208px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.qr-fallback {
  padding: 20px;
  color: var(--warn);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.app-header {
  min-height: 92px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  align-content: center;
  gap: 8px;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.user-bar button {
  height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent-strong);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.app-header.compact {
  min-height: 78px;
}

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

.back-link {
  color: var(--accent);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.compact-link {
  display: inline-block;
  margin-bottom: 5px;
  font-size: 14px;
}

.menu-grid {
  max-width: 980px;
  padding: 28px 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 16px;
}

.menu-card {
  min-height: 138px;
  padding: 20px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: var(--panel-alt);
  color: var(--text);
  text-decoration: none;
  display: grid;
  align-content: start;
  gap: 10px;
}

.menu-card:hover {
  border-color: var(--accent);
  background: #edf7f3;
}

.menu-card-title {
  font-size: 20px;
  font-weight: 800;
}

.menu-card-text {
  color: var(--muted);
  line-height: 1.42;
}

.entry-layout {
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(420px, 760px);
  gap: 16px;
}

.entry-data-shell {
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(740px, 1fr);
  gap: 0;
  background: var(--line);
}

.entry-member-pane {
  border-right: 1px solid var(--line);
}

.entry-history-pane {
  min-width: 0;
}

.entry-table-form {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
}

.entry-new-row td {
  background: #eef8f4;
  border-top: 2px solid var(--accent);
}

.entry-new-row input {
  width: 100%;
  min-width: 0;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 6px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  background: var(--panel);
}

.entry-new-row input:focus {
  outline: 2px solid rgba(31, 111, 98, 0.22);
  border-color: var(--accent);
}

.entry-save-bar {
  min-height: 54px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-alt);
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.member-add-button {
  margin: 10px 14px 0;
}

.new-member-form {
  margin: 10px 14px 0;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.checkbox-field {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.admin-layout {
  max-width: 1200px;
  padding: 22px 24px 28px;
  display: grid;
  gap: 24px;
}

.entry-panel,
.placeholder-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-alt);
}

.placeholder-panel {
  max-width: 760px;
  margin: 28px 24px;
}

.entry-panel h2,
.placeholder-panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.admin-section {
  min-width: 0;
}

.section-heading {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
}

.admin-maintenance {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 18px;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.invite-user-form {
  margin-top: 14px;
  padding: 14px 0 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
}

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

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

.entry-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.entry-field input {
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  font: inherit;
  background: var(--panel);
}

.entry-field select {
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  font: inherit;
  background: var(--panel);
}

.entry-field input:disabled,
.entry-field input[readonly],
.primary-action:disabled {
  opacity: 0.62;
}

.pending-note {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

.primary-action {
  margin-top: 16px;
  height: 38px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 800;
}

.compact-action {
  margin-top: 0;
  padding: 0 14px;
}

.admin-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.secondary-action,
.danger-action {
  min-height: 38px;
  border-radius: 6px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.secondary-action {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--accent-strong);
}

.danger-action {
  border: 1px solid #8f1d18;
  background: #8f1d18;
  color: white;
}

.form-error {
  min-height: 18px;
  color: #8f1d18;
  font-size: 13px;
  font-weight: 700;
}

.form-status {
  min-height: 18px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-link {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.form-link:hover {
  text-decoration: underline;
}

.admin-list {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  overflow: auto;
}

.admin-users-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: auto;
}

.admin-users-table th,
.admin-users-table td {
  padding: 11px 12px;
  border-right: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  overflow-wrap: normal;
  white-space: nowrap;
}

.admin-users-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  border-bottom: 2px solid var(--line-strong);
}

.admin-user-name {
  font-weight: 800;
}

.table-action {
  min-height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent-strong);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.table-action:hover {
  border-color: var(--accent);
  background: #edf7f3;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.role-badge {
  padding: 4px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 320px var(--history-pane-width) 7px minmax(380px, 0.9fr);
  gap: 0;
  background: var(--line);
}

.member-pane,
.history-pane,
.pdf-pane {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.member-pane {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
}

.member-pane.entry-member-pane {
  grid-template-rows: auto auto auto auto auto 1fr;
}

.pane-header,
.detail-header,
.pdf-header {
  min-height: 64px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}

.count,
.member-meta,
.source-meta,
.member-row-meta {
  color: var(--muted);
  font-size: 12px;
}

.search-box {
  display: grid;
  gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.search-box input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 11px;
  font: inherit;
  color: var(--text);
  background: var(--panel);
}

.search-box input:focus {
  outline: 2px solid rgba(31, 111, 98, 0.22);
  border-color: var(--accent);
}

.member-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
}

.member-nav button {
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent-strong);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.member-nav button:hover:not(:disabled) {
  border-color: var(--accent);
  background: #edf7f3;
}

.member-nav button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.55;
}

.member-list {
  overflow: auto;
}

.member-row {
  width: 100%;
  min-height: 54px;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  gap: 4px;
  text-align: left;
  cursor: pointer;
}

.member-row:hover {
  background: var(--panel-alt);
}

.member-row.selected {
  background: #e6f1ed;
  border-left: 4px solid var(--accent);
  padding-left: 12px;
}

.member-row-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-list,
.empty-cell {
  padding: 24px;
  color: var(--muted);
}

.history-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.pane-resizer {
  min-width: 7px;
  background: var(--line);
  cursor: col-resize;
  position: relative;
  z-index: 3;
  touch-action: none;
}

.pane-resizer::before {
  content: "";
  position: absolute;
  inset: 0 2px;
  background: transparent;
}

.pane-resizer:hover::before,
.pane-resizer:focus-visible::before,
.resizing-panes .pane-resizer::before {
  background: var(--accent);
}

.pane-resizer:focus-visible {
  outline: 2px solid rgba(31, 111, 98, 0.35);
  outline-offset: -2px;
}

.resizing-panes {
  cursor: col-resize;
  user-select: none;
}

.resizing-panes iframe {
  pointer-events: none;
}

.member-name {
  font-size: 19px;
  font-weight: 800;
}

.source-meta {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.table-wrap {
  overflow: auto;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 7px 8px;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e9eee9;
  color: #23312c;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
}

th:nth-child(1),
td:nth-child(1) {
  width: 82px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 180px;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5) {
  width: 124px;
}

th:nth-child(8),
td:nth-child(8) {
  width: 96px;
}

th:nth-child(9),
td:nth-child(9),
th:nth-child(10),
td:nth-child(10),
th:nth-child(11),
td:nth-child(11),
th:nth-child(12),
td:nth-child(12) {
  width: 104px;
  text-align: right;
}

.year-row td {
  background: #dfe8e2;
  color: var(--accent-strong);
  font-weight: 800;
  text-align: left;
}

.calculated-total td {
  background: #d9edf8;
  color: #123f5a;
  font-weight: 800;
  border-top: 2px solid #6fa9c9;
  border-bottom: 2px solid #6fa9c9;
}

.calculated-total td:nth-child(2) {
  text-align: left;
}

.source-total td {
  background: #fff5d6;
  color: #68430d;
  font-style: italic;
}

.source-total td:nth-child(2) {
  font-weight: 800;
}

.web-entry-row td {
  background: #f5fbf7;
}

.pdf-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.pdf-header {
  font-weight: 800;
}

.pdf-header a {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}

.pdf-header a:hover {
  text-decoration: underline;
}

iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #f1f1f1;
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 280px minmax(560px, 1fr);
    grid-template-rows: minmax(520px, 62vh) minmax(520px, 70vh);
  }

  .pane-resizer {
    display: none;
  }

  .pdf-pane {
    grid-column: 1 / -1;
  }

  .menu-grid,
  .entry-layout,
  .entry-data-shell,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .entry-view {
    display: block;
    overflow: auto;
  }

  .entry-data-shell {
    height: auto;
    min-height: calc(100vh - 78px);
    grid-template-rows: 360px minmax(520px, 1fr);
  }
}
