:root {
  --bg: #0b0f17;
  --bg-card: #131926;
  --bg-elevated: #1c2436;
  --border: #232d42;
  --border-focus: #3b82f6;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --green-glow: rgba(16, 185, 129, 0.3);
  --radius: 8px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
  min-height: 100vh;
  padding: 1rem;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.25rem;
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.user-select-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.user-select-bar label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.input-select, .input-text {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.input-select:focus, .input-text:focus {
  border-color: var(--border-focus);
}

.save-status {
  font-size: 0.78rem;
  color: #10b981;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s;
}

.save-status.visible {
  opacity: 1;
}

/* Admin Banner */
.admin-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

/* Summary Bar */
.summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

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

.participants-list .label {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chips-container {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.person-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s;
}

.person-chip.active {
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px #3b82f6;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.chip-del-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0 0.2rem;
  margin-left: 0.2rem;
}

.chip-del-btn:hover {
  filter: brightness(1.2);
}

.best-overlap-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: #6ee7b7;
}

/* Quick Bar */
.quick-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.82rem;
  padding: 0 0.25rem;
}

.editing-label strong {
  color: #38bdf8;
}

.quick-actions {
  display: flex;
  gap: 0.35rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit;
  transition: all 0.15s;
}

.btn-primary {
  background: #2563eb;
  color: white;
}
.btn-primary:hover { background: #1d4ed8; }

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: #263147; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text); }

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
}

/* Calendar Card & Grid */
.calendar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - 240px);
  min-height: 500px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  position: relative;
}

.grid-container {
  display: grid;
  grid-template-columns: 75px repeat(7, minmax(110px, 1fr));
  min-width: 820px;
  user-select: none;
}

/* Header Cells */
.col-header {
  background: var(--bg-elevated);
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.5rem 0.25rem;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 20;
}

.col-header:first-child {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 30;
  background: var(--bg-elevated);
}

.col-header:last-child {
  border-right: none;
}

.col-header .day-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.col-header .day-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* Time axis */
.time-label {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  font-size: 0.72rem;
  font-family: ui-monospace, monospace;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  position: sticky;
  left: 0;
  z-index: 15;
}

/* Slot Cell */
.grid-slot {
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  height: 32px;
  background: #0f1420;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
  gap: 2px;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-x pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.grid-slot:hover {
  filter: brightness(1.2);
}

.grid-slot.touch-pressing {
  outline: 2px solid #38bdf8;
  outline-offset: -2px;
  background: rgba(56, 189, 248, 0.25) !important;
}

.grid-slot:last-child {
  border-right: none;
}

/* Overlap background levels */
.grid-slot.overlap-all {
  background: rgba(16, 185, 129, 0.35);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.6);
}

.grid-slot.overlap-some {
  background: rgba(59, 130, 246, 0.22);
}

.grid-slot.overlap-few {
  background: rgba(99, 102, 241, 0.14);
}

/* Coloured ribbons inside slot */
.slot-ribbons {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  gap: 2px;
}

.ribbon {
  flex: 1;
  height: 100%;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.star-icon {
  position: absolute;
  right: 3px;
  top: 2px;
  font-size: 0.65rem;
  pointer-events: none;
}

/* Tooltip */
.hover-tooltip {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  display: none;
  z-index: 1000;
}

/* Responsive */
@media (max-width: 768px) {
  body { padding: 0.5rem; }
  .top-bar { padding: 0.6rem 0.75rem; }
  .logo h1 { font-size: 1.1rem; }
  .time-label {
    height: 38px;
    font-size: 0.72rem;
  }
  .grid-slot {
    height: 38px;
  }
  .ribbon {
    font-size: 0.7rem;
  }
}
