:root {
  --bg: #f5f4f1;
  --card: #ffffff;
  --ink: #2b2b2b;
  --muted: #777;
  --line: #e3e0da;
  --accent: #d65a4a;
  --accent-dark: #b8463a;
  --stay: #4a90d6;
  --stay-bg: #e3f0fb;
  --blocked: #888;
  --blocked-bg: #ececec;
  --conflict: #e0a800;
  --conflict-bg: #fff4d6;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.55em 1em;
  background: var(--line);
  color: var(--ink);
  transition: background 0.15s, transform 0.05s;
}
button:active {
  transform: translateY(1px);
}
button.primary {
  background: var(--accent);
  color: #fff;
}
button.primary:hover {
  background: var(--accent-dark);
}
button.ghost {
  background: transparent;
  color: var(--ink);
}
button.ghost:hover {
  background: var(--line);
}
button.ghost.small {
  font-size: 0.85em;
  padding: 0.4em 0.7em;
}
button.danger {
  background: var(--danger);
  color: #fff;
}

input,
select,
textarea {
  font: inherit;
  width: 100%;
  padding: 0.55em 0.7em;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
textarea {
  resize: vertical;
}

.muted {
  color: var(--muted);
}
.error {
  color: var(--danger);
  font-size: 0.9em;
  margin: 0.3em 0 0;
}
.hint {
  font-size: 0.8em;
  color: var(--muted);
  margin: 0.2em 0 0.6em;
}

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-card h1 {
  margin: 0 0 0.3em;
}
.login-card input {
  margin: 1rem 0;
}
.login-card button {
  width: 100%;
}

/* ---- App layout ---- */
.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar h1 {
  margin: 0;
  font-size: 1.4rem;
}
.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.timeline-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0 0.5rem;
}
.timeline-bar h2 {
  margin: 0;
  font-size: 1.1rem;
}
.timeline-bar button {
  margin-left: auto;
}

/* ---- Scrolling timeline (horizontal, itch.io game-jam style) ---- */
.timeline {
  position: relative;
  height: 70vh;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.timeline.dragging {
  cursor: grabbing;
  user-select: none;
}
.timeline-inner {
  position: relative;
}

/* Sticky date header (months band + day columns) */
.timeline-header {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #fafafa;
  border-bottom: 1px solid var(--line);
  cursor: grab;
}
.timeline.dragging .timeline-header {
  cursor: grabbing;
}
.tl-month {
  position: absolute;
  top: 0;
  height: 22px;
  display: flex;
  align-items: center;
  padding-left: 7px;
  font-weight: 700;
  font-size: 0.78em;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-left: 2px solid #cfcbc3;
  white-space: nowrap;
  overflow: hidden;
}
.tl-daycol-head {
  position: absolute;
  top: 22px;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 0.62em;
  line-height: 1;
  color: var(--muted);
  border-left: 1px solid var(--line);
}
.tl-daycol-head.weekend {
  background: #f1efea;
}
.tl-daycol-head.month-start {
  border-left: 2px solid #cfcbc3;
}
.tl-daycol-head .dom {
  font-weight: 700;
  font-size: 1.5em;
  color: var(--ink);
}
.tl-daycol-head .wd {
  text-transform: uppercase;
}
.tl-daycol-head.today .dom {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 1.45em;
  height: 1.45em;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Lanes area */
.timeline-lanes {
  position: relative;
  cursor: cell; /* empty space: click/drag to create */
}
.tl-create-ghost {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(214, 90, 74, 0.14);
  border: 1px dashed var(--accent);
  border-radius: 4px;
  pointer-events: none;
  z-index: 5;
}
/* Hover affordance over an empty day column. */
.tl-day-hover {
  position: absolute;
  top: 0;
  bottom: 0;
  display: none;
  background: rgba(214, 90, 74, 0.08);
  border-left: 1px dashed rgba(214, 90, 74, 0.5);
  border-right: 1px dashed rgba(214, 90, 74, 0.5);
  pointer-events: none;
  z-index: 1;
}
.tl-day-hover-plus {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.tl-col {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px solid var(--line);
}
.tl-col.weekend {
  background: #faf9f7;
}
.tl-col.month-start {
  border-left: 2px solid #e0ddd6;
}
.tl-col.conflict {
  background: var(--conflict-bg);
}
.tl-today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  z-index: 2;
}

/* Event bars (horizontal) */
.tl-event {
  position: absolute;
  border-radius: 6px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
  border-left: 4px solid transparent;
  z-index: 3;
  transition: filter 0.12s;
  touch-action: pan-x pan-y;
}
.tl-event:hover {
  filter: brightness(0.96);
  z-index: 6;
}
.tl-event.active {
  cursor: grabbing;
  z-index: 7;
  filter: brightness(0.97);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
}
/* Unsaved (draft) edits get a dashed accent outline. */
.tl-event.dirty {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
/* Resize grips at each end. */
.tl-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 2;
}
.tl-resize.left {
  left: 0;
}
.tl-resize.right {
  right: 0;
}
.tl-event:hover .tl-resize::after {
  content: "";
  position: absolute;
  top: 25%;
  bottom: 25%;
  width: 2px;
  background: rgba(0, 0, 0, 0.25);
}
.tl-resize.left::after {
  left: 2px;
}
.tl-resize.right::after {
  right: 2px;
}
.tl-event.stay {
  background: var(--stay-bg);
  border-left-color: var(--stay);
}
.tl-event.blocked {
  background: var(--blocked-bg);
  border-left-color: var(--blocked);
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 6px,
    rgba(0, 0, 0, 0.04) 6px,
    rgba(0, 0, 0, 0.04) 12px
  );
}
.tl-event-name {
  font-weight: 600;
  font-size: 0.8em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-event-when {
  font-size: 0.72em;
  color: var(--muted);
  white-space: nowrap;
}

/* ---- Unsaved-changes bar + interaction hint ---- */
.change-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 0.6rem 0;
  padding: 0.6em 0.9em;
  background: var(--conflict-bg);
  border: 1px solid #e6d18a;
  border-radius: 8px;
}
#change-summary {
  font-size: 0.9em;
  font-weight: 600;
}
.timeline-hint {
  margin: 0.5rem 0 0;
  font-size: 0.78em;
  color: var(--muted);
}

