:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #16202a;
  --muted: #5d6b78;
  --line: #dde3e9;
  --accent: #0b6e8a;
  --accent-text: #ffffff;
  --positive: #1a7f37;
  --negative: #cf222e;
  --danger-bg: #ffebe9;
  --tab-height: 3.6rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --card: #182028;
    --text: #e8eef3;
    --muted: #93a1ad;
    --line: #2a3541;
    --accent: #3aa6c4;
    --accent-text: #08151b;
    --positive: #3fb950;
    --negative: #ff7b72;
    --danger-bg: #3a1d1d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 34rem;
  margin: 0 auto;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem
    calc(var(--tab-height) + env(safe-area-inset-bottom) + 1.5rem);
}

h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; }
.subtitle { color: var(--muted); margin: 0 0 1rem; }
.muted { color: var(--muted); }
.positive { color: var(--positive); }
.negative { color: var(--negative); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 0.9rem 1rem;
}

.reminder { border-color: var(--accent); margin-bottom: 1rem; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.stat span { display: block; color: var(--muted); font-size: 0.85rem; }
.stat strong { display: block; font-size: 1.3rem; margin-top: 0.15rem; overflow-wrap: anywhere; }

.price-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.price-form { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.price-form input { flex: 1; min-width: 0; }

label { display: block; margin: 0.9rem 0 0.25rem; color: var(--muted); font-size: 0.9rem; }
input, button, .button {
  font: inherit;
  font-size: 1rem; /* 16px keeps iOS from zooming into focused fields */
  border-radius: 0.7rem;
}
input[type="text"], input[type="number"], input[type="date"] {
  width: 100%;
  min-height: 2.9rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}
button, .button {
  display: inline-block;
  min-height: 2.9rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; border-color: var(--negative); color: var(--negative); }
button.small { min-height: 2.2rem; padding: 0.3rem 0.8rem; }
button.full { width: 100%; margin-top: 1.25rem; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 0.7rem;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: var(--card);
  color: var(--text);
  font-weight: 600;
}
.segmented input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.error { background: var(--danger-bg); color: var(--negative); padding: 0.6rem 0.8rem; border-radius: 0.7rem; margin: 0.9rem 0 0; }

.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.entry {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  color: inherit;
  text-decoration: none;
}
.entry .right { text-align: right; }
.badge { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; }
.badge.buy { color: var(--positive); }
.badge.sell { color: var(--negative); }

details summary { cursor: pointer; font-weight: 600; padding: 0.25rem 0; }
.table-scroll { overflow-x: auto; margin-top: 0.5rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; white-space: nowrap; }
th, td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); text-align: right; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }
td small { display: block; color: var(--muted); }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
.file-input { display: none; }

.banner {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem;
  background: var(--danger-bg);
  color: var(--negative);
  text-align: center;
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  min-height: var(--tab-height);
  color: var(--muted);
  font-size: 0.75rem;
  text-decoration: none;
}
.tabs a.active { color: var(--accent); font-weight: 600; }
.tabs svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
