/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0f0f18;
  --surface:      #1a1a2e;
  --surface2:     #22223a;
  --border:       #2e2e4a;
  --text:         #d0d0e8;
  --text-dim:     #7070a0;
  --accent:       #5a5aff;
  --accent-light: #8888ff;
  --selected-bg:  #2d2d6e;
  --selected-border: #7070ff;
  --conflict-border: #ff4444;
  --conflict-bg:  #3a1a1a;
  --non-band-bg:  #1e1e2a;
  --non-band-text:#6060a0;
  --header-h:     56px;
  --tabs-h:       42px;
  --time-gutter:  56px;
  --col-w:        200px;
  --px-per-min:   1.5;        /* grid pixels per schedule minute */
  --day-start-h:   9;         /* schedule starts at 09:00 (Campsite opens at 09:30) */
  --day-end-h:    27;         /* schedule ends at 03:00 next day (=27h) */
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
}

.header-left { display: flex; align-items: baseline; gap: 10px; }

h1 { font-size: 16px; font-weight: 700; color: var(--accent-light); letter-spacing: .02em; }

.header-sub { font-size: 12px; color: var(--text-dim); }

.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Name prompt ──────────────────────────────────────────────────── */
.name-prompt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.name-prompt-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px 20px;
  width: 260px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.name-prompt-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-light);
}

.name-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
.name-input:focus { border-color: var(--accent); }

.btn-name-ok {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 7px 0;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-name-ok:hover { background: var(--accent-light); }

/* ── Presence dots ────────────────────────────────────────────────── */
.presence-list { display: flex; gap: 5px; align-items: center; }

.presence-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  cursor: default;
  transition: border-color .2s;
}

.presence-dot-me { border-color: rgba(255, 255, 255, .65); }

.btn-reset {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-reset:hover { color: var(--conflict-border); border-color: var(--conflict-border); }

.btn-editlink {
  background: transparent;
  color: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-editlink:hover { background: var(--selected-bg); }

.btn-share {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-share:hover { background: var(--accent-light); }

.share-result {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.share-result.hidden { display: none; }

#share-url-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  width: 280px;
}

.btn-copy {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.btn-copy:hover { border-color: var(--accent); color: var(--accent-light); }

.readonly-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 4px;
  padding: 3px 9px;
  letter-spacing: .05em;
  text-transform: uppercase;
}

/* ── Day tabs ─────────────────────────────────────────────────────── */
.day-tabs {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  height: var(--tabs-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 4px;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: 5px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); border-color: var(--border); }
.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Timetable container ──────────────────────────────────────────── */
main { padding: 16px; overflow-x: auto; }

.loading-msg { color: var(--text-dim); padding: 24px; }

.day-grid-wrapper { display: none; }
.day-grid-wrapper.active { display: block; }

/* Stage column header row */
.stage-headers {
  display: flex;
  margin-left: var(--time-gutter);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.stage-header {
  width: var(--col-w);
  flex-shrink: 0;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-light);
  letter-spacing: .04em;
  text-transform: uppercase;
  border-right: 1px solid var(--border);
}
.stage-header:last-child { border-right: none; }

/* Grid area */
.day-grid {
  position: relative;
  /* width = gutter + 4 stage cols */
  width: calc(var(--time-gutter) + 4 * var(--col-w));
  /* height set by JS based on time span */
}

/* Hour tick marks */
.hour-label {
  position: absolute;
  left: 0;
  width: var(--time-gutter);
  font-size: 10px;
  color: var(--text-dim);
  text-align: right;
  padding-right: 6px;
  line-height: 1;
  transform: translateY(-50%);
}

.hour-line {
  position: absolute;
  left: var(--time-gutter);
  right: 0;
  height: 1px;
  background: var(--border);
  opacity: .5;
}

/* Slot cards */
.slot-card {
  position: absolute;
  padding: 4px 6px;
  border-radius: 4px;
  border: 2px solid transparent;
  background: var(--surface2);
  color: var(--text);
  font-size: 11px;
  line-height: 1.3;
  overflow: hidden;
  min-height: 24px;
  transition: background .12s, border-color .12s;
  box-sizing: border-box;
}

.slot-card .slot-band {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-card .slot-time {
  color: var(--text-dim);
  font-size: 10px;
  margin-top: 1px;
  white-space: nowrap;
}

/* editable */
.slot-card.editable {
  cursor: pointer;
}
.slot-card.editable:hover {
  background: #2a2a48;
  border-color: var(--border);
}

/* selected */
.slot-card.selected {
  background: var(--selected-bg);
  border-color: var(--selected-border);
  color: #fff;
}
.slot-card.selected .slot-time { color: #a0a0d0; }

/* conflict */
.slot-card.conflict {
  border-color: var(--conflict-border) !important;
  background: var(--conflict-bg) !important;
}

/* non-band (no end time = special event) */
.slot-card.non-band {
  background: var(--non-band-bg);
  color: var(--non-band-text);
  border-style: dashed;
  border-color: var(--border);
  font-style: italic;
}
.slot-card.non-band .slot-band { font-weight: 400; }

/* stage column separators (vertical lines behind cards) */
.col-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
  opacity: .4;
}

/* ── Empty state ──────────────────────────────────────────────────── */
.empty-selection {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-dim);
  pointer-events: none;
}

/* ── Selection counter ────────────────────────────────────────────── */
#selection-count {
  font-size: 12px;
  color: var(--text-dim);
}

/* ── Share choice modal ───────────────────────────────────────────── */
.share-choice-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.share-choice-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 20px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.share-choice-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-light);
  text-align: center;
  margin-bottom: 4px;
}

