:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --today: #1d4ed8;
  --hour-height: 48px;
  --visible-hours: 18; /* 6am–midnight */
  --header-height: 56px;
  --all-day-min-height: 36px;
  --day-width: 180px;
  --axis-width: 72px;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
}

.app {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.1rem 0.85rem;
  background: #121a26;
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.2rem 0.55rem 0.35rem;
  color: var(--text);
  text-decoration: none;
}

.sidebar-title {
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.sidebar-tag {
  color: var(--muted);
  font-size: 0.75rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.nav-link {
  display: block;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
}

.nav-link:hover {
  background: var(--surface-2);
}

.nav-link.active {
  background: #1e3a5f;
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 600;
}

.nav-toggle {
  display: none;
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 45;
  width: 2.35rem;
  height: 2.35rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
}

.sidebar-backdrop {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.field input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font: inherit;
}

.watch-shell {
  flex: 1;
  min-height: 0;
  padding: 1rem 1.25rem 1.5rem;
}

.watch-lobby {
  display: grid;
  place-items: start center;
  padding-top: 2rem;
}

.lobby-layout {
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 800px) {
  .lobby-layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.lobby-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.lobby-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.lobby-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.lobby-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.lobby-actions input {
  flex: 1;
  min-width: 8rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  font: inherit;
  text-transform: uppercase;
}

.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.room-row {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.room-row:hover {
  border-color: var(--accent);
}

.room-row-code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  letter-spacing: 0.1em;
  font-weight: 650;
}

.room-row-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.watch-room {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1rem;
  align-items: start;
}

.player-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.player-frame iframe,
.player-frame video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.player-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 1.5rem;
  text-align: center;
}

.video-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.video-bar input {
  flex: 1;
  min-width: 12rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font: inherit;
}

.watch-side {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: calc(100vh - 8.5rem);
  overflow: auto;
}

.library-status {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.2rem 0 0.45rem;
}

.library-crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.3rem;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.crumb {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
}

.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.library-item {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.library-item:hover {
  border-color: var(--accent);
}

.library-item.folder {
  color: var(--muted);
}

.resume-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 0;
  background: rgba(2, 6, 23, 0.62);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  cursor: pointer;
}

.watch-side h2 {
  margin: 0;
  font-size: 0.95rem;
}

.room-code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  letter-spacing: 0.12em;
  font-size: 1.15rem;
  font-weight: 650;
}

.participant-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.participant-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.88rem;
}

.host-badge {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hidden {
  display: none !important;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: linear-gradient(180deg, #152033 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  background: #0ea5e9;
  border-color: #0284c7;
  color: #041018;
  font-weight: 600;
}

.range-label {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.range-label input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: #121a26;
}

.range-text {
  font-weight: 600;
  min-width: 16rem;
}

.source-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  line-height: 1.2;
}

.chip:hover:not(:disabled) {
  border-color: var(--accent);
}

.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chip .dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.chip.error {
  border-color: #b91c1c;
  color: #fca5a5;
}

.chip.disabled,
.chip.config-off {
  opacity: 0.45;
  cursor: not-allowed;
}

/* User-toggled off (still configured) */
.chip.toggled-off {
  opacity: 0.45;
  color: var(--muted);
  text-decoration: line-through;
  background: #121820;
}

.chip.toggled-off .dot {
  opacity: 0.35;
  filter: grayscale(1);
}

.status {
  color: var(--muted);
  font-size: 0.85rem;
}

.status.error {
  color: #fca5a5;
}

.calendar-shell {
  flex: 1;
  min-height: 0;
  padding: 0.75rem 1rem 1rem;
}

.calendar-container {
  display: flex;
  height: calc(100vh - 160px);
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--surface);
  position: relative;
}

.time-axis {
  width: var(--axis-width);
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 4;
  background: #152033;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.time-axis-header {
  position: sticky;
  top: 0;
  z-index: 5;
  height: var(--header-height);
  flex-shrink: 0;
  background: #152033;
  border-bottom: 1px solid var(--border);
}

