:root {
  color-scheme: light;
  --canvas: #fbf4f5;
  --glow: #f3dce2;
  --surface: #fffdfd;
  --surface-tint: #fff8f9;
  --soft: #f8e8ed;
  --soft-strong: #f3dce4;
  --stroke: #e8d8df;
  --ink: #2b2228;
  --muted: #70616a;
  --accent: #a64e70;
  --accent-strong: #873754;
  --accent-text: #79354f;
  --balance-tint: #f0d5df;
  --pill: #f9ecef;
  --swatch: #c984a1;
  --shadow: 0 12px 40px rgb(77 41 57 / .055);
  --serif: "Baskervville", "Georgia", "Noto Serif", serif;
  --sans: "Inter", "OpenAI Sans", system-ui, -apple-system, sans-serif;
  --telegram-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --telegram-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
}

:root[data-theme="lavender"] {
  --canvas: #f7f4fb;
  --glow: #e9def6;
  --surface: #fffdfd;
  --surface-tint: #fcf9ff;
  --soft: #efe6f7;
  --soft-strong: #e9dcf4;
  --stroke: #e3d8ed;
  --ink: #2c2436;
  --muted: #695d74;
  --accent: #72529e;
  --accent-strong: #5c3c87;
  --accent-text: #523878;
  --balance-tint: #e5d6f3;
  --pill: #f0e8f8;
  --swatch: #aa8cca;
  --shadow: 0 12px 40px rgb(55 40 84 / .055);
}

:root[data-theme="mint"] {
  --canvas: #f1f8f4;
  --glow: #dceee4;
  --surface: #fcfefd;
  --surface-tint: #f7fcf9;
  --soft: #e3f1e9;
  --soft-strong: #d8ece0;
  --stroke: #d5e6db;
  --ink: #202e27;
  --muted: #53695c;
  --accent: #3a765c;
  --accent-strong: #285d45;
  --accent-text: #26563f;
  --balance-tint: #d3e9dc;
  --pill: #e6f2eb;
  --swatch: #82b29a;
  --shadow: 0 12px 40px rgb(39 71 54 / .055);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--canvas); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(ellipse 65% 64% at 50% -16%, var(--glow) 0%, transparent 95%),
    var(--canvas);
  font: 15px/1.45 var(--sans);
}
body:has(dialog[open]) { overflow: hidden; }
button, input, select { font: inherit; }
button { color: inherit; }
button:enabled { cursor: pointer; }
button:disabled { opacity: .48; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
h1, h2, p, dl, dd { margin: 0; }
h1, h2 { font-weight: 620; }
h1 {
  font-family: var(--serif);
  font-size: clamp(2.55rem, 5.4vw, 3.75rem);
  font-weight: 400;
  letter-spacing: -.058em;
  line-height: 1.06;
}
h2 { font-size: 1.16rem; letter-spacing: -.03em; line-height: 1.24; }

.shell {
  width: min(1080px, calc(100% - 72px));
  margin-inline: auto;
  padding: calc(23px + var(--telegram-top)) 0 calc(40px + var(--telegram-bottom));
}

.masthead {
  min-height: 59px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding-bottom: 19px;
  border-bottom: 1px solid var(--stroke);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  font-size: 1.35rem;
  background: var(--soft);
  border: 1px solid var(--stroke);
  border-radius: 13px;
}
.brand-name {
  font-family: var(--serif);
  font-size: 1.5rem;
  letter-spacing: -.05em;
  line-height: 1;
}
.masthead-actions { justify-self: end; display: flex; gap: 9px; align-items: center; }
.demo-badge {
  color: var(--muted);
  padding: 4px 8px;
  font-size: .72rem;
  font-weight: 600;
  border: 1px solid var(--stroke);
  border-radius: 99px;
}
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--soft);
  border: 1px solid var(--stroke);
  border-radius: 14px;
}
.tab {
  min-height: 39px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: .86rem;
  white-space: nowrap;
}
.tab span { margin-right: 4px; }
.tab[aria-current="page"] {
  background: var(--surface);
  border-color: var(--stroke);
  color: var(--accent-text);
  box-shadow: 0 2px 4px rgb(55 34 45 / .05);
}

