/* kanalapp — design tokens + shell (notes/design-brief.md е закон).
   Naming: app_блок_елемент, --modifier, is-state, data-* за JS hooks.
   Vanilla CSS, без framework. */

:root {
  color-scheme: light dark; /* задължително — иначе light-dark() е no-op */

  /* --- Брандови цветове (oklch приближения на hex от business-context.md) --- */
  --brand-accent: oklch(53% 0.19 258); /* #2563eb */
  --brand-accent2: oklch(68% 0.15 235); /* #0ea5e9 */
  --brand-green: oklch(59% 0.16 145); /* #16a34a — платено */
  --brand-red: oklch(63% 0.21 25); /* #ef4444 — спешно/дължимо */
  --brand-text: oklch(21% 0.04 265); /* #0f172a */

  /* --- Повърхности: light-dark() двойки --- */
  --app_bg: light-dark(oklch(98% 0.006 258), oklch(17% 0.02 260));
  --app_surface: light-dark(oklch(100% 0 0), oklch(23% 0.02 260));
  --app_surface-raised: light-dark(oklch(100% 0 0), oklch(27% 0.02 260));
  --app_text: light-dark(var(--brand-text), oklch(93% 0.015 265));
  --app_text-muted: light-dark(oklch(45% 0.03 265), oklch(70% 0.02 265));
  --app_border: light-dark(oklch(90% 0.008 258), oklch(34% 0.02 260));

  --app_accent: light-dark(var(--brand-accent), oklch(70% 0.15 258));
  --app_accent-hover: color-mix(in oklch, var(--app_accent) 85%, black);
  --app_accent-tint: color-mix(in oklch, var(--app_accent) 14%, transparent);
  --app_green: light-dark(var(--brand-green), oklch(70% 0.15 145));
  --app_green-tint: color-mix(in oklch, var(--app_green) 16%, transparent);
  --app_red: light-dark(var(--brand-red), oklch(72% 0.18 25));
  --app_red-tint: color-mix(in oklch, var(--app_red) 16%, transparent);
  --app_yellow: light-dark(oklch(68% 0.15 85), oklch(78% 0.15 85));
  --app_yellow-tint: color-mix(in oklch, var(--app_yellow) 22%, transparent);

  /* --- Fluid type (стъпка max÷min ≤ 2.5, WCAG zoom) --- */
  --step--1: clamp(0.8rem, 0.77rem + 0.15vw, 0.875rem);
  --step-0: clamp(1rem, 0.95rem + 0.2vw, 1.0625rem);
  --step-1: clamp(1.125rem, 1.05rem + 0.35vw, 1.25rem);
  --step-2: clamp(1.3rem, 1.2rem + 0.5vw, 1.5rem);
  --step-3: clamp(1.6rem, 1.4rem + 0.9vw, 1.9rem);

  /* --- Spacing скала --- */
  --space-3xs: 0.25rem;
  --space-2xs: 0.375rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4.5rem;

  /* --- Radius йерархия --- */
  --radius-container: 1rem;
  --radius-card: 0.75rem;
  --radius-button: 0.625rem;
  --radius-pill: 999px;

  /* --- Layered soft shadow (тонирана, 4 слоя) --- */
  --shadow-card:
    0 1px 1px color-mix(in oklch, var(--brand-text) 4%, transparent),
    0 2px 4px color-mix(in oklch, var(--brand-text) 4%, transparent),
    0 6px 12px color-mix(in oklch, var(--brand-text) 5%, transparent),
    0 12px 24px color-mix(in oklch, var(--brand-text) 4%, transparent);

  --nav-height: 4rem;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--app_bg);
  color: var(--app_text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--step-0);
  line-height: 1.5;
}

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
}

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

h1, h2, h3 {
  line-height: 1.2;
  margin: 0 0 var(--space-sm);
}
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }

p { margin: 0 0 var(--space-md); }

a {
  color: var(--app_accent);
}

