:root {
  --bg: #050505;
  --bar: #0c0c0c;
  --surface: #161616;
  --border: #252525;
  --text: #f0f0f0;
  --muted: #6a6a6a;
  --green: #1db954;
  --green-dim: rgba(29, 185, 84, 0.2);
  --red: #e74c3c;
  --red-dim: rgba(231, 76, 60, 0.2);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --radius: 12px;
  --app-h: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  background: #000;
}

body {
  height: 100%;
  margin: 0;
  background: #000;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* Stały shell = brak „zjeżdżania” viewportu na iOS */
.shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: var(--app-h);
  max-width: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.appbar {
  flex-shrink: 0;
  padding: calc(8px + var(--safe-t)) 12px 10px;
  background: var(--bar);
  border-bottom: 1px solid var(--border);
}

.appbar-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.brand {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  min-width: 36px;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.month-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-transform: lowercase;
  padding: 8px 4px;
  cursor: pointer;
  white-space: nowrap;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 10px;
  display: grid;
  place-items: center;
}

.icon-btn:active {
  background: var(--surface);
}

.today-btn {
  font-size: 0.78rem;
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text);
  border: 1.5px solid #444;
  border-radius: 10px;
  width: 34px;
  height: 34px;
}

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

.stat {
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.stat-k {
  font-size: 0.62rem;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.1em;
}

.stat-v {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-v.pos { color: var(--green); }
.stat-v.neg { color: var(--red); }
.stat-v.zero { color: var(--muted); }

.dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr) minmax(40px, 0.7fr);
  gap: 4px;
  padding: 8px 10px 4px;
  flex-shrink: 0;
  background: var(--bg);
}

.dow span {
  text-align: center;
  font-size: 0.62rem;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dow-sum { color: #3a3a3a !important; }

.cal {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 10px calc(10px + var(--safe-b));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  touch-action: pan-y;
}

.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr) minmax(40px, 0.7fr);
  gap: 4px;
  flex: 1 1 0;
  min-height: 56px;
}

.day {
  border: none;
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  padding: 6px 4px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  color: inherit;
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.day:active:not(.empty) {
  opacity: 0.85;
}

.day.empty {
  background: transparent;
  pointer-events: none;
  visibility: hidden;
}

.day.today:not(.empty) {
  box-shadow: inset 0 0 0 1.5px #555;
}

.day.pos { background: var(--green-dim); }
.day.neg { background: var(--red-dim); }

.day-n {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 500;
  text-align: left;
}

.day.pos .day-n,
.day.neg .day-n {
  color: rgba(255, 255, 255, 0.45);
}

.day-v {
  font-family: var(--mono);
  font-size: clamp(0.55rem, 2.5vw, 0.72rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.day.pos .day-v { color: var(--green); }
.day.neg .day-v { color: var(--red); }

.week-sum {
  background: #101010;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 2px;
  font-family: var(--mono);
  font-size: 0.52rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-align: center;
  line-height: 1.15;
  overflow-wrap: anywhere;
  min-width: 0;
}

.week-sum.pos { color: var(--green); background: rgba(29, 185, 84, 0.08); }
.week-sum.neg { color: var(--red); background: rgba(231, 76, 60, 0.08); }

/* Bottom sheet — bez blur/animacji transform (iOS glitches) */
#editor {
  border: none;
  background: #121212;
  color: var(--text);
  padding: 0;
  width: 100%;
  max-width: 100%;
  border-radius: 16px 16px 0 0;
  margin: 0;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  max-height: 90%;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
}

#editor[open] {
  display: flex;
  flex-direction: column;
}

#editor::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #333;
  margin: 10px auto 0;
  flex-shrink: 0;
}

#editor-form {
  padding: 14px 16px calc(16px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.editor-date {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.amount-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  align-items: stretch;
}

.sign-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--green);
  cursor: pointer;
  touch-action: manipulation;
}

.sign-btn:active {
  opacity: 0.85;
}

.sign-btn.neg {
  color: var(--red);
  border-color: rgba(231, 76, 60, 0.4);
  background: var(--red-dim);
}

.sign-btn.pos {
  color: var(--green);
  border-color: rgba(29, 185, 84, 0.35);
  background: var(--green-dim);
}

#amount {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  font-family: var(--mono);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  border-radius: var(--radius);
}

#amount:focus {
  border-color: #3a3a3a;
}

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

.btn {
  height: 48px;
  border-radius: 12px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  touch-action: manipulation;
}

.btn:active {
  opacity: 0.85;
}

.btn.ghost {
  background: var(--surface);
  color: var(--red);
}

.btn.primary {
  background: var(--text);
  color: #0a0a0a;
}

@media (min-width: 560px) {
  body {
    background: #000;
  }

  .shell {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(420px, 100%);
    height: min(860px, 100%);
    max-height: 100%;
    transform: translate(-50%, -50%);
    border-radius: 0;
    border: none;
  }

  #editor {
    left: 50%;
    right: auto;
    width: min(420px, 100%);
    transform: translateX(-50%);
  }
}
