/* ── Reset ─────────────────────────────────────────────────────────────────── */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme tokens (mapped onto Telegram CSS vars) ──────────────────────────── */
:root {
  --bg:       var(--tg-theme-bg-color, #ffffff);
  --bg-2:     var(--tg-theme-secondary-bg-color, #fafafa);
  --bg-3:     #f5f5f5;
  --text:     var(--tg-theme-text-color, #0a0a0a);
  --muted:    var(--tg-theme-hint-color, #737373);
  --muted-2:  #a3a3a3;
  --border:   #e5e5e5;
  --accent:   var(--tg-theme-button-color, #3390ec);
  --accent-fg:var(--tg-theme-button-text-color, #ffffff);
  --accent-bg:rgba(51,144,236,0.08);
  --green:    #16a34a;
  --shadow:   0 1px 2px rgba(0,0,0,0.04);
}
[data-theme="dark"], .dark {
  --bg-3:    #1f1f1f;
  --border:  #262626;
  --muted-2: #737373;
  --accent-bg: rgba(78,163,240,0.14);
  --shadow:  0 1px 2px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg-2);
  color: var(--text);
  overscroll-behavior: none;
  touch-action: manipulation;
}

.fullscreen-msg {
  display: flex; align-items: center; justify-content: center;
  height: 100vh;
  color: var(--muted);
}

/* ── App shell ─────────────────────────────────────────────────────────────── */
#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  background: var(--bg);
}

/* Mobile / narrow: stack (calendar on top, day on bottom).
   Cap calendar max-height so the day panel and its add button remain visible. */
.cal-panel {
  position: relative;
  flex: 0 0 auto;
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex; flex-direction: column;
}
.day-panel {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  min-width: 0;
  min-height: 0;
}

/* Desktop / wide TG popups: side-by-side. Breakpoint chosen so TG Desktop
   Mini App windows wider than ~560px (after the user drags the popup wider)
   automatically switch to split-pane. */
@media (min-width: 560px) {
  .layout {
    flex-direction: row;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
  .cal-panel {
    width: 220px;
    flex: 0 0 220px;
    max-height: none;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    border-bottom: none;
    background: var(--bg-2);
  }
  .day-panel {
    flex: 1 1 auto;
  }
}

@media (min-width: 900px) {
  .cal-panel { width: 260px; flex: 0 0 260px; }
}

@media (min-width: 1200px) {
  .cal-panel { width: 300px; flex: 0 0 300px; }
}

/* ── Panel header ──────────────────────────────────────────────────────────── */
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}
.panel-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.panel-title-block { min-width: 0; flex: 1; }
.day-summary {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.head-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}
.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover  { background: var(--bg-3); color: var(--text); }
.icon-btn:active { transform: scale(0.95); }

/* ── Mini calendar ─────────────────────────────────────────────────────────── */
.day-headers {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 0 12px;
  flex-shrink: 0;
}
.day-headers span {
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  padding: 4px 0;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Filter button toggle — hidden on desktop split-pane (filters always visible) */
#btn-filters { display: flex; }
.cal-toggle  { display: none; }
@media (min-width: 560px) {
  #btn-filters { display: flex; }   /* keep filter popover trigger on desktop too */
  .cal-toggle  { display: none; }   /* expand toggle is mobile-only */
}
@media (max-width: 559px) {
  .cal-toggle  { display: flex; }
}

/* Filters popover — anchored under the cal-panel header */
.filters-popover {
  position: absolute;
  top: 50px;
  right: 12px;
  z-index: 10;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
}

/* Week strip — single-row date picker shown when calendar is collapsed (mobile) */
.week-strip {
  display: none;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 0 12px 8px;
  gap: 2px;
  flex-shrink: 0;
}
.cal-panel.collapsed .pager-viewport { display: none; }
.cal-panel.collapsed .week-strip { display: grid; }
.cal-panel.collapsed { max-height: none; }

/* Mobile / stacked layout only: when calendar is in full-month mode, hide the
   day list and its header so the screen shows just the calendar + the bottom
   action row. The day list & header surface only in week-strip mode (after the
   user taps a date). */
@media (max-width: 559px) {
  .cal-panel:not(.collapsed) ~ .day-panel #day-list,
  .cal-panel:not(.collapsed) ~ .day-panel .panel-head {
    display: none;
  }
}

/* On desktop split-pane the collapse class is irrelevant — always show the
   full month grid + day list regardless of mobile-collapsed state. */
@media (min-width: 560px) {
  .cal-panel.collapsed .pager-viewport { display: block; }
  .cal-panel.collapsed .week-strip { display: none; }
}

.pager-viewport {
  position: relative;
  overflow: hidden;
  width: 100%;
  flex-shrink: 0;
  touch-action: pan-y;
}
.pager-track {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-start;
  width: 300%;
  will-change: transform;
}
.pager-page {
  flex: 0 0 33.3333%;
  width: 33.3333%;
  min-width: 0;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 0 12px 8px;
  gap: 2px;
  width: 100%;
  box-sizing: border-box;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  min-width: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: 6px;
  position: relative;
  font-size: 12px;
  color: var(--text);
}
.cal-cell.clickable { cursor: pointer; }
.cal-cell.clickable:hover { background: var(--bg-3); }
.cal-cell.past { color: var(--muted); opacity: 0.55; }

.cal-num {
  font-size: 12px;
  line-height: 1;
  font-weight: 500;
}
.cal-cell.today {
  border: 1.5px solid var(--accent);
}
.cal-cell.today .cal-num {
  color: var(--accent);
  font-weight: 700;
}
.cal-cell.selected {
  background: var(--text);
}
.cal-cell.selected .cal-num {
  color: var(--bg);
  font-weight: 600;
}
.cal-cell.selected.today {
  border-color: var(--bg);
}
.cal-cell.selected.today .cal-num {
  color: var(--bg);
}
.cal-dot {
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 2px;
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
}
.cal-cell.selected .cal-dot { background: var(--bg); }

/* ── Filters (inside popover) ──────────────────────────────────────────────── */
.filters-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.filter-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px; height: 16px;
  cursor: pointer;
}

/* ── Day list ──────────────────────────────────────────────────────────────── */
.day-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  text-align: center;
  margin-top: 48px;
  color: var(--muted);
  font-size: 13px;
  padding: 0 16px;
}

/* ── Event card ────────────────────────────────────────────────────────────── */
.event {
  display: flex;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  position: relative;
}
.event:last-child { border-bottom: none; }
.event.clickable { cursor: pointer; }
.event.clickable:hover { background: var(--bg-3); }

.event-marker {
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
  align-self: stretch;
}
.event-marker.past  { background: var(--border); }
.event-marker.green { background: var(--green); }

.event-time {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-width: 50px;
  flex-shrink: 0;
  padding-top: 2px;
}

.event-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.event-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.event-name-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.event-handle {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
.event-handle:hover { text-decoration: underline; }

.event-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.event-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.event-field strong {
  color: var(--text);
  font-weight: 500;
}

.event-comment {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  background: var(--bg-2);
  border-left: 2px solid var(--border);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.event-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--accent);
  text-decoration: none;
  align-self: flex-start;
  word-break: break-all;
}
.event-link:hover { text-decoration: underline; }

/* ── Pills ─────────────────────────────────────────────────────────────────── */
.pill {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill.now {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: transparent;
}
.pill.soon {
  background: var(--bg-3);
  color: var(--text);
  border-color: transparent;
}
.pill.past {
  color: var(--muted);
}

/* ── Add row ───────────────────────────────────────────────────────────────── */
.add-row {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
  width: 100%;
}
.add-row-inner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}
.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.add-btn:hover  { opacity: 0.9; }
.add-btn:active { transform: scale(0.98); }
.add-btn .plus { font-weight: 700; font-size: 16px; line-height: 1; }

.btn-my-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn-my-row:hover  { background: var(--bg-3); }
.btn-my-row:active { transform: scale(0.98); }
.btn-my-row .my-icon { color: var(--accent); font-size: 14px; line-height: 1; }

/* ── Overlays (my interviews + modal) ──────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 768px) {
  .overlay { align-items: center; }
}

.overlay-content {
  background: var(--bg);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (min-width: 768px) {
  .overlay-content { border-radius: 12px; }
}

.overlay-header {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.overlay-header .day-title {
  font-weight: 700;
  font-size: 15px;
}

/* My interviews list items */
.my-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.my-item:last-child { border-bottom: none; }
.my-item-info { min-width: 0; flex: 1; }
.my-item-title { font-weight: 600; font-size: 14px; }
.my-item-time  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.my-item-note  { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.my-item-actions { display: flex; gap: 4px; flex-shrink: 0; }

.btn-icon {
  background: none;
  border: 1px solid transparent;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}
.btn-icon:hover  { background: var(--bg-3); }
.btn-icon:active { transform: scale(0.92); }

/* ── Modal (Add / Edit) ────────────────────────────────────────────────────── */
.modal {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
@media (min-width: 768px) {
  .modal { border-radius: 14px; }
}

.modal h2 {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}

.modal-row.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.modal-hint {
  font-size: 11px;
  color: var(--muted-2);
  font-weight: 400;
  margin-top: 2px;
  line-height: 1.35;
}

.modal input,
.modal textarea {
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  outline: none;
  resize: vertical;
}
.modal input:focus,
.modal textarea:focus {
  border-color: var(--accent);
  background: var(--bg);
}
.modal textarea { min-height: 64px; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 11px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}
.btn-secondary {
  background: var(--bg-3);
  color: var(--text);
}
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-primary:not(:disabled):hover  { opacity: 0.92; }
.btn-secondary:hover { opacity: 0.85; }