:focus-visible {
  outline: 3px solid var(--app_accent);
  outline-offset: 2px;
}

/* никога outline:none без замяна */

button, .app_button {
  font: inherit;
  cursor: pointer;
}

.app_button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  min-height: 44px;
  min-width: 44px;
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-button);
  border: 1px solid transparent;
  background: var(--app_accent);
  color: white;
  font-weight: 600;
  transition: background-color 0.15s ease;
}
.app_button:hover { background: var(--app_accent-hover); }
.app_button--secondary {
  background: var(--app_surface);
  color: var(--app_text);
  border-color: var(--app_border);
}
.app_button--secondary:hover { background: var(--app_accent-tint); }
.app_button--danger {
  background: var(--app_surface);
  color: var(--app_red);
  border-color: var(--app_red);
}
.app_button--full { width: 100%; }

/* --- Форми --- */
.app_field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  margin-bottom: var(--space-md);
}
.app_field label {
  font-weight: 600;
  font-size: var(--step--1);
}
.app_field input, .app_field select, .app_field textarea {
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-button);
  border: 1px solid var(--app_border);
  background: var(--app_surface);
  color: var(--app_text);
  font: inherit;
}
.app_field textarea { field-sizing: content; min-height: 88px; }
.app_field small[data-error] {
  color: var(--app_red);
  font-size: var(--step--1);
}

/* --- Карти / контейнери --- */
.app_card {
  background: var(--app_surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-lg);
}

.app_container {
  max-width: 64rem;
  margin: 0 auto;
  padding: var(--space-lg);
}

/* --- Pill статуси --- */
.app_pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3xs);
  padding: var(--space-3xs) var(--space-sm);
  border-radius: var(--radius-pill);
  font-size: var(--step--1);
  font-weight: 600;
  background: var(--app_accent-tint);
  color: var(--app_accent);
}
.app_pill--green { background: var(--app_green-tint); color: var(--app_green); }
.app_pill--red { background: var(--app_red-tint); color: var(--app_red); }
.app_pill--yellow { background: var(--app_yellow-tint); color: var(--app_yellow); }

/* --- Layout: header + content + bottom nav (mobile) / sidebar (desktop) --- */
.app_shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--space-md));
}

.app_header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--app_border);
}
.app_header_brand {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-weight: 700;
  font-size: var(--step-1);
  text-decoration: none;
  color: var(--app_text);
}

.app_main {
  flex: 1;
  width: 100%;
}

/* Bottom nav — mobile default */
.app_nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  height: var(--nav-height);
  display: flex;
  background: var(--app_surface-raised);
  border-top: 1px solid var(--app_border);
  box-shadow: var(--shadow-card);
  z-index: 20;
}
.app_nav_item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3xs);
  min-height: 44px;
  color: var(--app_text-muted);
  text-decoration: none;
  font-size: var(--step--1);
}
.app_nav_item svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.app_nav_item.is-active { color: var(--app_accent); font-weight: 700; }
.app_nav_item--fab {
  color: var(--app_accent);
}
.app_nav_item--fab svg { width: 28px; height: 28px; }

@media (min-width: 900px) {
  .app_shell {
    flex-direction: row;
    padding-bottom: 0;
  }
  .app_header { display: none; }
  .app_nav {
    position: static;
    flex-direction: column;
    height: auto;
    width: 15rem;
    border-top: none;
    border-inline-end: 1px solid var(--app_border);
    padding: var(--space-lg) var(--space-sm);
    gap: var(--space-2xs);
  }
  .app_nav_item {
    flex-direction: row;
    justify-content: flex-start;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-button);
    gap: var(--space-sm);
    font-size: var(--step-0);
  }
  .app_nav_item.is-active { background: var(--app_accent-tint); }
  .app_main { padding: var(--space-lg); }
}

