:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --ink: #173b43;
  --muted: #6b7b80;
  --line: #d9e4e2;
  --brand: #16827b;
  --brand-dark: #0f6762;
  --soft: #eaf4f2;
  --warn: #b35b00;
  --shadow: 0 10px 28px rgba(20, 55, 58, 0.08);
  --shadow-soft: 0 4px 14px rgba(20, 55, 58, 0.06);
}

.ledger-badge {
  display: inline-flex;
  justify-self: start;
  align-items: center;
  max-width: 100%;
  margin-bottom: 8px;
  padding: 4px 10px;
  border-radius: 5px;
  background: var(--soft);
  color: var(--brand-dark);
  font-size: 13px;
  line-height: 1.4;
  font-weight: 800;
  letter-spacing: 0.06em;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--brand);
}

body[data-ledger-theme="blue"] {
  --bg: #f4f7fa;
  --ink: #2a4057;
  --muted: #687b8c;
  --line: #dce5ed;
  --brand: #527696;
  --brand-dark: #416484;
  --soft: #edf3f7;
  --shadow: 0 10px 28px rgba(47, 69, 91, 0.08);
  --shadow-soft: 0 4px 14px rgba(47, 69, 91, 0.05);
}

.audit-page { max-width: 1100px; margin: 0 auto; padding: 20px; }
.audit-heading { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.audit-page > * { margin-bottom: 18px; }
.audit-tabs { margin-bottom: 16px; }
.audit-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin: 16px 0; }
.audit-filters label { display: grid; gap: 6px; flex: 1 1 210px; min-width: 0; }
.audit-filters .actions { flex-wrap: wrap; }
.audit-list { display: grid; gap: 12px; margin: 16px 0; }
.audit-card { padding: 16px; border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; }
.audit-diff { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.7; }
.audit-overview { line-height: 1.8; }
.audit-technical { margin-top: 12px; padding: 10px 12px; border-radius: 6px; background: var(--soft); }
.audit-technical summary { cursor: pointer; color: var(--brand-dark); }
.audit-technical p { margin-bottom: 0; line-height: 1.7; }

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

body.modal-open {
  overflow: hidden;
}

body.read-only .edit-only {
  display: none !important;
}

body.read-only .layout {
  grid-template-columns: 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 24px;
}

p {
  margin: 6px 0 0;
}

.topbar p,
.hint {
  color: var(--muted);
  font-size: 14px;
}

.auth-status {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.actions,
.inline-grid,
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filters > * {
  min-width: 0;
}

.filter-field,
.filter-ponds {
  min-width: 150px;
  color: #42595f;
  font-size: 12px;
  font-weight: 800;
}

.filter-field input {
  margin-top: 4px;
}

.filter-ponds {
  display: grid;
  gap: 4px;
}

.compact-checks {
  gap: 6px;
  margin-top: 0;
}

.compact-checks label {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 600px) 1fr;
  gap: 18px;
  padding: 18px;
}

.left,
.right {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid #edf1f0;
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  padding: 14px;
}

.panel.accent {
  border-top: 3px solid var(--brand);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 35, 38, 0.34);
  backdrop-filter: blur(2px);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(244, 247, 246, 0.96);
}

.login-card {
  display: grid;
  gap: 12px;
  width: min(380px, 100%);
  padding: 22px;
  border: 1px solid #d8e6e3;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.loading-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(320px, 100%);
  padding: 22px 20px;
  border: 1px solid #d8e6e3;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  text-align: center;
}

.loading-card strong {
  color: var(--ink);
  font-size: 17px;
}

.loading-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid #d6e9e6;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.panel-title {
  margin-bottom: 12px;
  color: #08776f;
  font-size: 18px;
  font-weight: 700;
}

button,
.button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover,
.file-button:hover {
  background: var(--brand-dark);
}

.button.ghost,
.file-button {
  background: #eef6f5;
  color: var(--brand-dark);
  border: 1px solid #cfe3df;
}

.button.ghost:hover,
.file-button:hover {
  background: #dcefed;
}

.file-button input {
  display: none;
}

.hidden {
  display: none !important;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 50%;
  background: #eef6f5;
  color: var(--brand-dark);
  border: 1px solid #cfe3df;
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  background: #dcefed;
}

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

textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: block;
  color: #42595f;
  font-size: 14px;
  font-weight: 700;
}

label > input,
label > select {
  margin-top: 6px;
}

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

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

.checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #cfdad8;
  border-radius: 6px;
  background: #fff;
}

.checks input {
  width: auto;
  min-height: auto;
}

.warning {
  min-height: 20px;
  color: var(--warn);
  font-weight: 700;
}

.remark-photo-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.form-actions {
  display: grid;
  grid-template-columns: minmax(120px, 0.65fr) 1fr;
  gap: 10px;
}

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 35, 38, 0.42);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(760px, calc(100dvh - 36px));
  overflow: auto;
  box-shadow: var(--shadow);
}

.modal-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-title-row .panel-title {
  margin-bottom: 2px;
}

.draft-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.draft-list.empty {
  min-height: 54px;
  align-items: center;
  justify-content: center;
  color: #8a989c;
}

.draft-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdfd;
}

.draft-card strong {
  display: block;
  margin-bottom: 4px;
}

.draft-note {
  display: grid;
  gap: 6px;
}

