:root {
  --bg: #f4f2ee;
  --ink: #1d1a16;
  --paper: #ffffff;
  --line: #e3dfd8;
  --muted: #6d675f;
  --red: #c4473a;
  --red-dark: #a53b30;
  --green: #2a6b45;
  --warn: #8d5a2b;
  --shadow: none;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 16.5px;
  line-height: 1.45;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
a { color: inherit; }

.top {
  background: var(--bg);
  color: var(--ink);
  padding: 16px 18px 8px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 8px;
  padding: calc(16px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 8px max(18px, env(safe-area-inset-left));
}
.top h1 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.top p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.top-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.top-row > div:first-child { flex: 1 1 180px; min-width: 0; }
.top-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 12px; align-items: center; }
.linkish {
  background: transparent;
  color: var(--ink);
  border: 0;
  padding: 8px 0;
  text-decoration: underline;
  font-size: 14px;
}
.langs { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.langs button {
  border: 0;
  background: transparent;
  min-width: 44px;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
}
.langs button.on { background: var(--ink); color: #fff; }

.wrap {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 16px 16px 28px;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
  padding: 16px max(16px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.card, .ticket, .banner, .fold, .courier-row {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: none;
}
.card, .banner { padding: 16px; margin-bottom: 14px; }
.ticket { overflow: hidden; margin-bottom: 14px; }
.ticket-body { padding: 14px 14px 16px; }

h2 { margin: 22px 0 10px; font-size: 15px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
h2.profile-name { margin: 0 0 8px; font-size: 24px; letter-spacing: -0.03em; text-transform: none; color: var(--ink); }
label { display: block; font-size: 14px; font-weight: 650; margin: 14px 0 6px; }
textarea, input[type="password"], input[type="text"], input[type="date"], input[type="time"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 52px;
  outline: none;
}
textarea { min-height: 74px; resize: vertical; }
textarea:focus, input:focus { border-color: var(--ink); }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.suggest { position: relative; }
.suggest-list {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: 100%;
  margin: 6px 0 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(28, 25, 23, 0.08);
  max-height: 240px;
  overflow: auto;
}
.suggest-list button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 10px 12px;
}
.suggest-list button.on { background: #f3efe8; }

.actions, .stack { display: grid; gap: 8px; }
.actions { margin-top: 12px; }
.btn {
  border: 0;
  border-radius: 14px;
  min-height: 52px;
  padding: 12px 14px;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1.25;
  white-space: normal;
}
.btn-red { background: var(--red); color: white; }
.btn-red:active { background: var(--red-dark); }
.btn-dark { background: var(--ink); color: #f6f1e8; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn:disabled { opacity: 0.55; }
.btn-done, .btn-done:disabled {
  opacity: 1;
  background: #e8f3ec;
  color: var(--green);
  border: 1px solid #d3e7da;
  cursor: default;
}
.done-pill {
  min-height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e8f3ec;
  color: var(--green);
  font-weight: 650;
}
.when-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.when-fields > div { min-width: 0; }
.date-cal { min-width: 0; }
.date-cal-bar { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-bottom: 4px; }
.date-cal-bar strong { flex: 1; min-width: 0; text-align: center; font-size: 13px; font-weight: 650; line-height: 1.25; }
.date-nav {
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}
.date-cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.date-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
  line-height: 1;
  padding: 2px 0 4px;
  text-transform: capitalize;
}
.date-day {
  border: 0;
  background: transparent;
  border-radius: 8px;
  min-height: 34px;
  padding: 0;
  font-size: 14px;
  font-weight: 650;
}
.date-day.today { box-shadow: inset 0 0 0 1px var(--line); }
.date-day.on, .date-day:active { background: var(--ink); color: #fff; }
.date-day.on.today { box-shadow: none; }
.fold { margin: 0 0 14px; }
.fold > summary {
  list-style: none;
  cursor: pointer;
  min-height: 56px;
  padding: 14px 16px;
  font-weight: 650;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold-body { padding: 0 12px 12px; }
.fold .count { color: inherit; font-weight: 700; font-size: 15px; flex: none; }
#free-fold.calm { background: #e7f3ea; border-color: #d5e8db; }
#free-fold.calm > summary { color: #3f6a4c; }
#free-fold.alert { background: #f8ebe7; border-color: #f0d6d0; }
#free-fold.alert > summary { color: #8a433c; }
.month { margin-top: 8px; }
.courier-row {
  width: 100%;
  text-align: left;
  min-height: 64px;
  padding: 14px 16px;
  margin: 0 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-weight: 650;
}
.courier-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.courier-row .sum { flex: none; font-size: 20px; font-weight: 650; letter-spacing: -0.03em; white-space: nowrap; }
.back { display: inline-flex; margin: 4px 0 12px; }
.row-actions { grid-template-columns: 1fr 1fr; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  min-height: 44px;
}
.chip.on { background: var(--ink); color: #f6f1e8; border-color: var(--ink); }

.shot { display: block; width: 100%; padding: 0; border: 0; background: #111; }
.shot img, .preview img { width: 100%; max-height: 240px; object-fit: cover; }
.preview { position: relative; margin-top: 10px; }
.preview button {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 0;
  background: rgba(28, 25, 21, 0.8);
  color: white;
  border-radius: 999px;
  min-height: 36px;
  padding: 6px 10px;
}
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.when { font-weight: 800; font-size: 20px; letter-spacing: -0.03em; }
.addr { margin-top: 4px; font-size: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note { color: var(--muted); margin: 8px 0 0; white-space: pre-wrap; }
.who { margin-top: 8px; font-size: 14px; font-weight: 700; color: var(--green); }
.who.warn { color: var(--warn); }
.flag {
  background: var(--red);
  color: white;
  display: inline-block;
  margin: 12px 0 0 14px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 700;
}

.banner ol { margin: 8px 0 0; padding-left: 18px; }
.banner p { margin: 8px 0 0; }
.banner.ok { outline: 2px solid rgba(31, 122, 77, 0.25); }
.banner.warn { background: #fff4e8; }
.muted { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); padding: 8px 2px 16px; }

.courier {
  display: block;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.courier:first-child { border-top: 0; }
.courier-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.balance-line { font-weight: 700; margin-top: 4px; }
.balance-card {
  margin-bottom: 14px;
  padding: 18px 16px 14px;
  background: #f6f4f0;
}
.balance-card .balance-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.2;
}
.balance-figure {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-top: 6px;
}
.balance-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.balance-card .balance-eur {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.balance-card .balance-amount {
  font-size: 28px;
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 1;
}
.balance-card .pay-line {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--muted);
}
.balance-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}
.balance-split div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.balance-split span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.balance-split b {
  display: block;
  margin-top: 2px;
  font-size: 18px;
  font-weight: 750;
  overflow-wrap: anywhere;
}
.pay-history {
  margin-top: 12px;
  display: grid;
  gap: 4px;
}
.pay-history div { color: var(--muted); font-size: 13px; }
.balance-sum { font-size: 28px; font-weight: 800; letter-spacing: -0.04em; overflow-wrap: anywhere; }
.amount-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.amount-row label { grid-column: 1 / -1; margin: 0; }
.amount-row .btn { grid-column: 1 / -1; }
.eur { flex: none; font-size: 14px; font-weight: 700; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; margin-right: 6px; background: #b9b1a4; }
.dot.on { background: var(--green); }
.tiny { background: transparent; border: 0; color: var(--red); padding: 8px; }

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--ink);
  color: #f6f1e8;
  border-radius: 14px;
  padding: 14px 16px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 5;
}
#toast.show { opacity: 1; transform: none; }

#light {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 12, 0.92);
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
#light[hidden] { display: none; }
#light img { max-height: 100%; max-width: 100%; object-fit: contain; }
.light-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  font-size: 28px;
}

:focus-visible { outline: 3px solid #8d8578; outline-offset: 2px; }
@media (max-width: 520px) {
  .top-tools { width: 100%; justify-content: space-between; }
}
@media (max-width: 460px) {
  .when-fields { grid-template-columns: 1fr; }
  .date-day { min-height: 40px; }
}
@media (max-width: 380px) {
  .top h1 { font-size: 22px; }
  .wrap { padding-left: 12px; padding-right: 12px; }
  .wrap { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .photo-actions, .row-actions, .balance-split { grid-template-columns: 1fr; }
  .balance-card .balance-amount, .balance-sum { font-size: 24px; }
}
@media (min-width: 900px) {
  .wrap { width: min(640px, 100%); }
}