/* --- Login --- */
.app_login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}
.app_login_card {
  width: 100%;
  max-width: 24rem;
}
.app_login_logo {
  text-align: center;
  font-size: var(--step-3);
  font-weight: 700;
  margin-bottom: var(--space-lg);
}

/* --- Empty state --- */
.app_empty {
  text-align: center;
  padding: var(--space-2xl) var(--space-md);
  color: var(--app_text-muted);
}

/* --- Таблица потребители --- */
.app_table {
  width: 100%;
  border-collapse: collapse;
}
.app_table th, .app_table td {
  text-align: start;
  padding: var(--space-sm);
  border-bottom: 1px solid var(--app_border);
}

content-visibility-list, [data-cv] {
  content-visibility: auto;
  contain-intrinsic-size: 0 200px;
}

/* --- Phase 2 wave A: клиенти/адреси/посещения/бърз запис --- */

.app_row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.app_text-muted {
  color: var(--app_text-muted);
  font-size: var(--step--1);
}

.app_plainlist {
  list-style: none;
  padding: 0;
  margin: 0;
}
.app_plainlist li {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--app_border);
}
.app_plainlist li:last-child { border-bottom: none; }
.app_plainlist form { display: inline-flex; }

.app_visit-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs);
}
.app_visit-row > a { flex: 1 1 auto; }
.app_visit-row > .app_text-muted { flex-basis: 100%; }

.app_chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
  margin-bottom: var(--space-sm);
}

/* Toggleable pill button — used for phone-suggest client picker, address
   chips, lead/helper worker chips. is-active = selected. */
.app_chip {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--space-2xs) var(--space-md);
  border-radius: var(--radius-pill);
  border: 2px solid color-mix(in oklch, var(--chip-color, var(--app_accent)) 55%, var(--app_border));
  background: var(--app_surface);
  color: var(--app_text);
  font-weight: 600;
  font-size: var(--step--1);
}
.app_chip.is-active {
  background: color-mix(in oklch, var(--chip-color, var(--app_accent)) 22%, var(--app_surface));
  border-color: var(--chip-color, var(--app_accent));
}

/* Multi-select colored grid buttons — quick-add step 3 (services). */
.app_service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: var(--space-2xs);
  margin-bottom: var(--space-md);
}
.app_service-btn {
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-button);
  border: 2px solid color-mix(in oklch, var(--svc-color, var(--app_accent)) 45%, var(--app_border));
  background: color-mix(in oklch, var(--svc-color, var(--app_accent)) 10%, var(--app_surface));
  color: var(--app_text);
  font: inherit;
  font-weight: 600;
  font-size: var(--step--1);
  text-align: start;
  cursor: pointer;
}
.app_service-btn.is-active {
  background: color-mix(in oklch, var(--svc-color, var(--app_accent)) 32%, var(--app_surface));
  border-color: var(--svc-color, var(--app_accent));
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--svc-color, var(--app_accent)) 40%, transparent) inset;
}

.app_dot {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  background: var(--app_accent);
}

.app_map-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 12rem;
  border-radius: var(--radius-card);
  background: var(--app_surface-raised);
  border: 1px dashed var(--app_border);
  margin-bottom: var(--space-lg);
}

/* Quick-add (visits/new) — each numbered step is its own card, stacked. */
.app_qa-step { margin-bottom: var(--space-lg); }
.app_qa-step h2 { font-size: var(--step-1); }

/* --- Phase 2 wave B: календар, "Готово" екран, офлайн опашка --- */

.app_cal_nav { margin-bottom: var(--space-lg); }
.app_cal_nav-mid { display: flex; align-items: center; gap: var(--space-xs); }
.app_cal_nav-mid input[type="date"] {
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-button);
  border: 1px solid var(--app_border);
  background: var(--app_surface);
  color: var(--app_text);
  font: inherit;
}

.app_cal-day {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}
@media (min-width: 900px) {
  .app_cal-day { flex-direction: row; align-items: flex-start; }
  .app_cal-grid { flex: 1 1 auto; min-width: 0; }
  .app_cal-sidebar { flex: 0 0 18rem; display: flex; flex-direction: column; gap: var(--space-lg); }
}