.draft-note-main {
  display: block;
  color: #42595f;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.draft-note-raw {
  font-size: 12px;
  color: var(--muted);
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}

.metric {
  padding: 12px;
  border-radius: 6px;
  background: var(--soft);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric b {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
  background: #fff;
}

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

th {
  background: var(--soft);
  color: #056c66;
  font-weight: 800;
}

td.note {
  max-width: 280px;
  color: #52666b;
}

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

.entry-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.note-cell {
  display: grid;
  gap: 7px;
}

.note-main {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.note-image {
  color: var(--muted);
  font-size: 12px;
}

.note-raw {
  display: grid;
  gap: 5px;
  padding-top: 5px;
  border-top: 1px dashed #d6e2df;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.note-raw-title {
  color: #7b8b8f;
  font-weight: 800;
}

.note-short,
.note-full {
  overflow-wrap: anywhere;
}

.note-toggle {
  justify-self: start;
  min-height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

.danger {
  background: #fff0ec;
  color: #a33b1f;
  border: 1px solid #f2c6ba;
}

.danger:hover {
  background: #ffe4dc;
}

.secondary {
  background: #f7faf9;
  color: #42595f;
  border: 1px solid #cfdad8;
}

.secondary:hover {
  background: #edf4f2;
}

.full-width {
  width: 100%;
  margin-top: 10px;
}

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

.draft-card em {
  display: inline-flex;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e4f4eb;
  color: #25734a;
  font-style: normal;
  font-size: 12px;
}

.draft-card.posted {
  background: #f5faf7;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

@media (max-width: 900px) {
  .topbar,
  .dashboard {
    display: block;
  }

  .actions,
  .filters {
    margin-top: 12px;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 12px;
  }

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

  .form-grid,
  .filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    overflow: hidden;
  }

  .filter-field {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .filter-ponds {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .filters button {
    grid-column: auto;
  }

  .filters select,
  .filters input,
  .filters button {
    min-width: 0;
    max-width: 100%;
    padding-left: 8px;
    padding-right: 8px;
  }

  .panel {
    padding: 12px;
  }

  .panel-title {
    margin-bottom: 10px;
    font-size: 16px;
  }

  textarea,
  input,
  select,
  button,
  .button,
  .file-button {
    min-height: 38px;
    font-size: 14px;
  }

  label {
    font-size: 13px;
  }

  .metric {
    padding: 9px;
  }

  .metric span {
    font-size: 12px;
  }

  .metric b {
    font-size: 15px;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
  }

  td {
    border-bottom: 0;
    padding: 8px 10px;
    min-width: 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    min-width: 0;
    margin-bottom: 2px;
    color: #08776f;
    font-size: 12px;
    font-weight: 800;
  }

  td.note,
  td:last-child {
    grid-column: 1 / -1;
  }

  .draft-card {
    grid-template-columns: 1fr;
  }

  .draft-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal {
    align-items: end;
    padding: 8px;
  }

  .modal-panel {
    width: 100%;
    max-height: calc(100dvh - 16px);
    border-radius: 8px 8px 0 0;
  }

  .modal-title-row {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: -12px -12px 10px;
    padding: 12px;
    background: #fff;
    border-bottom: 1px solid var(--line);
  }

  .form-actions {
    position: sticky;
    bottom: -12px;
    grid-template-columns: 0.8fr 1.2fr;
    margin: 4px -12px -12px;
    padding: 10px 12px 12px;
    background: #fff;
    border-top: 1px solid var(--line);
  }
}

/* Each ledger inherits the shared layout and applies its own identity colors. */
body[data-ledger-theme="blue"] :is(.topbar, .audit-heading) {
  background: #e2ebf3;
  color: #324d68;
  border-color: #cfdde9;
}

body[data-ledger-theme="blue"] :is(.topbar, .audit-heading) :is(p, .hint, .auth-status) {
  color: #526b81;
}

body[data-ledger-theme="blue"] :is(.topbar, .audit-heading) .ledger-badge {
  background: #f4f8fb;
  color: #44627d;
}

body[data-ledger-theme="blue"] :is(.panel-title, th),
body[data-ledger-theme="blue"] td::before {
  color: #486780;
}

body[data-ledger-theme="blue"] :is(.button.ghost, .file-button, .icon-button, .secondary) {
  background: #f0f5f9;
  color: #496780;
  border-color: #d6e2ec;
}

body[data-ledger-theme="blue"] :is(.button.ghost, .file-button, .icon-button, .secondary):hover {
  background: #e3edf5;
}

body[data-ledger-theme="blue"] :is(.panel, .login-card, .loading-card, .checks label, input, select, textarea) {
  border-color: var(--line);
}

body[data-ledger-theme="blue"] .login-overlay {
  background: rgba(244, 247, 250, 0.97);
}

body[data-ledger-theme="blue"] .login-card {
  border-top: 5px solid var(--brand);
}

body[data-ledger-theme="blue"] .login-card h2 {
  color: #3e5e7b;
}

body[data-ledger-theme="blue"] .spinner {
  border-color: #dce6ef;
  border-top-color: var(--brand);
}

body[data-ledger-theme="blue"] :is(input, select, textarea, button, a):focus-visible {
  outline: 3px solid #95aec3;
  outline-offset: 2px;
}

body[data-ledger-theme="blue"] .checks label:has(input:checked) {
  background: var(--soft);
  border-color: #91abc1;
}