.share-choice-opt {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--text);
  transition: border-color .15s, background .15s;
  gap: 3px;
}
.share-choice-opt:hover { border-color: var(--accent); background: var(--selected-bg); }

.share-opt-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.share-opt-desc {
  font-size: 11px;
  color: var(--text-dim);
}

.share-choice-cancel {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 6px;
  text-align: center;
  transition: color .15s;
  align-self: center;
}
.share-choice-cancel:hover { color: var(--text); }

.share-choice-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  width: 100%;
  outline: none;
}
.share-choice-input:focus { border-color: var(--accent); }

.share-choice-loading {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 20px;
}

/* ── List view (mobile-only; hidden on desktop) ───────────────────── */
.day-list-wrapper { display: none; }

.list-stage-section { margin-bottom: 20px; }

.list-stage-header {
  background: var(--surface2);
  color: var(--accent-light);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  margin-bottom: 2px;
}

.list-slot-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  min-height: 44px;
  transition: background .12s, border-left-color .12s;
}

.list-slot-card.editable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.list-slot-card.editable:active { background: #2a2a48; }

.list-slot-card.selected {
  background: var(--selected-bg);
  border-left-color: var(--selected-border);
}

.list-slot-card.conflict {
  background: var(--conflict-bg) !important;
  border-left-color: var(--conflict-border) !important;
}

.list-slot-card.non-band { background: var(--non-band-bg); }

.ls-time {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 90px;
  flex-shrink: 0;
}

.ls-band {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.list-slot-card.selected .ls-band { color: #fff; }
.list-slot-card.selected .ls-time { color: #a0a0d0; }
.list-slot-card.non-band .ls-band { font-weight: 400; color: var(--non-band-text); font-style: italic; }
.list-slot-card.non-band .ls-time { color: var(--non-band-text); }

/* ── Mobile action bar (hidden on desktop) ────────────────────────── */
.mobile-bar { display: none; }

/* ── Mobile link sheet (JS-injected, slides up above action bar) ──── */
.mobile-link-sheet {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  left: 0;
  right: 0;
  z-index: 95;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideUp .18s ease;
}

.mobile-link-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mobile-link-sheet-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent-light);
}

.mobile-link-sheet-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.mobile-link-sheet-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  width: 100%;
  outline: none;
}
.mobile-link-sheet-input:focus { border-color: var(--accent); }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Mobile breakpoint (≤ 639px) ─────────────────────────────────── */
@media (max-width: 639px) {
  /* Header: hide subtitle and all action buttons */
  .header-sub { display: none; }
  header { padding: 0 12px; gap: 8px; }
  .header-right .btn-reset,
  .header-right .btn-editlink,
  .header-right .btn-share,
  .header-right .share-result { display: none !important; }
  .header-right { flex-wrap: nowrap; overflow: hidden; min-width: 0; gap: 6px; }

  /* Day tabs: horizontal scroll strip */
  .day-tabs {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 8px;
    gap: 2px;
  }
  .day-tabs::-webkit-scrollbar { display: none; }
  .tab-btn { padding: 5px 12px; flex-shrink: 0; }

  /* Swap grid → list */
  .day-grid-wrapper,
  .day-grid-wrapper.active { display: none !important; }
  .day-list-wrapper.active { display: block; }

  /* Main: remove horizontal scroll (list doesn't need it), leave room for bar */
  main {
    overflow-x: visible;
    padding: 8px 0 calc(60px + env(safe-area-inset-bottom, 0px) + 8px);
  }

  /* Stage headers: tap to scroll, highlight active stage */
  .stage-header {
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s, color .15s;
    font-size: 10px;
    padding: 6px 6px;
  }
  .stage-header.active-stage {
    background: var(--selected-bg);
    color: #fff;
  }

  /* Mobile action bar */
  .mobile-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 90;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-bar-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 56px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s;
  }
  .mobile-bar-btn:active { color: var(--accent-light); }

  .mobile-bar-icon {
    font-size: 20px;
    line-height: 1;
  }

  .mobile-bar-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .02em;
  }

  /* Name prompt: use more of the screen width */
  .name-prompt-dialog { width: calc(100vw - 48px); }

  /* Empty state: lift above mobile bar */
  .empty-selection {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}