.app_cal-grid {
  display: flex;
  gap: var(--space-2xs);
  overflow-x: auto;
  border: 1px solid var(--app_border);
  border-radius: var(--radius-card);
  background: var(--app_surface);
  padding: var(--space-sm);
}
.app_cal-axis {
  position: relative;
  flex: 0 0 3rem;
  border-inline-end: 1px solid var(--app_border);
}
.app_cal-hour {
  position: absolute;
  inset-inline-start: 0;
  font-size: var(--step--1);
  color: var(--app_text-muted);
  transform: translateY(-0.5em);
}
.app_cal-col {
  flex: 0 0 11rem;
  min-width: 11rem;
}
.app_cal-col h3 {
  font-size: var(--step--1);
  display: flex;
  align-items: center;
  gap: var(--space-3xs);
  padding-bottom: var(--space-2xs);
  border-bottom: 1px solid var(--app_border);
  margin-bottom: var(--space-2xs);
}
.app_cal-col_track {
  position: relative;
  border-inline-start: 1px dashed var(--app_border);
}

.app_cal-visit {
  position: absolute;
  inset-inline: var(--space-3xs);
  display: flex;
  flex-direction: column;
  padding: var(--space-3xs) var(--space-2xs);
  min-height: 24px;
  overflow: hidden;
  border-radius: var(--radius-button);
  border: none;
  border-inline-start: 4px solid var(--svc-color, var(--app_accent));
  background: color-mix(in oklch, var(--svc-color, var(--app_accent)) 14%, var(--app_surface-raised));
  color: var(--app_text);
  text-align: start;
  font: inherit;
  font-size: var(--step--1);
  cursor: grab;
  touch-action: none;
}
.app_cal-visit:active,
.app_cal-visit.is-dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-card);
  z-index: 5;
}
.app_cal-visit.is-overlap {
  border: 2px solid var(--app_red);
  border-inline-start-width: 4px;
}
.app_cal-visit.is-travel-warn:not(.is-overlap) {
  border: 2px solid var(--app_yellow);
  border-inline-start-width: 4px;
}
.app_cal-visit_time { font-weight: 700; }
.app_cal-visit_client {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app_cal-visit_travel {
  font-size: var(--step--1);
  color: var(--app_text-muted);
}
.app_cal-late-badge { align-self: flex-start; }
@media (prefers-reduced-motion: no-preference) {
  .app_cal-late-badge {
    animation: app_pulse-late 1.4s ease-in-out infinite;
  }
}
@keyframes app_pulse-late {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(1.05); }
}

.app_cal-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(9rem, 1fr));
  gap: var(--space-2xs);
  overflow-x: auto;
}
.app_cal-week_day {
  border: 1px solid var(--app_border);
  border-radius: var(--radius-card);
  background: var(--app_surface);
  padding: var(--space-sm);
}
.app_cal-week_day.is-today { border-color: var(--app_accent); }
.app_cal-week_day h3 { font-size: var(--step--1); margin-bottom: var(--space-2xs); }
.app_cal-week_card {
  display: block;
  border-inline-start: 3px solid var(--svc-color, var(--app_accent));
  padding-inline-start: var(--space-2xs);
  text-decoration: none;
  color: var(--app_text);
  font-size: var(--step--1);
}

/* "Готово" dialog + reschedule action sheet share this base — nativно
   <dialog>, bottom sheet on mobile, centered card on desktop. */
