/* Lokaj: shared look in the spirit of iOS. Modules use these classes and tokens. */

:root {
  --bg: #F2F2F7;              /* systemGroupedBackground */
  --surface: #FFFFFF;         /* secondarySystemGroupedBackground */
  --surface-pressed: #E5E5EA;
  --fill: rgba(118, 118, 128, 0.12);
  --text: #000000;
  --text-secondary: rgba(60, 60, 67, 0.6);
  --text-tertiary: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.29);
  --accent: #007AFF;
  --destructive: #FF3B30;
  --success: #34C759;
  --warning: #FF9500;
  --note-bg: #FFF4CC;
  --note-text: #8A5A00;
  --radius: 12px;
  --radius-card: 20px;
  --gutter: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --surface-pressed: #2C2C2E;
    --fill: rgba(118, 118, 128, 0.24);
    --text: #FFFFFF;
    --text-secondary: rgba(235, 235, 245, 0.6);
    --text-tertiary: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
    --accent: #0A84FF;
    --destructive: #FF453A;
    --success: #30D158;
    --warning: #FF9F0A;
    --note-bg: #3A3110;
    --note-text: #FFD60A;
  }
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
img, svg { display: block; }
.mono { font-family: var(--mono); font-size: 0.88em; letter-spacing: 0; word-break: break-all; }
.secondary { color: var(--text-secondary); }

/* --- layout ------------------------------------------------------------------ */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    calc(env(safe-area-inset-right) + var(--gutter))
    calc(env(safe-area-inset-bottom) + 40px)
    calc(env(safe-area-inset-left) + var(--gutter));
}

.navbar + .page { padding-top: 4px; }

.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: env(safe-area-inset-top) calc(env(safe-area-inset-right) + 8px) 0 calc(env(safe-area-inset-left) + 8px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

.navbar-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 8px;
  font-size: 17px;
}

.navbar-back svg { width: 12px; height: 20px; }
.navbar-action { display: flex; align-items: center; gap: 4px; padding-right: 8px; }

.large-title {
  margin: 4px 0 16px;
  font: 700 34px/1.12 var(--font-display);
  letter-spacing: 0.01em;
}

.eyebrow {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
}

/* --- home screen ------------------------------------------------------------- */

.home-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.home-header .large-title { margin-bottom: 20px; }

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  margin-bottom: 22px;
  border-radius: 50%;
  background: linear-gradient(180deg, #A5A5AA, #8E8E93);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 600;
}

.avatar-large { width: 84px; height: 84px; margin: 0; font-size: 36px; }

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.module-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 132px;
  padding: 14px;
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--text);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.module-card:active { transform: scale(0.97); background: var(--surface-pressed); }

.module-card .app-icon { margin-bottom: auto; }
.module-name { margin-top: 14px; font-size: 17px; font-weight: 600; }
.module-desc { color: var(--text-secondary); font-size: 13px; line-height: 1.3; }

.app-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--tile) 85%, #FFFFFF), var(--tile));
  color: #FFFFFF;
  font-size: 24px;
}

.app-icon svg { width: 26px; height: 26px; }

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-title { margin: 0 0 6px; color: var(--text); font-size: 20px; font-weight: 600; }

/* --- grouped lists (Settings-like) -------------------------------------------- */

.section-header {
  margin: 28px 16px 7px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.section-footer {
  margin: 7px 16px 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.list {
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
}

.list-spaced { margin-top: 32px; }
.list form { margin: 0; }

.list-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 11px 16px;
  border: 0;
  background: transparent;
  text-align: left;
}

.list-row + .list-row::before,
.list form + form .list-row::before,
.list .list-row + form .list-row::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 16px;
  border-top: 0.5px solid var(--separator);
}

.list-row-stacked { flex-direction: column; align-items: flex-start; gap: 2px; }
.row-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.row-label { font-size: 17px; }
.row-value { color: var(--text-secondary); }
.row-detail { color: var(--text-secondary); font-size: 15px; }