.time-axis-allday {
  position: sticky;
  top: var(--header-height);
  z-index: 5;
  min-height: var(--all-day-min-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.25rem 0.4rem 0.25rem 0.2rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  background: #1a2740;
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.time-axis-hours {
  flex: 0 0 auto;
}

.time-label {
  height: var(--hour-height);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 0 0.4rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  border-top: 1px solid transparent;
  transform: translateY(-0.45rem);
}

.calendar {
  display: flex;
  min-width: max-content;
  align-items: stretch;
}

.day-column {
  position: relative;
  width: var(--day-width);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: calc(var(--header-height) + var(--all-day-min-height) + (var(--visible-hours) * var(--hour-height)));
}

.day-column.weekend .day-timed {
  background-color: rgba(15, 23, 42, 0.45);
}

.day-column.today .day-timed {
  background-color: rgba(29, 78, 216, 0.12);
}

.day-header {
  position: sticky;
  top: 0;
  z-index: 3;
  height: var(--header-height);
  flex-shrink: 0;
  padding: 0.45rem 0.4rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: #152033;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
}

.day-header .weekday {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.day-header .date {
  font-weight: 650;
  font-size: 0.95rem;
}

.day-column.today .day-header {
  background: #1e3a5f;
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* Dedicated all-day row under the date headers */
.all-day-row {
  position: sticky;
  top: var(--header-height);
  z-index: 3;
  min-height: var(--all-day-min-height);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px;
  background: #1a2740;
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.day-column.today .all-day-row {
  background: #1c3050;
}

.day-column.weekend .all-day-row {
  background: #172236;
}

.all-day-row .event {
  position: relative;
  left: auto;
  right: auto;
  top: auto;
  height: auto;
  min-height: 1.45rem;
  margin: 0;
}

.day-timed {
  position: relative;
  flex: 0 0 auto;
  height: calc(var(--visible-hours) * var(--hour-height));
  background:
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent calc(var(--hour-height) - 1px),
      rgba(148, 163, 184, 0.12) calc(var(--hour-height) - 1px),
      rgba(148, 163, 184, 0.12) var(--hour-height)
    );
}

.event {
  position: absolute;
  left: 4px;
  right: 4px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  padding: 0.2rem 0.35rem;
  font-size: 0.72rem;
  line-height: 1.25;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  color: #0b1220;
  background: #86efac;
}

.event:hover {
  filter: brightness(1.05);
  z-index: 4;
}

.event.event-birthday {
  box-shadow: 0 0 0 1px rgba(244, 114, 182, 0.55), 0 1px 2px rgba(0, 0, 0, 0.25);
}

.event .celebration-badge {
  float: right;
  margin: 0 0 0 0.2rem;
  font-size: 0.95rem;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
}

.event strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event .meta,
.event .location,
.event .details {
  color: rgba(15, 23, 42, 0.82);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event .location {
  font-weight: 600;
}

.event .details {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  opacity: 0.92;
}

/* Short blocks: keep title/time/location, hide long details */
.event:not(.event-all-day) .details {
  -webkit-line-clamp: 3;
}

.all-day-row .event .details {
  -webkit-line-clamp: 2;
  white-space: normal;
}

.all-day-row .event {
  min-height: 1.45rem;
  max-height: none;
}

.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #f43f5e;
  z-index: 5;
  pointer-events: none;
}

.now-line::before {
  content: "";
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f43f5e;
}

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.65);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 1rem;
}

.modal-card {
  width: min(480px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.25rem 1rem;
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.modal-card h2 {
  margin: 0 1.5rem 0.75rem 0;
  font-size: 1.15rem;
}

.modal-close {
  position: absolute;
  top: 0.55rem;
  right: 0.7rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  margin: 0;
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.45rem 0.75rem;
  font-size: 0.9rem;
}

.modal-body dt {
  color: var(--muted);
}

.modal-body dd {
  margin: 0;
  word-break: break-word;
}

.modal-body a {
  color: var(--accent);
}

.modal-description {
  white-space: pre-wrap;
  line-height: 1.4;
}

.empty-state {
  position: absolute;
  inset: var(--header-height) 0 0 var(--axis-width);
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
  z-index: 1;
}

@media (max-width: 900px) {
  .watch-room {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  :root {
    --day-width: 140px;
    --hour-height: 40px;
  }

  .app-header {
    align-items: flex-start;
    padding-left: 3.4rem;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 44;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 43;
    background: rgba(2, 6, 23, 0.55);
  }

  .sidebar-backdrop[hidden] {
    display: none;
  }
}