.app_sheet-dialog {
  border: none;
  border-radius: var(--radius-card);
  padding: var(--space-lg);
  width: min(32rem, 100vw);
  max-height: 100dvh;
  background: var(--app_surface);
  color: var(--app_text);
  box-shadow: var(--shadow-card);
}
.app_sheet-dialog::backdrop {
  background: color-mix(in oklch, black 55%, transparent);
}
@media (max-width: 599px) {
  .app_sheet-dialog {
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    margin: 0;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
  }
}
.app_done-price {
  max-width: 6rem;
  min-height: 44px;
  padding: var(--space-3xs) var(--space-xs);
  border-radius: var(--radius-button);
  border: 1px solid var(--app_border);
  background: var(--app_surface);
  color: var(--app_text);
  font: inherit;
  text-align: end;
}

.app_offline-banner {
  position: fixed;
  inset-inline: 0;
  bottom: calc(var(--nav-height) + var(--space-xs));
  z-index: 30;
  margin-inline: auto;
  width: fit-content;
  max-width: calc(100% - 2 * var(--space-md));
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-pill);
  background: var(--app_accent);
  color: white;
  font-size: var(--step--1);
  font-weight: 600;
  box-shadow: var(--shadow-card);
  text-align: center;
}
@media (min-width: 900px) {
  .app_offline-banner { bottom: var(--space-md); }
}

/* Фаза 6: SW update банер (app.js) — "Нова версия — Презареди". */
.app_update-banner {
  position: fixed;
  inset-inline: 0;
  bottom: calc(var(--nav-height) + var(--space-xs));
  z-index: 31;
  margin-inline: auto;
  width: fit-content;
  max-width: calc(100% - 2 * var(--space-md));
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-md);
  border-radius: var(--radius-pill);
  background: var(--app_text);
  color: var(--app_surface);
  font-size: var(--step--1);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}
.app_update-banner .app_button {
  padding: var(--space-3xs) var(--space-sm);
}
@media (min-width: 900px) {
  .app_update-banner { bottom: var(--space-md); }
}

/* --- Phase 3: карти и маршрути (geopicker.js / daymap.js / addrmap.js) --- */

.app_geo-picker { position: relative; }
.app_geo-suggest {
  position: relative;
  margin-bottom: var(--space-sm);
}
.app_geo-suggest-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--app_border);
  border-radius: var(--radius-card);
  background: var(--app_surface-raised);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.app_geo-suggest-item {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  border: none;
  border-bottom: 1px solid var(--app_border);
  background: transparent;
  color: var(--app_text);
  text-align: start;
  font: inherit;
}
.app_geo-suggest-item:last-child { border-bottom: none; }
.app_geo-suggest-item:hover,
.app_geo-suggest-item:focus-visible { background: var(--app_accent-tint); }

.app_map-mini {
  min-height: 14rem;
  border-radius: var(--radius-card);
  border: 1px solid var(--app_border);
  margin-block: var(--space-sm) var(--space-lg);
  background: var(--app_surface-raised);
}
.app_map-mini--tall { min-height: 18rem; }

.app_daymap {
  min-height: 60vh;
  border-radius: var(--radius-card);
  border: 1px solid var(--app_border);
  background: var(--app_surface-raised);
}

/* Leaflet's default marker pin is a photo-realistic drop shape; a numbered
   colored dot (per worker color) reads faster on a busy day-map at a
   glance, so daymap.js uses L.divIcon with this instead. */
.app_daymap-pin_dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: var(--shadow-card);
  color: white;
  font-size: var(--step--1);
  font-weight: 700;
}
.app_daymap-popup { font-size: var(--step--1); }

/* --- Phase 4: снимки, маска, сподели (photos.js / share-public.js) --- */

.app_photos-upload-btn input[type="file"] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app_photos-progress {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--app_surface-raised);
  overflow: hidden;
  margin-block: var(--space-xs);
}
.app_photos-progress_bar {
  height: 100%;
  width: 0%;
  background: var(--app_accent);
  transition: width 0.15s ease;
}

.app_photos-failed { margin-bottom: var(--space-sm); }