a.list-row { color: var(--text); }
a.list-row::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--text-tertiary);
  border-right: 2px solid var(--text-tertiary);
  transform: rotate(45deg);
}

.list-button { justify-content: center; color: var(--accent); cursor: pointer; }
a.list-button { color: var(--accent); }
a.list-button::after { display: none; }
.list-button:active, a.list-row:active { background: var(--surface-pressed); }
.destructive { color: var(--destructive) !important; }

.text-button {
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 17px;
  cursor: pointer;
}

/* --- profile ---------------------------------------------------------------- */

.profile { display: grid; justify-items: center; gap: 2px; margin: 8px 0 8px; text-align: center; }
.profile-name { margin: 10px 0 0; font-size: 22px; font-weight: 600; }
.profile-sub { margin: 0; color: var(--text-secondary); font-size: 15px; }

/* --- buttons, cards, notices -------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.button:active { opacity: 0.7; transform: scale(0.98); }
.button-primary { background: var(--accent); color: #FFFFFF; }
.button-secondary { background: var(--fill); color: var(--accent); }
.button-plain { background: none; color: var(--accent); font-weight: 400; }
.button-block { width: 100%; }
.button-small { min-width: 56px; min-height: 34px; padding: 0 14px; border-radius: 999px; font-size: 15px; }

.lead { margin: -6px 0 20px; color: var(--text-secondary); font-size: 17px; }

.center-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  max-width: 380px;
  margin: 12vh auto 0;
  text-align: center;
}

.center-card form, .dev-login { width: 100%; }
.dev-login { display: grid; gap: 10px; margin-top: 12px; }
.dev-login .section-header { margin: 0; }
.stack { display: grid; gap: 4px; width: 100%; margin-top: 12px; }

.hero-icon { width: 88px; height: 88px; border-radius: 20px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); }
.hero-title { margin: 8px 0 0; font: 700 28px/1.15 var(--font-display); }
.hero-text { margin: 0; color: var(--text); font-size: 17px; }
.hero-text.secondary { color: var(--text-secondary); font-size: 15px; }

.notice { width: 100%; margin: 4px 0; padding: 12px 14px; border-radius: var(--radius); font-size: 15px; }
.notice-error { background: color-mix(in srgb, var(--destructive) 14%, transparent); color: var(--destructive); }

.footnote { margin-top: 28px; color: var(--text-tertiary); font-size: 13px; text-align: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(30, 30, 32, 0.92);
  color: #FFFFFF;
  font-size: 15px;
  transform: translate(-50%, 20px);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* --- shared components for modules ---------------------------------------------------------- */

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--accent);
}

.icon-button svg { width: 24px; height: 24px; }

/* Pull-down menu (like a UIMenu): <details class="menu"><summary class="icon-button">…</summary>
   <div class="menu-popover"><a class="menu-item">…</a></div></details> */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-popover {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 20;
  min-width: 230px;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.22), 0 0 0 0.5px var(--separator);
}
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 0 16px;
  color: var(--text);
  font-size: 17px;
}
.menu-item + .menu-item { box-shadow: inset 0 0.5px 0 var(--separator); }
.menu-item:active { background: var(--surface-pressed); }
.menu-item-value { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.text-right { text-align: right; }
.list-row > .row-main, .list-row > .row-label:first-child { flex: 1; min-width: 0; }
.list-text { margin: 0; padding: 11px 16px; white-space: pre-line; }
.section-header .count { margin-left: 4px; color: var(--text-tertiary); }

/* Search field (like UISearchBar) */
.search-field {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  margin: 0 0 16px;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--fill);
  color: var(--text-secondary);
}

.search-field svg { flex: none; width: 17px; height: 17px; }

.search-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 17px;
  -webkit-appearance: none;
  appearance: none;
}

.search-field input::placeholder { color: var(--text-secondary); }

