:root {
  --bg: #f5f4fb;
  --card: #ffffff;
  --card-2: #f4f2fb;
  --text: #201e2c;
  --text-muted: #6b6780;
  --border: #e4e1f0;
  --accent: #5b46e0;
  --accent-soft: #ece9fb;
  --danger: #d94a3f;
  --danger-soft: #fdecea;
  --warn: #e08a1f;
  --netflix-red: #f26b64;
  --spotify-green: #33c481;
  --ps-blue: #3f8cf2;
  --xbox-green: #33c481;
  --apple-ink: #3a3750;
  --tv-cyan: #33aee0;
  --ai-purple: #9b5de5;
  --other-gray: #8b869e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131020;
    --card: #1c1830;
    --card-2: #201c38;
    --text: #edebf7;
    --text-muted: #a39fbd;
    --border: #2e294a;
    --accent: #9483ff;
    --accent-soft: #2a2350;
    --danger: #ff7a6e;
    --danger-soft: #3a1e1d;
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overscroll-behavior-y: none;
}

body {
  font-family: 'IBM Plex Sans', -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

h1, h2, h3 { font-family: 'Sora', sans-serif; margin: 0; }

button { font-family: inherit; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 4px;
}

.topbar h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.add-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(20, 15, 50, 0.12);
  cursor: pointer;
}
.add-btn:active { transform: scale(0.94); }

.dashboard {
  margin: 14px 20px 6px;
  padding: 18px;
  background: var(--card-2);
  border-radius: 16px;
  text-align: center;
}

.dashboard .label {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.dashboard .total {
  font-family: 'Sora', sans-serif;
  font-size: 34px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.list {
  flex: 1;
  margin: 14px 20px 24px;
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(20, 15, 50, 0.08);
}

.empty-state {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }
.empty-state h3 { font-size: 17px; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 14px; margin: 0; }

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  color: inherit;
}
.row:last-child { border-bottom: none; }
.row:active { background: var(--card-2); }

.tile {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.tile .glyph {
  width: 24px;
  height: 24px;
  background-color: currentColor;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
}

.tile .monogram {
  font-family: 'Sora', sans-serif;
  font-weight: 700;
  font-size: 15px;
}

.row-main { flex: 1; min-width: 0; }
.row-main .name {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-main .expiry {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}
.row-main .expiry.soon { color: var(--danger); font-weight: 600; }
.row-main .expiry.week { color: var(--warn); }

.row-price { text-align: right; flex: none; }
.row-price .amount { font-weight: 700; font-size: 15.5px; }
.row-price .monthly { display: block; font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* Sheet (modal form) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 20, 0.4);
  z-index: 20;
  opacity: 1;
  transition: opacity 0.2s ease;
}
.sheet-backdrop.hidden { opacity: 0; pointer-events: none; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 8dvh;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  z-index: 21;
  display: flex;
  flex-direction: column;
  transform: translateY(0);
  transition: transform 0.25s ease;
  max-width: 560px;
  margin: 0 auto;
  box-shadow: 0 -8px 30px rgba(10, 8, 20, 0.2);
}
.sheet.hidden { transform: translateY(100%); pointer-events: none; }

#sub-form { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.sheet-header h2 { font-size: 16px; font-weight: 700; }

.sheet-btn {
  border: none;
  background: none;
  font-size: 15.5px;
  color: var(--text-muted);
  padding: 6px 4px;
  cursor: pointer;
}
.sheet-btn--primary { color: var(--accent); font-weight: 700; }
.sheet-btn--primary:disabled { color: var(--border); cursor: not-allowed; }

.sheet-body {
  overflow-y: auto;
  padding: 8px 16px 32px;
  padding-bottom: calc(32px + var(--safe-bottom));
}

.form-section {
  background: var(--card);
  border-radius: 14px;
  padding: 4px 14px;
  margin: 16px 0;
}
.form-section h3 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 2px 6px;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 2px;
  border-top: 1px solid var(--border);
  font-size: 15px;
}
.form-section h3 + .field { border-top: none; }

.field span { color: var(--text); flex: none; }

.field input {
  flex: 1;
  text-align: right;
  border: none;
  background: none;
  /* 16px zabrání Safari na iPhonu automaticky přiblížit stránku při klepnutí do pole */
  font-size: 16px;
  color: var(--text);
  font-family: inherit;
  min-width: 0;
}

/* input[type=date/time] mají na iOS vlastní kompaktní vzhled, který nejde
   zarovnat přes text-align — místo roztahování na celou šířku je necháme
   přirozeně velké a přilepíme k pravému okraji přes margin-left: auto. */
.field input[type="date"],
.field input[type="time"] {
  flex: 0 1 auto;
  margin-left: auto;
}

/* Nativní <select> na iOS ignoruje text-align, proto mu vypneme systémový
   vzhled úplně a nahradíme vlastní šipkou, ať sedí na stejnou linku jako vše ostatní. */
.select-wrap {
  flex: 1;
  position: relative;
  display: flex;
  min-width: 0;
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 2px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 1.6px solid var(--text-muted);
  border-bottom: 1.6px solid var(--text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}
.field select {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  width: 100%;
  min-width: 0;
  text-align: right;
  padding-right: 16px;
  border: none;
  background: none;
  font-size: 16px;
  color: var(--text);
  font-family: inherit;
}

.field select:focus,
.field input:focus { outline: none; }
.field--readonly strong { font-weight: 700; }

.hint {
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 6px 2px 12px;
  margin: 0;
}

.form-section--danger { background: none; padding: 0; }
.btn {
  width: 100%;
  padding: 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 15.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.btn--destructive { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn--destructive:active { opacity: 0.75; }

/* Confirm dialog */
.confirm-dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 31;
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  width: min(320px, 86vw);
  box-shadow: 0 12px 40px rgba(10, 8, 20, 0.3);
}
.confirm-dialog.hidden { display: none; }
.confirm-dialog p { margin: 0 0 16px; font-size: 15px; text-align: center; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { margin: 0; }

.hidden { display: none !important; }

::selection { background: var(--accent-soft); }