.app_photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: var(--space-xs);
  content-visibility: auto;
  contain-intrinsic-size: 0 400px;
}
.app_photos-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-button);
  overflow: hidden;
  background: var(--app_surface-raised);
  border: 1px solid var(--app_border);
}
.app_photos-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.app_photos-heic {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--app_text-muted);
  font-size: var(--step--1);
  text-align: center;
}
.app_photos-check {
  position: absolute;
  inset-block-start: var(--space-3xs);
  inset-inline-start: var(--space-3xs);
  z-index: 2;
  background: color-mix(in oklch, black 45%, transparent);
  border-radius: var(--radius-button);
  padding: var(--space-3xs);
  display: flex;
}
.app_photos-check input { width: 22px; height: 22px; }
.app_photos-kind {
  position: absolute;
  inset-block-end: var(--space-3xs);
  inset-inline-end: var(--space-3xs);
  font-size: 0.65rem;
  padding: 0.1rem var(--space-2xs);
  background: color-mix(in oklch, black 45%, transparent);
  color: white;
}

.app_mask-dialog { width: min(40rem, 100vw); }
.app_mask-canvas-wrap {
  position: relative;
  margin-bottom: var(--space-sm);
  line-height: 0;
}
.app_mask-canvas-wrap img { width: 100%; height: auto; display: block; border-radius: var(--radius-button); }
.app_mask-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: move;
}

/* --- Public share page (share_public.html) --- */
.app_share-body {
  margin: 0;
  min-height: 100dvh;
  background: var(--app_bg);
  color: var(--app_text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
.app_share-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--app_border);
}
.app_share-brand { font-weight: 700; font-size: var(--step-1); }
.app_share-main { flex: 1; max-width: 56rem; width: 100%; margin: 0 auto; padding: var(--space-lg); }
.app_share-card { margin-bottom: var(--space-lg); }
.app_share-created code { word-break: break-all; }

.app_share-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: var(--space-sm);
}
.app_share-thumb {
  padding: 0;
  border: 1px solid var(--app_border);
  border-radius: var(--radius-card);
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--app_surface-raised);
  cursor: zoom-in;
}
.app_share-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.app_share-lightbox {
  border: none;
  padding: 0;
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  background: black;
  display: flex;
  align-items: center;
  justify-content: center;
}
.app_share-lightbox::backdrop { background: black; }
.app_share-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.app_share-lightbox_close {
  position: fixed;
  inset-block-start: var(--space-md);
  inset-inline-end: var(--space-md);
  z-index: 2;
}
.app_share-lightbox_nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--step-3);
  z-index: 2;
}
.app_share-lightbox_prev { inset-inline-start: var(--space-md); }
.app_share-lightbox_next { inset-inline-end: var(--space-md); }

.app_share-footer {
  text-align: center;
  padding: var(--space-lg);
  color: var(--app_text-muted);
  font-size: var(--step--1);
}

/* --- Phase 5: Пари (SPEC.md §M7) --- */

/* Big number badge — total due (Неплатени), Приход/Разход/Печалба
   (Сметачето). --app_stat-color defaults to the accent color; pages set it
   inline to app_red/app_green for "дължимо"/"печалба"/"загуба". */
.app_stat {
  font-size: var(--step-3);
  font-weight: 700;
  color: var(--app_stat-color, var(--app_accent));
}
.app_stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-lg);
  align-items: baseline;
}
.app_stat-label {
  display: block;
  font-size: var(--step--1);
  color: var(--app_text-muted);
  font-weight: 400;
}

/* Simple CSS bar (expenses-by-category) — no chart library, per SPEC.md
   §M7: width% set inline per row via style="--pct:NN%". */
.app_bar-row {
  display: grid;
  grid-template-columns: 8rem 1fr auto;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-3xs) 0;
}
.app_bar-track {
  background: var(--app_border);
  border-radius: var(--radius-pill);
  height: 0.6rem;
  overflow: hidden;
}
.app_bar-fill {
  background: var(--app_accent);
  height: 100%;
  width: var(--pct, 0%);
}

.app_chip-field { margin-bottom: var(--space-sm); }
