/* ── ChronoHub layout ── */
.ch-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 72px);
  overflow: hidden;
  background: #f8f9fa;
}

/* ── Toolbar ── */
.ch-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 2px solid #dee2e6;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.ch-toolbar-section {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ch-toolbar-label {
  font-size: .75rem;
  color: #6c757d;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.ch-btn {
  padding: 4px 10px;
  font-size: .82rem;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.ch-btn:hover { background: #f1f3f5; }
.ch-btn.active {
  background: #0d6efd;
  color: #fff;
  border-color: #0d6efd;
}
.ch-btn:disabled {
  cursor: not-allowed;
  opacity: .5;
  background: #fff;
  color: #6c757d;
  border-color: #dee2e6;
}
.ch-btn:disabled:hover { background: #fff; }

.ch-btn-primary {
  background: #0d6efd;
  color: #fff;
  border-color: #0d6efd;
}
.ch-btn-primary:hover { background: #0b5ed7; }

.ch-btn-success {
  background: #198754;
  color: #fff;
  border-color: #198754;
}
.ch-btn-success:hover { background: #157347; }

.ch-year-display {
  font-size: .88rem;
  font-weight: 600;
  min-width: 100px;
  text-align: center;
}

.ch-year-input {
  width: 52px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: .8rem;
  font-weight: 600;
  text-align: center;
  color: #343a40;
  background: #fff;
}
.ch-year-input:focus { outline: none; border-color: #4a6cf7; }

.ch-event-yr {
  flex-shrink: 0;
  font-size: .65rem;
  opacity: .65;
  margin-left: 4px;
}

/* ── Matrix ── */
.ch-matrix {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.ch-timeline-inner {
  display: flex;
  align-items: flex-start;
  min-width: max-content;
  min-height: 100%;
}

/* ── Year axis ── */
.ch-year-axis {
  position: sticky;
  left: 0;
  width: 64px;
  flex-shrink: 0;
  background: #fff;
  border-right: 2px solid #dee2e6;
  z-index: 20;
}

.ch-axis-header {
  position: sticky;
  top: 0;
  height: 40px;
  background: #f1f3f5;
  border-bottom: 2px solid #dee2e6;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
}

.ch-axis-body {
  position: relative;
}

.ch-year-tick {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 2px 8px 0;
  font-size: .72rem;
  color: #495057;
  font-weight: 600;
  height: 80px;
  box-sizing: border-box;
}

.ch-year-tick::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  width: 6px;
  height: 1px;
  background: #ced4da;
}

/* ── Column ── */
.ch-column {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid #e9ecef;
  position: relative;
}

.ch-column-header {
  position: sticky;
  top: 0;
  height: 40px;
  background: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  font-size: .8rem;
  font-weight: 700;
  color: #343a40;
}

.ch-column-header-badge {
  font-size: .68rem;
  padding: 1px 6px;
  border-radius: 99px;
  font-weight: 600;
}

.ch-column-body {
  position: relative;
}

.ch-slot-band {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 0;
}

/* ── Grid lines ── */
.ch-gridline {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: #f1f3f5;
  pointer-events: none;
}

/* ── Event card ── */
.ch-event {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 20px;
  border-radius: 3px;
  padding: 0 4px;
  font-size: .72rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  overflow: hidden;
  transition: transform .1s, box-shadow .1s;
  z-index: 5;
}

.ch-event:hover {
  transform: translateX(2px);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  z-index: 6;
}

.ch-event-title {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-edited-dot {
  font-size: .55rem;
  color: #f59e0b;
  margin-left: 3px;
  flex-shrink: 0;
  line-height: 1;
  align-self: center;
}

/* sub-region badge inside global events */
.ch-subbadge {
  display: inline-block;
  font-size: .65rem;
  font-weight: 700;
  line-height: 1;
  padding: 1px 4px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
  flex-shrink: 0;
  white-space: nowrap;
}

/* private events */
.ch-event-private {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1e3a5f;
}

/* group events */
.ch-event-group {
  background: #dcfce7;
  border-color: #22c55e;
  color: #14532d;
}

/* world events — per region */
.ch-event-mainland_china { background: #fee2e2; border-color: #ef4444; color: #7f1d1d; }
.ch-event-taiwan         { background: #dbeafe; border-color: #3b82f6; color: #1e3a5f; }
.ch-event-japan          { background: #ffe4e6; border-color: #e11d48; color: #881337; }
.ch-event-usa            { background: #dcfce7; border-color: #22c55e; color: #14532d; }
.ch-event-asia           { background: #fef3c7; border-color: #f59e0b; color: #78350f; }
.ch-event-europe         { background: #f3e8ff; border-color: #a855f7; color: #4a044e; }
.ch-event-global         { background: #e5e7eb; border-color: #9ca3af; color: #1f2937; }

/* bullet dot */
.ch-event::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: .5;
  margin-right: 5px;
  flex-shrink: 0;
}

/* ── Modal ── */
.ch-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.ch-modal-overlay.open { display: flex; }

.ch-modal-box {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
}

.ch-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 16px;
}

.ch-form-group {
  margin-bottom: 14px;
}

.ch-form-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: #374151;
}

.ch-form-control {
  width: 100%;
  padding: 7px 10px;
  font-size: .88rem;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  box-sizing: border-box;
}

.ch-form-control:focus {
  outline: none;
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}

.ch-form-hint {
  font-size: .73rem;
  color: #6c757d;
  margin-top: 3px;
}

.ch-form-row {
  display: flex;
  gap: 10px;
}

.ch-form-row .ch-form-group { flex: 1; }

.ch-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #f1f3f5;
}

/* ── Speech widget inside Add Event modal (global mode; see #ch-speech-widget) ── */
#ch-speech-widget .speech-controls {
  padding: 4px 8px;
}

/* ── Event detail popover ── */
.ch-popover {
  display: none;
  position: fixed;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  padding: 12px 14px;
  max-width: 300px;
  max-height: calc(100vh - 20px);
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 500;
  font-size: .82rem;
}

.ch-popover.open { display: block; }

.ch-popover-meta { font-weight: 600; font-size: .8rem; color: #374151; margin-bottom: 3px; }
.ch-popover-date { color: #6c757d; font-size: .76rem; margin-bottom: 4px; }
.ch-popover-title { font-weight: 700; font-size: .88rem; margin-bottom: 4px; line-height: 1.4; }
.ch-popover-desc { line-height: 1.5; margin-bottom: 8px; font-size: .82rem; color: #495057; }
.ch-popover-weight { color: #f59e0b; font-size: .82rem; margin-bottom: 6px; letter-spacing: 1px; }

.ch-popover-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Image preview strip (Add Event modal) */
.ch-image-preview-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.ch-image-preview-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #dee2e6;
}

/* Popover image thumbnails */
.ch-popover-images {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.ch-pop-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid #dee2e6;
  cursor: zoom-in;
}


/* ── Column color header bands ── */
.ch-col-personal  .ch-column-header { border-top: 3px solid #3b82f6; }
.ch-col-group     .ch-column-header { border-top: 3px solid #22c55e; }
.ch-col-mainland_china .ch-column-header { border-top: 3px solid #ef4444; }
.ch-col-taiwan    .ch-column-header { border-top: 3px solid #3b82f6; }
.ch-col-usa       .ch-column-header { border-top: 3px solid #22c55e; }
.ch-col-asia      .ch-column-header { border-top: 3px solid #f59e0b; }
.ch-col-europe    .ch-column-header { border-top: 3px solid #a855f7; }
.ch-col-global    .ch-column-header { border-top: 3px solid #9ca3af; }

/* ── Empty / loading states ── */
.ch-empty {
  padding: 40px 16px;
  text-align: center;
  color: #9ca3af;
  font-size: .85rem;
}

.ch-loading {
  text-align: center;
  padding: 60px;
  color: #6c757d;
}

/* ── "Today" marker ── */
.ch-today-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #ef4444;
  opacity: .6;
  pointer-events: none;
  z-index: 4;
}

.ch-today-line::before {
  content: 'Today';
  position: absolute;
  right: 4px;
  top: -18px;
  font-size: .65rem;
  color: #ef4444;
  font-weight: 700;
}

/* ── Event type tabs ── */
.ch-event-type-tabs {
  display: flex;
  gap: 0;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 4px;
}
.ch-type-tab {
  flex: 1;
  padding: 6px 0;
  background: #f8f9fa;
  border: none;
  border-right: 1px solid #dee2e6;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 500;
  color: #495057;
  transition: background .15s;
}
.ch-type-tab:last-child { border-right: none; }
.ch-type-tab:hover { background: #e9ecef; }
.ch-type-tab.active {
  background: #0d6efd;
  color: #fff;
}

/* ── Personal event shared into a group column ── */
.ch-event-personal-shared {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #78350f;
  font-style: italic;
}
.ch-event-author {
  font-size: .62rem;
  opacity: .75;
  margin-left: 4px;
  font-style: normal;
}

/* ── Checkbox list for group sharing ── */
.ch-checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid #dee2e6;
  border-radius: 5px;
  padding: 8px 10px;
  background: #f8f9fa;
}
.ch-checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  cursor: pointer;
}
.ch-checkbox-item input { cursor: pointer; }

/* ── Collapsible toolbar sections (mobile) ── */
.ch-toolbar-label.ch-collapsible-toggle {
  cursor: default;
}

@media (max-width: 640px) {
  .ch-column { width: 180px; }
  .ch-toolbar { padding: 6px 10px; gap: 8px; }

  .ch-mobile-hidden { display: none !important; }

  /* Collapsible: hide child buttons, show on expanded */
  .ch-collapsible .ch-btn { display: none; }
  .ch-collapsible.expanded .ch-btn { display: inline-flex; }

  /* Make the label look tappable */
  .ch-toolbar-label.ch-collapsible-toggle {
    cursor: pointer;
    color: #0d6efd;
    border-bottom: 1px solid currentColor;
    padding-bottom: 1px;
  }
}