.theme-button, .small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 6px 13px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: var(--surface);
  font-size: .83rem;
  font-weight: 620;
  white-space: nowrap;
}
.theme-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 2px var(--soft);
}

main { padding-top: 32px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 9px 17px;
  font-size: .9rem;
  font-weight: 620;
  text-align: center;
}
.button.primary { background: var(--accent); color: white; }
.button.primary:enabled:hover { background: var(--accent-strong); }
.button.secondary { background: var(--surface); border-color: var(--stroke); }
.button.danger { background: #a23a4e; color: #fff; }
.plus { font-size: 1.17em; line-height: 1; }

.panel {
  min-width: 0;
  padding: clamp(16px, 2.4vw, 28px);
  border: 1px solid var(--stroke);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.calendar-layout, .finance-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.14fr) minmax(0, .86fr);
  align-items: start;
  gap: 20px;
}
.calendar-top, .agenda-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
}
.arrow-pair { display: flex; gap: 6px; }
.arrow {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--stroke);
  border-radius: 11px;
  background: var(--surface-tint);
  font-size: 1.45rem;
  line-height: 1;
}
.arrow span { transform: translateY(-1px); }
.arrow:enabled:hover, .theme-button:enabled:hover, .small-button:enabled:hover { background: var(--soft); }

.weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); text-align: center; }
.weekdays {
  margin-top: 17px;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 620;
}
.calendar-grid { margin-top: 8px; gap: 4px; }
.calendar-day {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 42px;
  height: clamp(42px, 5.4vw, 55px);
  padding: 0 0 3px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  font-size: .89rem;
  font-weight: 570;
}
.calendar-day[aria-current="date"] { border-color: var(--stroke); }
.calendar-day:hover { background: var(--surface-tint); }
.calendar-day[aria-pressed="true"] { color: var(--accent-text); background: var(--soft-strong); border-color: var(--stroke); }
.calendar-day.has-visits::after, .legend i {
  background: var(--accent);
  width: 5px;
  height: 5px;
  border-radius: 50%;
}
.calendar-day.has-visits::after { content: ""; position: absolute; bottom: 5px; left: calc(50% - 2.5px); }
.calendar-footer {
  margin-top: 12px;
  padding-top: 6px;
  min-height: 40px;
  border-top: 1px solid var(--stroke);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .77rem; }
