:root {
  --tg-bg: var(--tg-theme-bg-color, #ffffff);
  --tg-secondary: var(--tg-theme-secondary-bg-color, #f2f2f6);
  --tg-text: var(--tg-theme-text-color, #14161a);
  --tg-hint: var(--tg-theme-hint-color, #8a8f98);
  --tg-link: var(--tg-theme-link-color, #2f6fed);
  --tg-accent: var(--tg-theme-button-color, #2f6fed);
  --tg-accent-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-section: var(--tg-theme-section-bg-color, var(--tg-secondary));
  --tg-destructive: var(--tg-theme-destructive-text-color, #d64545);
  --line: rgba(15, 20, 30, 0.08);
  --shadow: 0 1px 2px rgba(15, 20, 30, 0.06);
  --home-bg: #fdf1e2;
  --home-fg: #a55b13;
  --salon-bg: #fde8ef;
  --salon-fg: #b23a63;
  --ok-bg: #e7f4ea;
  --ok-fg: #2f7d45;
  --skel: rgba(15, 20, 30, 0.07);
  --radius: 16px;
  --tap: 44px;
  --topbar-h: 52px;
  --tabbar-h: 62px;
}

:root[data-theme="dark"] {
  --tg-bg: var(--tg-theme-bg-color, #101114);
  --tg-secondary: var(--tg-theme-secondary-bg-color, #1b1c20);
  --tg-text: var(--tg-theme-text-color, #f2f3f5);
  --tg-hint: var(--tg-theme-hint-color, #9aa0a8);
  --tg-link: var(--tg-theme-link-color, #6ea8fe);
  --tg-accent: var(--tg-theme-button-color, #3b82f6);
  --tg-accent-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-section: var(--tg-theme-section-bg-color, #1b1c20);
  --tg-destructive: var(--tg-theme-destructive-text-color, #ff6b6b);
  --line: rgba(255, 255, 255, 0.09);
  --shadow: none;
  --home-bg: #3a2a17;
  --home-fg: #f0b877;
  --salon-bg: #3a1f2a;
  --salon-fg: #f08fb0;
  --ok-bg: #1d3324;
  --ok-fg: #86d09a;
  --skel: rgba(255, 255, 255, 0.09);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--tg-bg);
  color: var(--tg-text);
}

body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

a { color: var(--tg-link); text-decoration: none; }

.app { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: var(--tg-bg);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  flex: 1;
  margin: 0;
  padding-left: 4px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  min-width: var(--tap);
  border: 0;
  background: transparent;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-text);
  cursor: pointer;
}

.icon-btn:active { background: var(--tg-secondary); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.add { color: var(--tg-link); }

main {
  padding: 10px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

body.nested main { padding-bottom: 28px; }
body.nested .tabbar { display: none; }

/* ---------------------------------------------------------------- segments */
.segmented {
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--tg-secondary);
  border-radius: 12px;
}

.segmented button {
  flex: 1;
  min-height: var(--tap);
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--tg-text);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  padding: 0 6px;
  white-space: nowrap;
}

.segmented button[aria-pressed="true"] {
  background: var(--tg-bg);
  box-shadow: var(--shadow);
  font-weight: 650;
}

.controls { display: grid; gap: 10px; margin: 2px 0 6px; }

.controls-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: transparent;
  color: var(--tg-text);
  font-size: 13px;
  cursor: pointer;
}

.pill[aria-pressed="true"] {
  background: var(--tg-text);
  color: var(--tg-bg);
  border-color: transparent;
}

.pill .count { opacity: 0.75; margin-left: 4px; }

.link-btn {
  border: 0;
  background: transparent;
  color: var(--tg-link);
  font-size: 14px;
  min-height: var(--tap);
  padding: 0 4px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- lists */
.day-head {
  position: sticky;
  top: var(--topbar-h);
  z-index: 10;
  background: var(--tg-bg);
  padding: 10px 2px 6px;
  font-size: 13px;
  font-weight: 650;
  color: var(--tg-hint);
  text-transform: none;
}

.list { display: grid; gap: 10px; margin-bottom: 6px; }

.booking {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: var(--tap);
  padding: 14px;
  border-radius: var(--radius);
  background: var(--tg-section);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.booking:active { transform: scale(0.995); }

.booking-time {
  width: 54px;
  flex: none;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.booking-time span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  color: var(--tg-hint);
}

.booking-main { flex: 1; min-width: 0; }

.booking-service { font-size: 15px; font-weight: 600; }

.booking-client {
  margin-top: 2px;
  font-size: 13px;
  color: var(--tg-hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.booking-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.booking.cancelled .booking-time, .booking.cancelled .booking-service { opacity: 0.6; }
.booking.cancelled { text-decoration-color: var(--tg-hint); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
}

.badge.home { background: var(--home-bg); color: var(--home-fg); }
.badge.salon { background: var(--salon-bg); color: var(--salon-fg); }

.status {
  font-size: 12px;
  color: var(--tg-hint);
  padding: 3px 0;
}

.status.cancelled { color: var(--tg-destructive); }
.status.confirmed { color: var(--ok-fg); }

.chevron { align-self: center; color: var(--tg-hint); font-size: 22px; padding-right: 2px; }

.transfer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--tg-hint);
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--tap);
  padding: 4px 0;
  font-size: 15px;
  cursor: pointer;
}

.switch {
  width: 48px;
  height: var(--tap);
  flex: none;
  border: 0;
  border-radius: 22px;
  background: transparent;
  position: relative;
  cursor: pointer;
  padding: 0;
}

.switch::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: rgba(120, 128, 140, 0.35);
  transition: background 0.18s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 11px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
  transition: transform 0.18s ease;
}

.switch[aria-checked="true"]::before { background: var(--tg-accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* ---------------------------------------------------------------- detail */
.hero {
  padding: 18px;
  border-radius: var(--radius);
  background: var(--tg-section);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.hero-time { font-size: 30px; font-weight: 720; letter-spacing: -0.03em; }
.hero-date { margin-top: 2px; font-size: 15px; color: var(--tg-hint); }
.hero-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.card-block {
  border-radius: var(--radius);
  background: var(--tg-section);
  box-shadow: var(--shadow);
  padding: 6px 16px;
  margin-bottom: 12px;
}

.field {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.field:last-child { border-bottom: 0; }
.field-label { color: var(--tg-hint); flex: none; }
.field-value { text-align: right; font-weight: 500; word-break: break-word; }
.field-value a { font-weight: 550; }

.actions { display: grid; gap: 10px; margin: 14px 0; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: var(--tg-secondary);
  color: var(--tg-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.btn:active { opacity: 0.8; }
.btn.primary { background: var(--tg-accent); color: var(--tg-accent-text); }
.btn.danger { background: transparent; color: var(--tg-destructive); border: 1px solid var(--line); }

.timeline { list-style: none; margin: 0; padding: 6px 0; }

.timeline li {
  display: flex;
  gap: 12px;
  padding: 9px 0;
  position: relative;
}

.timeline li:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 24px;
  bottom: -2px;
  width: 1px;
  background: var(--line);
}

.dot {
  width: 11px;
  height: 11px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--tg-hint);
  flex: none;
  z-index: 1;
}

.timeline li[data-kind="confirmed"] .dot { background: var(--ok-fg); }
.timeline li[data-kind="cancelled"] .dot { background: var(--tg-destructive); }
.timeline li[data-kind="rescheduled"] .dot { background: var(--tg-accent); }

.tl-text { font-size: 14px; }
.tl-time { margin-top: 2px; font-size: 12px; color: var(--tg-hint); }

.section-title {
  margin: 18px 2px 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--tg-hint);
}

/* ---------------------------------------------------------------- forms */
.day-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 2px 8px;
  -webkit-overflow-scrolling: touch;
}

.day-strip::-webkit-scrollbar { display: none; }

.day-chip {
  flex: none;
  min-width: 62px;
  min-height: 60px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--tg-text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}

.day-chip[aria-pressed="true"] {
  background: var(--tg-text);
  color: var(--tg-bg);
  border-color: transparent;
}

.day-chip .dow { font-size: 11px; text-transform: lowercase; opacity: 0.75; }
.day-chip .num { font-size: 17px; font-weight: 650; }

.time-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.time-cell {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--tg-text);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}

.time-cell[aria-pressed="true"] {
  background: var(--tg-accent);
  border-color: transparent;
  color: var(--tg-accent-text);
}

.time-cell:disabled {
  color: var(--tg-hint);
  background: var(--tg-secondary);
  border-color: transparent;
  text-decoration: line-through;
  cursor: default;
}

.hint {
  font-size: 13px;
  color: var(--tg-hint);
  margin: 6px 2px 10px;
}

.choice {
  width: 100%;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--tg-text);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.choice:last-child { border-bottom: 0; }
.choice .choice-meta { color: var(--tg-hint); font-size: 13px; white-space: nowrap; }
.choice[aria-pressed="true"] { color: var(--tg-link); font-weight: 650; }

.note-input, .edit-area, .select {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--tg-section);
  color: var(--tg-text);
  font-size: 15px;
  outline: none;
  resize: none;
}

.note-input:focus, .edit-area:focus, .select:focus {
  border-color: var(--tg-accent);
}

.summary {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--tg-section);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.5;
}

.summary b { font-weight: 650; }

.primary-action {
  margin-top: 14px;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--tg-accent);
  color: var(--tg-accent-text);
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
}

.primary-action:disabled { opacity: 0.45; cursor: default; }
.has-main-button .primary-action { display: none; }

.edit-head {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--tg-secondary);
  margin-bottom: 12px;
}

.edit-head .who { font-size: 14px; font-weight: 650; margin-bottom: 6px; }

.edit-head .msg {
  margin: 4px 0;
  font-size: 13px;
  color: var(--tg-hint);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.edit-area { min-height: 140px; line-height: 1.45; }

/* ---------------------------------------------------------------- history */
.feed { display: grid; gap: 10px; }

.feed-item {
  padding: 13px 14px;
  border-radius: var(--radius);
  background: var(--tg-section);
  box-shadow: var(--shadow);
}

.feed-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.feed-what { font-size: 14px; font-weight: 600; }
.feed-time { font-size: 12px; color: var(--tg-hint); flex: none; }
.feed-who { margin-top: 3px; font-size: 13px; color: var(--tg-hint); }

/* ---------------------------------------------------------------- states */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 64px 24px;
  color: var(--tg-hint);
}

.empty .glyph {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--tg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  font-size: 26px;
}

.empty h2 { margin: 0 0 6px; font-size: 16px; color: var(--tg-text); font-weight: 650; }
.empty p { margin: 0; font-size: 14px; max-width: 260px; }

.skeleton { display: grid; gap: 10px; margin-top: 12px; }

.sk {
  height: 84px;
  border-radius: var(--radius);
  background: var(--skel);
  animation: pulse 1.2s ease-in-out infinite;
}

.sk.head { height: 16px; width: 90px; margin: 12px 2px 0; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.notice {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--tg-secondary);
  color: var(--tg-hint);
  font-size: 14px;
  margin-bottom: 12px;
}

/* ---------------------------------------------------------------- tabbar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--tg-bg);
  border-top: 1px solid var(--line);
}

.tabbar a {
  flex: 1;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--tg-hint);
  font-size: 11px;
  font-weight: 550;
}

.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--tg-link); }

/* ---------------------------------------------------------------- toast + sheet */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 18px);
  transform: translateX(-50%);
  z-index: 60;
  max-width: 86vw;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(30, 32, 38, 0.94);
  color: #fff;
  font-size: 14px;
  text-align: center;
}

.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  background: rgba(8, 10, 14, 0.45);
}

.sheet {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--tg-bg);
}

.sheet h2 { margin: 0 0 8px; font-size: 19px; font-weight: 680; }
.sheet p { margin: 0 0 14px; font-size: 14px; color: var(--tg-hint); line-height: 1.45; }
.sheet .row { display: grid; gap: 10px; margin-top: 12px; }
.sheet .btn.danger {
  background: var(--tg-destructive);
  color: #fff;
  border-color: transparent;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  font-size: 15px;
  cursor: pointer;
}

.checkline input {
  width: 22px;
  height: 22px;
  accent-color: var(--tg-accent);
}

@media (min-width: 520px) {
  .time-grid { grid-template-columns: repeat(5, 1fr); }
}