/* ---- Role badge ---- */
.role-badge {
  display: inline-block;
  font-size: 0.5em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  vertical-align: middle;
  padding: 0.25em 0.6em;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
}
.role-badge.admin {
  background: var(--accent);
  color: #fff;
}

/* ---- Change history modal ---- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 55vh;
  overflow-y: auto;
  margin: 0.5rem 0;
}
.history-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5em 0.6em;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.history-info {
  min-width: 0;
  flex: 1;
}
.history-title {
  font-weight: 600;
  font-size: 0.92em;
}
.history-sub {
  font-size: 0.8em;
  color: var(--muted);
}
.history-row button {
  flex: none;
}
.history-row.undo-pending {
  border-color: var(--accent);
  background: rgba(214, 90, 74, 0.06);
}
.history-row.undo-pending button {
  background: var(--accent);
  color: #fff;
}

/* ---- Review changes modal ---- */
.review-warning {
  background: var(--conflict-bg);
  border: 1px solid #e6d18a;
  border-radius: 8px;
  padding: 0.6em 0.8em;
  margin: 0.5rem 0;
  font-size: 0.88em;
}
.review-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 50vh;
  overflow-y: auto;
  margin: 0.5rem 0;
}
.review-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5em 0.6em;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.review-row.foreign {
  border-color: var(--conflict);
  background: var(--conflict-bg);
}
.review-badge {
  flex: none;
  font-size: 0.68em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.25em 0.5em;
  border-radius: 5px;
  color: #fff;
  margin-top: 0.1em;
}
.review-badge.new {
  background: #3a9e57;
}
.review-badge.edit {
  background: var(--stay);
}
.review-badge.delete {
  background: var(--danger);
}
.review-badge.undo {
  background: var(--accent);
}
.review-info {
  min-width: 0;
}
.review-title {
  font-weight: 600;
}
.review-sub {
  font-size: 0.85em;
  color: var(--muted);
}
.review-foreign {
  font-size: 0.8em;
  font-weight: 600;
  color: var(--accent-dark);
  margin-top: 0.15em;
}

/* ---- Legend ---- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1rem 0;
  font-size: 0.85em;
  color: var(--muted);
}
.legend span {
  display: flex;
  align-items: center;
  gap: 0.4em;
}
.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
}
.swatch.stay {
  background: var(--stay-bg);
  border-left: 3px solid var(--stay);
}
.swatch.blocked {
  background: var(--blocked-bg);
  border-left: 3px solid var(--blocked);
}
.swatch.conflict {
  background: var(--conflict-bg);
  border: 2px solid var(--conflict);
}

/* ---- Upcoming list ---- */
.upcoming {
  margin-top: 1.5rem;
}
.upcoming h3 {
  margin-bottom: 0.5rem;
}
.upcoming ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.upcoming li {
  background: var(--card);
  border-radius: 8px;
  padding: 0.6em 0.8em;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  border-left: 4px solid var(--stay);
}
.upcoming li.blocked {
  border-left-color: var(--blocked);
}
.upcoming li .when {
  color: var(--muted);
  font-size: 0.85em;
  margin-left: auto;
  text-align: right;
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 440px;
  padding: 1.5rem;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h2 {
  margin-top: 0;
}
.modal-card label {
  display: block;
  margin-bottom: 0.8rem;
  font-size: 0.9em;
  font-weight: 600;
}
.modal-card label input,
.modal-card label select,
.modal-card label textarea {
  margin-top: 0.25em;
  font-weight: 400;
}
.row {
  display: flex;
  gap: 0.8rem;
}
.row label {
  flex: 1;
}
.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}
.modal-actions .spacer {
  flex: 1;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 0.8em 1.2em;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 90vw;
  z-index: 20;
  font-size: 0.9em;
}
.toast.warn {
  background: var(--conflict-dark, #946c00);
}

@media (max-width: 560px) {
  .timeline {
    height: 72vh;
  }
  .tl-event-when {
    display: none;
  }
}