/* Filter tiles (like the smart lists in Reminders) */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.tile {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 8px 6px;
  padding: 10px 12px 10px 10px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.tile:active { transform: scale(0.97); }
.tile-active { box-shadow: inset 0 0 0 2px var(--accent); }

.tile-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #FFFFFF;
}

.tile-icon svg { width: 18px; height: 18px; }
.tile-count { justify-self: end; font: 700 24px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.tile-label { grid-column: 1 / -1; color: var(--text-secondary); font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tone-gray { background: #8E8E93; }
.tone-red { background: var(--destructive); }
.tone-orange { background: var(--warning); }
.tone-blue { background: var(--accent); }
.tone-green { background: var(--success); }

/* Chips: one scrollable line by default, wrapped with .chips-wrap */
.chips {
  display: flex;
  gap: 8px;
  margin: 0 calc(-1 * var(--gutter)) 8px;
  padding: 2px var(--gutter) 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chips::-webkit-scrollbar { display: none; }
.chips-wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }

/* .chips[data-expandable]: lokaj.js adds a chevron that unfolds the line into wrapped rows */
.chips-toggle {
  position: sticky;
  right: calc(-1 * var(--gutter)); /* the sticky area is inset by the chips' padding */
  flex: none;
  display: flex;
  align-items: center;
  margin: 0 calc(-1 * var(--gutter)) 0 auto;
  padding: 0 var(--gutter) 0 14px;
  border: 0;
  background: linear-gradient(to right, transparent, var(--bg) 14px);
  color: var(--accent);
  cursor: pointer;
}
.chips-toggle[hidden] { display: none; }
.chips-toggle-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--surface);
}
.chips-toggle svg { width: 18px; height: 18px; transition: transform 0.2s ease; }
.chips-expanded { flex-wrap: wrap; overflow: visible; }
.chips-expanded .chips-toggle { position: static; margin: 0; padding: 0; background: none; }
.chips-expanded .chips-toggle svg { transform: rotate(180deg); }

.chip {
  flex: none;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  white-space: nowrap;
  cursor: pointer;
}

.chip-active { background: var(--accent); color: #FFFFFF; }
.chip-toggle { position: relative; padding: 0; }
.chip-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chip-toggle span { display: block; padding: 7px 13px; border-radius: 999px; }
.chip-toggle input:checked + span { background: var(--accent); color: #FFFFFF; }
.chip-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--fill);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}

.badge-blue { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* Status banner and note */
.banner {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
}

.banner-przeterminowany { background: color-mix(in srgb, var(--destructive) 14%, var(--surface)); color: var(--destructive); }
.banner-konczy_sie { background: color-mix(in srgb, var(--warning) 16%, var(--surface)); color: var(--warning); }
.banner-ok { background: color-mix(in srgb, var(--success) 14%, var(--surface)); color: var(--success); }
.banner-brak_daty, .banner-muted { color: var(--text-secondary); }

.note {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--note-bg);
  color: var(--note-text);
  font-size: 15px;
}

.status-text { font-size: 13px; font-weight: 600; }
.status-przeterminowany { color: var(--destructive); }
.status-konczy_sie { color: var(--warning); }
.status-brak_daty { color: var(--text-secondary); }

.result-summary { margin: 4px 4px 0; color: var(--text-secondary); font-size: 15px; }

/* Forms (grouped, stacked labels) */
.form { display: block; }

.form-group {
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
}

.form-group-spaced { margin-top: 10px; }

.field {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 9px 16px 10px;
}

.field + .field::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 16px;
  border-top: 0.5px solid var(--separator);
}

.field-label { color: var(--text-secondary); font-size: 13px; }

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 28px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 17px;
}

.field textarea { resize: vertical; line-height: 1.35; }
.field input[type="file"] { font-size: 15px; }
.field input::placeholder, .field textarea::placeholder { color: var(--text-tertiary); }

