:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #151923;
  --muted: #5d6472;
  --line: #d9dfeb;
  --soft-line: #edf0f6;
  --accent: #1c6657;
  --shadow: 0 10px 30px rgba(21, 25, 35, 0.09);
  --radius: 8px;
  --slot-height: 44px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(246, 247, 251, 0.78) 180px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 0 12px 32px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -12px;
  padding: 12px 12px 10px;
  background: rgba(246, 247, 251, 0.94);
  border-bottom: 1px solid rgba(217, 223, 235, 0.82);
  backdrop-filter: blur(16px);
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0;
}

.icon-button,
.ghost-button,
.segment,
.chip,
.sheet-action {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-button {
  width: 40px;
  font-size: 20px;
  line-height: 1;
}

.day-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.day-tab {
  min-width: 0;
  min-height: 44px;
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.day-tab strong,
.day-tab span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-tab strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.1;
}

.day-tab span {
  margin-top: 3px;
  font-size: 11px;
}

.day-tab.is-active {
  border-color: rgba(28, 102, 87, 0.5);
  background: #e8f3f0;
  color: #24594f;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 8px;
  margin-top: 10px;
}

input[type="search"],
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}

input[type="search"] {
  padding: 0 12px;
}

select {
  padding: 0 8px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(220px, 58vw);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.segment {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.segment.is-active {
  background: #202635;
  color: #fff;
}

.ghost-button {
  padding: 0 12px;
  color: var(--muted);
}

.ghost-button.is-active {
  border-color: rgba(179, 38, 30, 0.4);
  background: #fff0ee;
  color: #b3261e;
}

.type-chips {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.type-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  white-space: nowrap;
}

.chip.is-active {
  border-color: color-mix(in srgb, var(--chip-color) 65%, #ffffff);
  background: color-mix(in srgb, var(--chip-color) 14%, #ffffff);
  color: var(--ink);
}

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.summary-pill {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.timeline-panel {
  margin-bottom: 24px;
}

.day-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0 8px;
  padding: 10px 0 4px;
}

.day-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.day-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.timeline {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr);
  gap: 8px;
  position: relative;
}

.time-rail,
.track {
  position: relative;
  min-height: 80px;
}

.track {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(90, 100, 120, 0.15) 0,
      rgba(90, 100, 120, 0.15) 1px,
      transparent 1px,
      transparent var(--slot-height)
    ),
    #ffffff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.time-label {
  position: absolute;
  right: 2px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.collapsed-gap {
  position: absolute;
  left: 0;
  right: 0;
  display: grid;
  place-items: center;
  border-top: 1px dashed #c5ccd9;
  border-bottom: 1px dashed #c5ccd9;
  background: repeating-linear-gradient(135deg, #f2f4f8, #f2f4f8 6px, #e8ecf4 6px, #e8ecf4 12px);
  color: #5d6472;
  font-size: 12px;
}

.timeline-flow {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 0 6px;
}

.flow-time {
  min-height: var(--slot-height);
  padding-top: 6px;
  border-top: 1px solid var(--soft-line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
}

.flow-time strong,
.flow-time span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flow-time strong {
  color: var(--ink);
  font-size: 11px;
}

.flow-time span {
  margin-top: 4px;
}

.flow-gap {
  display: grid;
  min-height: 34px;
  margin: 4px 0;
  place-items: center;
  border: 1px dashed #c5ccd9;
  border-radius: var(--radius);
  background: repeating-linear-gradient(135deg, #f2f4f8, #f2f4f8 6px, #e8ecf4 6px, #e8ecf4 12px);
  color: var(--muted);
  font-size: 12px;
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(var(--slot-columns, 3), minmax(0, 1fr));
  gap: 6px;
  min-height: var(--slot-height);
  padding: 4px 0 8px;
  border-top: 1px solid var(--soft-line);
}

.slot-card {
  position: relative;
  min-width: 0;
  min-height: 92px;
  padding: 7px;
  border: 1px solid color-mix(in srgb, var(--event-color) 46%, #ffffff);
  border-left: 4px solid var(--event-color);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--event-color) 9%, #ffffff);
  box-shadow: 0 4px 12px rgba(21, 25, 35, 0.1);
  overflow: hidden;
  text-align: left;
}

.slot-card.is-group {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.2)),
    color-mix(in srgb, var(--event-color) 12%, #ffffff);
}

.slot-card.is-favorite::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #b3261e;
}

.slot-time {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.05;
}

.slot-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.16;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.slot-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 5px;
  max-height: 36px;
  overflow: hidden;
}

.count-pill {
  max-width: 100%;
  padding: 2px 4px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--pill-color) 12%, #ffffff);
  color: color-mix(in srgb, var(--pill-color) 80%, #151923);
  font-size: 9px;
  font-weight: 800;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-preview,
.slot-location {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  -webkit-box-orient: vertical;
}

.slot-preview {
  margin-top: 5px;
  -webkit-line-clamp: 2;
}

.slot-location {
  margin-top: 4px;
  -webkit-line-clamp: 1;
}

.event-card {
  position: absolute;
  min-width: 0;
  padding: 7px 7px 6px;
  border: 1px solid color-mix(in srgb, var(--event-color) 46%, #ffffff);
  border-left: 4px solid var(--event-color);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--event-color) 9%, #ffffff);
  box-shadow: 0 4px 12px rgba(21, 25, 35, 0.12);
  overflow: hidden;
  text-align: left;
}

.event-card.is-overflow {
  outline: 1px dashed rgba(21, 25, 35, 0.28);
}

.event-card.is-favorite::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #b3261e;
}

.event-time {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.event-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.16;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.event-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.1;
}

.conflict-dot {
  display: inline-flex;
  min-width: 18px;
  justify-content: center;
  padding: 1px 4px;
  border-radius: 999px;
  background: rgba(21, 25, 35, 0.08);
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
}

.list-view {
  display: grid;
  gap: 10px;
}

.time-group {
  display: grid;
  gap: 6px;
}

.time-group h3 {
  position: sticky;
  top: 222px;
  z-index: 3;
  margin: 0;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  font-size: 12px;
  backdrop-filter: blur(12px);
}

.list-card {
  width: 100%;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--event-color) 36%, #ffffff);
  border-left: 4px solid var(--event-color);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
}

.list-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 1.2;
}

.list-card span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 28px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.detail-sheet {
  width: min(100vw, 760px);
  max-width: none;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.detail-sheet::backdrop {
  background: rgba(21, 25, 35, 0.38);
}

.detail-card {
  max-height: min(82vh, 720px);
  overflow: auto;
  padding: 14px;
  border-radius: 8px 8px 0 0;
  background: var(--panel);
  box-shadow: 0 -16px 40px rgba(21, 25, 35, 0.2);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sheet-title {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: 0;
}

.sheet-original {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.sheet-close {
  flex: 0 0 auto;
  width: 36px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-size: 20px;
}

.sheet-grid {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.sheet-field {
  display: grid;
  gap: 3px;
  padding: 9px;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
  background: #fbfcff;
}

.sheet-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.sheet-field strong,
.sheet-field p {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
}

.sheet-summary {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
}

.tag {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
}

.sheet-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.slot-list {
  display: grid;
  gap: 8px;
}

.slot-list-item {
  width: 100%;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--event-color) 36%, #ffffff);
  border-left: 4px solid var(--event-color);
  border-radius: var(--radius);
  background: #fff;
  text-align: left;
}

.slot-list-item strong,
.slot-list-item span {
  display: block;
}

.slot-list-item strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.slot-list-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.sheet-action {
  display: grid;
  place-items: center;
  min-height: 42px;
  color: var(--ink);
  text-decoration: none;
}

.sheet-action.primary {
  border-color: rgba(28, 102, 87, 0.35);
  background: #e8f3f0;
  color: #174f43;
}

@media (min-width: 680px) {
  .app-shell {
    padding-inline: 18px;
  }

  .topbar {
    margin-inline: -18px;
    padding-inline: 18px;
  }

  .event-title {
    font-size: 12px;
  }

  .event-time,
  .event-meta {
    font-size: 11px;
  }
}
