:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --surface: var(--tg-theme-secondary-bg-color, #191c22);
  --text: var(--tg-theme-text-color, #f5f7fa);
  --muted: var(--tg-theme-hint-color, #9aa1aa);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(127, 127, 127, 0.24);
  --calendar-height: calc(100vh - 104px - env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

body { overflow: hidden; }

#appShell {
  min-height: 100vh;
  padding: max(10px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 8px;
}

.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.title {
  margin-top: 1px;
  font-size: 24px;
  line-height: 1;
  font-weight: 800;
}

.actor {
  max-width: 45vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.status {
  display: none;
  margin: 0 0 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.status.visible { display: block; }
.status.error { color: #ff7777; }

#calendar {
  height: var(--calendar-height);
  min-height: 520px;
  background: var(--bg);
  border-radius: 14px;
  overflow: hidden;
}

.fc {
  height: 100%;
  color: var(--text);
  --fc-border-color: var(--line);
  --fc-page-bg-color: var(--bg);
  --fc-neutral-bg-color: var(--surface);
  --fc-today-bg-color: rgba(46, 166, 255, 0.08);
  --fc-now-indicator-color: #ff4d4f;
  font-size: 13px;
}

.fc .fc-toolbar {
  gap: 7px;
  margin: 0 0 8px !important;
}

.fc .fc-toolbar-title {
  color: var(--text);
  font-size: 17px !important;
  font-weight: 800;
}

.fc .fc-button {
  border-radius: 10px !important;
  border: 1px solid var(--line) !important;
  background: var(--surface) !important;
  color: var(--text) !important;
  box-shadow: none !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  padding: 7px 9px !important;
}

.fc .fc-button-active,
.fc .fc-button:active {
  border-color: var(--accent) !important;
  background: var(--accent) !important;
  color: var(--accent-text) !important;
}

.fc .fc-col-header-cell-cushion,
.fc .fc-timegrid-axis-cushion,
.fc .fc-timegrid-slot-label-cushion {
  color: var(--muted);
  text-decoration: none;
}

.fc .fc-col-header-cell-cushion {
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 800;
}

.fc .fc-timegrid-slot {
  height: 2.05em;
}

.fc .fc-timegrid-slot-label {
  font-size: 10px;
}

.fc .fc-event {
  border: 0 !important;
  border-radius: 7px !important;
  padding: 2px 4px !important;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.fc .fc-event-main { color: #fff !important; }

.event-source-own { background: #3b82f6 !important; }
.event-source-mikhail { background: #a855f7 !important; }
.event-source-partner { background: #16a36a !important; }
.event-block {
  background: #5c616b !important;
  opacity: 0.90;
}

.event-card {
  min-width: 0;
  line-height: 1.12;
}

.event-card .event-time {
  font-size: 10px;
  font-weight: 800;
  opacity: 0.9;
}

.event-card .event-car {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.event-card .event-work {
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 10px;
  opacity: 0.92;
}

.modal-backdrop {
  position: fixed;
  z-index: 9999;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(4px);
}

.modal-backdrop.hidden { display: none; }

.sheet {
  width: min(680px, 100%);
  max-height: min(78vh, 760px);
  overflow: auto;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 -8px 34px rgba(0, 0, 0, 0.34);
}

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 99px;
  background: var(--line);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sheet-head h2 {
  margin: 3px 0 0;
  font-size: 22px;
  line-height: 1.12;
}

.detail-time {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 0;
  border-radius: 50%;
  background: rgba(127, 127, 127, 0.18);
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}

.detail-body {
  padding-top: 14px;
}

.detail-row {
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.detail-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.detail-value {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.34;
}

.phone-link {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 2px 2px;
  color: var(--muted);
  font-size: 11px;
}

.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; }
.legend-own { background: #3b82f6; }
.legend-mikhail { background: #a855f7; }
.legend-partner { background: #16a36a; }
.legend-block { background: #5c616b; }

@media (max-width: 560px) {
  :root { --calendar-height: calc(100vh - 95px - env(safe-area-inset-bottom)); }
  #appShell { padding-left: 6px; padding-right: 6px; }
  .topbar { height: 52px; padding-left: 4px; padding-right: 4px; }
  .title { font-size: 21px; }
  .fc .fc-toolbar-title { font-size: 15px !important; }
  .fc .fc-button { padding: 7px 7px !important; }
}