.field-inline { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.field-inline input { width: 20px; height: 20px; accent-color: var(--accent); }

.form-actions { display: grid; gap: 4px; margin-top: 24px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* Segmented control (like UISegmentedControl) for switching a module's main views:
   <nav class="segmented"><a class="segment segment-active" aria-current="page">…</a><a class="segment">…</a></nav> */
.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 2px;
  margin: 0 0 16px;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
}
.segment {
  padding: 7px 4px;
  border-radius: 7px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.segment-active {
  background: var(--surface);
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
}
@media (prefers-color-scheme: dark) {
  .segment-active { background: #636366; }
}

/* Screen transitions (cross-document View Transitions: Safari 18.2+, Chrome 126+; elsewhere pages just load).
   Going deeper slides the new screen in from the right like iOS, back slides it away, tabs and saved forms
   cross-fade. The navigation bar only fades, so the back button does not jump. Direction: lokaj.js + base.html. */
@view-transition { navigation: auto; }
.navbar { view-transition-name: navbar; }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.25s; animation-timing-function: cubic-bezier(0.2, 0.85, 0.25, 1); }
::view-transition-old(navbar),
::view-transition-new(navbar) { animation-duration: 0.2s; }
html:active-view-transition-type(forward)::view-transition-old(root) { animation-name: lokaj-push-out; }
html:active-view-transition-type(forward)::view-transition-new(root) { animation-name: lokaj-push-in; }
html:active-view-transition-type(back)::view-transition-old(root) { animation-name: lokaj-pop-out; z-index: 1; }
html:active-view-transition-type(back)::view-transition-new(root) { animation-name: lokaj-pop-in; }
html:active-view-transition-type(tab)::view-transition-old(root),
html:active-view-transition-type(tab)::view-transition-new(root),
html:active-view-transition-type(fade)::view-transition-old(root),
html:active-view-transition-type(fade)::view-transition-new(root) { animation-duration: 0.15s; }
@keyframes lokaj-push-in { from { transform: translateX(100%); box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12); } }
@keyframes lokaj-push-out { to { transform: translateX(-30%); opacity: 0.7; } }
@keyframes lokaj-pop-in { from { transform: translateX(-30%); opacity: 0.7; } }
@keyframes lokaj-pop-out { to { transform: translateX(100%); box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12); } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}

/* A tap that leaves the page lights up what was tapped at once (lokaj.js). Only when the next page takes longer
   than 0.3 s do the progress bar and the dimmed page appear, so quick navigation stays calm. */
.nav-progress {
  opacity: 0;
  animation: lokaj-appear 0.15s ease 0.3s forwards;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(env(safe-area-inset-top) + 3px);
  pointer-events: none;
  overflow: hidden;
}
.nav-progress::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--accent);
  transform-origin: left;
  animation: lokaj-progress 6s cubic-bezier(0.1, 0.75, 0.2, 1) 0.3s both;
}
@keyframes lokaj-appear { to { opacity: 1; } }
@keyframes lokaj-progress { from { transform: scaleX(0.08); } to { transform: scaleX(0.92); } }
html.is-navigating .page { opacity: 0.5; transition: opacity 0.2s ease 0.3s; }
.list-row.is-pressed,
.list-button.is-pressed { background: var(--fill); }
.icon-button.is-pressed,
.navbar-back.is-pressed,
.segment.is-pressed { opacity: 0.45; }
.button.is-pressed { opacity: 0.6; }
@media (prefers-reduced-motion: reduce) {
  .nav-progress::before { animation: none; transform: scaleX(0.6); }
}

/* Live search (htmx): a spinner at the end of the field while results load, shown only when it takes a moment. */
.search-field.htmx-request::after {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--separator);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  opacity: 0;
  animation: lokaj-spin 0.7s linear infinite, lokaj-appear 0.15s ease 0.2s forwards;
}
@keyframes lokaj-spin { to { transform: rotate(360deg); } }
