:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #17202a;
  --muted: #687384;
  --line: #d8dde5;
  --accent: #1677ff;
  --accent-2: #0f9f8f;
  --warn: #c77700;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1f25;
    --surface-2: #232a32;
    --text: #eef2f6;
    --muted: #9aa6b4;
    --line: #343c46;
    --accent: #58a6ff;
    --accent-2: #36c4b2;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(22px + env(safe-area-inset-bottom));
}

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

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.icon-link,
button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 40px;
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stats div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stats span {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

.stats small {
  color: var(--muted);
  font-size: 12px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  margin-bottom: 10px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

#clear-search {
  min-height: 44px;
  font-size: 24px;
  color: var(--muted);
}

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

.tab {
  min-height: 38px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.table-head,
.entry-row {
  display: grid;
  grid-template-columns: 88px minmax(82px, 0.9fr) minmax(145px, 1.5fr) 58px;
  gap: 8px;
  align-items: center;
}

.table-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.rows {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-left: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.entry-row {
  width: 100%;
  padding: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.entry-row:last-child {
  border-bottom: 0;
}

.entry-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.entry-row .date {
  color: var(--muted);
  font-size: 13px;
}

.entry-row .amount {
  font-weight: 800;
  text-align: right;
}

.note {
  display: inline-flex;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
}

.document-list {
  display: grid;
  gap: 8px;
}

.danger-zone {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, #d43d3d 45%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, #d43d3d 10%, var(--surface));
}

.danger-zone strong,
.danger-zone span {
  display: block;
}

.danger-zone span {
  color: var(--muted);
  font-size: 13px;
}

.danger-zone button,
.danger-button,
.document-delete {
  border-color: color-mix(in srgb, #d43d3d 60%, var(--line));
  color: #ff6b6b;
}

.document-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.document-open,
.document-delete {
  min-height: 36px;
  padding: 0 10px;
}

.document-delete {
  font-weight: 800;
}

.document-item strong {
  display: block;
  margin-bottom: 3px;
}

.document-item span,
.empty {
  color: var(--muted);
}

.photo-panel {
  min-height: 260px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.photo-panel img {
  display: block;
  width: 100%;
  height: auto;
}

dialog {
  width: min(420px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.edit-form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

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

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.dialog-actions button {
  min-height: 42px;
}

#save-edit {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 800;
}

.confirm-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

@media (max-width: 430px) {
  .app-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  .table-head,
  .entry-row {
    grid-template-columns: 74px 76px minmax(120px, 1fr) 46px;
    gap: 6px;
  }

  .entry-row {
    padding: 10px 8px;
  }

  .danger-zone,
  .document-item {
    grid-template-columns: 1fr;
  }
}