.text-button {
  border: 0;
  padding: 7px 3px;
  min-height: 38px;
  background: transparent;
  color: var(--accent-text);
  font-size: .82rem;
  font-weight: 650;
}
.text-button:enabled:hover { text-decoration: underline; }
.muted { color: var(--muted); font-size: .82rem; }
.agenda-top p { margin-top: 4px; }
.visits { display: grid; gap: 10px; margin-top: 16px; }
.visit-card { background: var(--surface-tint); border: 1px solid var(--stroke); border-radius: 15px; overflow: hidden; }
.visit-details {
  display: grid;
  grid-template-columns: 51px minmax(0, 1fr) auto;
  align-items: start;
  width: 100%;
  min-height: 49px;
  padding: 13px 12px 6px;
  gap: 8px;
  border: 0;
  background: transparent;
  text-align: left;
}
.visit-details:hover, .operation:hover { background: var(--soft); }
.visit-time { color: var(--accent-text); font-variant-numeric: tabular-nums; font-weight: 670; font-size: .83rem; padding-top: 2px; }
.visit-person, .operation-label { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.visit-name { font-size: .91rem; font-weight: 650; }
.visit-phone { color: var(--muted); font-size: .77rem; }
.visit-price { font-size: .86rem; font-weight: 650; text-align: right; overflow-wrap: anywhere; }
.visit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  flex-wrap: wrap;
  padding: 0 9px 8px 12px;
}
.visit-status {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 28px;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: .74rem;
  font-weight: 590;
}
.visit-status.planned { color: var(--accent-text); background: var(--pill); }
.visit-status.paid { color: #2e664c; background: #e8f3eb; border: 0; }
button.visit-status.paid { min-height: 35px; }
button.visit-status.paid:enabled:hover { background: #d7ebdf; }
.payment-button {
  min-height: 39px;
  margin-left: auto;
  padding: 5px 8px;
  border: 0;
  background: transparent;
  color: var(--accent-text);
  font-size: .77rem;
  font-weight: 650;
}
.payment-button:hover { text-decoration: underline; }
.empty-state {
  padding: 22px 13px;
  border: 1px dashed var(--stroke);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
  font-size: .88rem;
}
.empty-state p { margin-top: 3px; }

.balance {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  padding: 23px 20px;
  background: linear-gradient(130deg, var(--soft) 10%, var(--balance-tint) 100%);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  color: var(--accent-text);
}
.balance span { font-size: .86rem; font-weight: 630; }
.balance strong {
  font-family: var(--serif);
  font-size: clamp(2.15rem, 5vw, 3.6rem);
  font-weight: 400;
  letter-spacing: -.055em;
  line-height: 1.08;
  overflow-wrap: anywhere;
}
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 11px; }
.totals div {
  min-width: 0;
  padding: 12px;
  background: var(--surface-tint);
  border: 1px solid var(--stroke);
  border-radius: 13px;
}
.totals dt { font-size: .83rem; color: var(--muted); }
.totals dd { margin-top: 3px; font-size: 1.12rem; font-weight: 680; overflow-wrap: anywhere; }
.storage-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 43px;
  margin-top: 13px;
  padding: 5px 0;
  border: 0;
  border-top: 1px solid var(--stroke);
  background: transparent;
  color: var(--muted);
  font-size: .83rem;
}
.storage-link:hover { color: var(--accent-text); }
.storage-link-value { display: flex; align-items: center; gap: 9px; }
.storage-link-value > span:last-child { font-size: 1.2rem; }
.activity-top { display: flex; align-items: center; min-height: 46px; }
.activity-list { margin-top: 12px; }
.operation {
  display: grid;
  width: 100%;
  min-height: 59px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--stroke);
  background: transparent;
  text-align: left;
  font-size: .86rem;
}
.operation:last-child { border-bottom: 0; }
.operation-icon {
  display: grid;
  place-items: center;
  height: 31px;
  width: 31px;
  border-radius: 9px;
  color: var(--accent-text);
  background: var(--soft);
  font-size: 1.1rem;
}
.operation-icon.income-icon { color: #315d46; background: #e9f4ed; }
.operation-income { color: #315d46; }
.operation-cost { color: #8a3c4d; }
.operation-income, .operation-cost { overflow-wrap: anywhere; text-align: right; }

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
  padding: 10px 12px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: var(--soft);
  color: var(--accent-text);
  font-size: .85rem;
}
.notice div { display: grid; gap: 2px; }
.notice span { font-size: .77rem; }
.capacity-notice { background: #fff2d7; border-color: #e8d6ac; color: #694c16; }
.state-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 45px 15px;
  text-align: center;
  color: var(--muted);
}
.state-panel h1 { font-size: 2rem; color: var(--ink); }
.spinner {
  width: 23px;
  height: 23px;
  border: 2px solid var(--stroke);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

dialog {
  width: min(440px, calc(100vw - 28px));
  max-height: min(94dvh, 700px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--stroke);
  border-radius: 22px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 64px rgb(32 20 27 / .19);
}
dialog::backdrop { background: rgb(39 25 34 / .37); }
.sheet { display: grid; gap: 16px; padding: 20px; }
.sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.sheet-header h2 { font-family: var(--serif); font-size: 1.82rem; font-weight: 400; }
.sheet-header p { margin-top: 5px; }
.close-button {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  background: var(--soft);
  color: var(--accent-text);
  font-size: 1.38rem;
  line-height: 1;
}
.fields { display: grid; gap: 13px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.field { display: block; min-width: 0; font-size: .83rem; font-weight: 630; }
.optional { font-size: .76rem; color: var(--muted); font-weight: 400; }
.field input, .field select {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: var(--surface-tint);
  color: var(--ink);
  font-size: 16px;
}
.field input::placeholder { color: var(--muted); opacity: .83; }
.field input:read-only { background: var(--soft); }
.form-error, .status-message { font-size: .83rem; }
.form-error, .status-message.error, .destructive { color: #9a3447; }
.status-message { color: var(--accent-text); }
.sheet-actions { display: grid; gap: 5px; }
.confirm-box { display: grid; gap: 11px; padding: 13px; border: 1px solid var(--stroke); border-radius: 13px; background: var(--surface-tint); }
.confirm-box p { font-size: .86rem; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.confirm-actions .button { flex: 1 0 auto; }

.theme-options { display: grid; gap: 8px; }
.theme-choice {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 6px 11px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: var(--surface-tint);
  font-weight: 620;
  text-align: left;
}
.theme-choice[aria-pressed="true"] { background: var(--soft); border-color: var(--swatch); }
.theme-choice .chosen { color: var(--accent-text); visibility: hidden; }
.theme-choice[aria-pressed="true"] .chosen { visibility: visible; }
.swatches { width: 40px; height: 26px; border-radius: 7px; background: linear-gradient(100deg, var(--light) 52%, var(--dark) 52%); }
[data-pick-theme="powder"] { --light: #f4dce7; --dark: #a64e70; }
[data-pick-theme="lavender"] { --light: #e9dcf4; --dark: #72529e; }
[data-pick-theme="mint"] { --light: #dceee4; --dark: #3a765c; }

progress { display: block; width: 100%; height: 8px; accent-color: var(--accent); }
.toast {
  z-index: 3;
  position: fixed;
  bottom: calc(18px + var(--telegram-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 34px);
  padding: 9px 15px;
  border-radius: 30px;
  background: var(--ink);
  color: var(--surface);
  text-align: center;
  box-shadow: 0 5px 14px rgb(38 27 34 / .2);
  font-size: .84rem;
}

@media (max-width: 760px) {
  .shell { width: min(545px, calc(100% - 32px)); padding-top: calc(12px + var(--telegram-top)); padding-bottom: calc(93px + var(--telegram-bottom)); }
  .masthead { display: flex; justify-content: space-between; min-height: 55px; padding-bottom: 10px; }
  .brand-mark { width: 37px; height: 37px; font-size: 1.15rem; border-radius: 10px; }
  .brand-name { font-size: 1.31rem; }
  .theme-button { min-height: 38px; padding-inline: 10px; }
  .tabs {
    z-index: 2;
    position: fixed;
    bottom: calc(10px + var(--telegram-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: min(545px, calc(100vw - 28px));
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgb(42 25 34 / .13);
  }
  .tab { min-height: 44px; padding-inline: 5px; font-size: .86rem; border-radius: 11px; }
  .tab[aria-current="page"] { background: var(--soft); box-shadow: none; }
  main { padding-top: 21px; }
  .page-heading { align-items: center; margin-bottom: 15px; }
  .page-heading .button { padding-inline: 10px; }
  .calendar-layout, .finance-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .panel { border-radius: 19px; }
  .calendar-top { min-height: 42px; }
  .weekdays { margin-top: 12px; }
  .calendar-grid { gap: 2px; }
  .calendar-day { min-height: 38px; height: 38px; }
  .calendar-footer { margin-top: 6px; padding-top: 2px; }
  .agenda-top { min-height: 42px; }
  .visits { margin-top: 11px; }
  .balance { margin-top: 12px; padding: 18px 15px; }
  .activity-top { min-height: 32px; }
  .activity-list { margin-top: 8px; }
  .toast { bottom: calc(71px + var(--telegram-bottom)); }
}

@media (max-width: 365px) {
  .shell { width: calc(100% - 22px); }
  .brand { gap: 6px; }
  .masthead-actions { gap: 5px; }
  .page-heading h1 { font-size: 2.2rem; }
  .page-heading .button { font-size: .78rem; padding-inline: 8px; }
  .panel { padding: 13px; }
  .calendar-day { min-height: 38px; height: 38px; }
  .visit-details { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
