:root {
  --bg: #f4f4f0;
  --panel: #ffffff;
  --ink: #0a0a0a;
  --ink-soft: #6b6b66;
  --line: #0a0a0a;
  --border-w: 2px;
  --shadow: 3px 3px 0 var(--ink);
  --shadow-lg: 4px 4px 0 var(--ink);
  --shadow-sm: 2px 2px 0 var(--ink);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select { font-family: inherit; }

/* ---------- icons ---------- */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 28px; height: 28px; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 14px;
  background: var(--panel);
  border-bottom: var(--border-w) solid var(--line);
}
.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.muted {
  color: var(--ink-soft);
  font-size: 11px;
  font-family: "SF Mono", "Menlo", monospace;
  display: block;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  color: var(--ink);
  border: var(--border-w) solid var(--ink);
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  box-shadow: var(--shadow-sm);
  font-family: "SF Mono", "Menlo", monospace;
}
.badge .icon { width: 13px; height: 13px; }
.badge.ok { background: var(--panel); }
.badge.err { background: var(--ink); color: var(--panel); }

/* ---------- main ---------- */
main {
  padding: 16px 16px calc(110px + var(--safe-bottom));
  max-width: 760px;
  margin: 0 auto;
}
.panel { display: none; }
.panel.active { display: block; animation: fadein 0.18s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink);
  margin: 24px 0 10px;
  font-weight: 900;
  border-bottom: var(--border-w) solid var(--ink);
  padding-bottom: 8px;
}
h2 .icon { width: 16px; height: 16px; }
h2:first-child { margin-top: 4px; }

/* ---------- cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
.card {
  background: var(--panel);
  padding: 14px 14px;
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow-lg);
}
.card.wide { grid-column: 1 / -1; }
.card-label {
  font-size: 9px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
}
.card-value {
  font-size: 22px;
  font-weight: 900;
  margin-top: 6px;
  letter-spacing: -0.02em;
}

/* ---------- forms ---------- */
.form {
  display: grid;
  gap: 12px;
  background: var(--panel);
  padding: 16px;
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow-lg);
  margin-bottom: 4px;
}
.form input,
.form select {
  width: 100%;
  padding: 12px 14px;
  background: var(--panel);
  border: var(--border-w) solid var(--ink);
  color: var(--ink);
  border-radius: 0;
  font-size: 16px; /* prevents iOS auto-zoom */
  font-weight: 500;
  min-height: 44px;
  transition: box-shadow 0.1s;
  appearance: none;
  -webkit-appearance: none;
}
.form select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.form input:focus,
.form select:focus {
  outline: none;
  box-shadow: var(--shadow);
}
.form input[type="file"] {
  padding: 10px;
  font-size: 13px;
}
.form input[type="file"]::file-selector-button {
  background: var(--ink);
  color: var(--panel);
  border: none;
  padding: 8px 12px;
  font-weight: 800;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 12px;
  cursor: pointer;
  font-family: inherit;
}
.form label {
  display: flex;
  flex-direction: column;
  font-size: 10px;
  color: var(--ink);
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
}
.form fieldset {
  border: var(--border-w) solid var(--ink);
  padding: 14px;
  margin: 0;
}
.form fieldset legend {
  font-size: 10px;
  color: var(--ink);
  padding: 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  background: var(--panel);
}
.checks { display: flex; flex-wrap: wrap; gap: 10px; }
.checks label {
  flex-direction: row;
  align-items: center;
  font-size: 14px;
  color: var(--ink);
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 700;
  padding: 8px 12px;
  border: var(--border-w) solid var(--ink);
  cursor: pointer;
  user-select: none;
  background: var(--panel);
  min-height: 40px;
}
.checks label:has(input:checked) {
  background: var(--ink);
  color: var(--panel);
}
.checks input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--ink);
  margin: 0;
  pointer-events: none;
}

.form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--ink);
  color: var(--panel);
  border: var(--border-w) solid var(--ink);
  padding: 14px;
  border-radius: 0;
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.06s, box-shadow 0.06s;
  min-height: 48px;
}
.form button .icon { color: var(--panel); }
.form button:hover { background: #1a1a1a; }
.form button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

/* ---------- list rows ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  padding: 12px 14px;
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow);
  gap: 12px;
}
.row .left {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.row .text { flex: 1; min-width: 0; }
.row .title {
  font-weight: 800;
  font-size: 14px;
  word-wrap: break-word;
}
.row .sub {
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 3px;
  font-family: "SF Mono", "Menlo", monospace;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.row .sub .icon { width: 12px; height: 12px; }
.row .right {
  text-align: right;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.row .amt {
  font-weight: 900;
  font-size: 16px;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.row .amt .icon { width: 12px; height: 12px; }
.row a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 1px;
}
.row .actions { display: flex; gap: 6px; }
.row .iconbtn {
  background: var(--panel);
  border: var(--border-w) solid var(--ink);
  color: var(--ink);
  padding: 6px;
  border-radius: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  transition: all 0.06s;
}
.row .iconbtn:hover, .row .iconbtn:active {
  background: var(--ink);
  color: var(--panel);
}

/* ---------- avatar ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: var(--border-w) solid var(--ink);
  background: var(--panel);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.avatar.sm {
  width: 22px;
  height: 22px;
  font-size: 9px;
  border-width: 1.5px;
}
.avatar.filled {
  background: var(--ink);
  color: var(--panel);
}

/* ---------- empty state ---------- */
.empty {
  color: var(--ink-soft);
  font-size: 12px;
  padding: 28px 16px;
  border: 2px dashed var(--ink);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.empty .icon { width: 32px; height: 32px; opacity: 0.5; }

/* ---------- bottom nav ---------- */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: var(--panel);
  border-top: var(--border-w) solid var(--ink);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -2px 0 0 transparent;
}
.navbtn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: transparent;
  border: none;
  border-right: var(--border-w) solid var(--ink);
  color: var(--ink-soft);
  padding: 10px 4px 10px;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  min-height: 60px;
}
.navbtn:last-child { border-right: none; }
.navbtn .icon { width: 22px; height: 22px; }
.navbtn.active {
  background: var(--ink);
  color: var(--panel);
}
.navbtn:active { background: #e8e8e3; }
.navbtn.active:active { background: #1a1a1a; }

@media (min-width: 640px) {
  .cards { grid-template-columns: repeat(4, 1fr); }
  main { padding-bottom: calc(120px + var(--safe-bottom)); }
}
