:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #2856d9;
  --primary-soft: #e7edff;
  --tag-bg: #ffffff;
  --tag-text: #182230;
  --danger: #b42318;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  padding: 10px 12px;
}

button:hover {
  filter: brightness(0.96);
}

.app-header {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 18px clamp(16px, 4vw, 36px);
  position: sticky;
  top: 0;
  z-index: 10;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

h2 {
  font-size: 17px;
  margin-bottom: 14px;
}

.app-header p {
  color: var(--muted);
  margin-bottom: 0;
}

.header-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.view-tabs {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  padding: 3px;
}

.tab {
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
}

.tab.active {
  background: var(--primary);
  color: white;
}

.secondary,
.import-button {
  background: #344054;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  display: inline-flex;
  padding: 10px 12px;
}

.import-button {
  font-size: 16px;
  margin-bottom: 0;
}

.sync-status {
  background: #f2f4f7;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 10px;
  white-space: nowrap;
}

.sync-status-on {
  background: #ecfdf3;
  border-color: #abefc6;
  color: #067647;
}

.import-button input {
  display: none;
}

.app-shell {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  padding: 18px clamp(16px, 4vw, 36px) 36px;
}

.left-pane,
.right-pane {
  display: grid;
  gap: 16px;
  align-content: start;
}

.panel,
.filters,
.event-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.entry-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.entry-panel > summary {
  cursor: pointer;
  font-weight: 700;
  padding: 13px 16px;
}

.entry-panel > .panel {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}

.form-note,
.sync-message {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.sync-message {
  margin-bottom: 0;
}

.checkbox-line {
  align-items: center;
  display: flex;
  gap: 8px;
}

.checkbox-line input {
  width: auto;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 10px;
  width: 100%;
}

textarea {
  resize: vertical;
}

.chips,
.event-people,
.event-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  align-items: center;
  background: var(--tag-bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--tag-text);
  display: inline-flex;
  font-size: 13px;
  gap: 5px;
  padding: 5px 9px;
}

.chip button {
  background: transparent;
  color: inherit;
  padding: 0;
}

.chip-button {
  border: 1px solid var(--line);
}

button.chip-button {
  background: var(--tag-bg);
  border-color: var(--line);
  color: var(--tag-text);
  padding: 5px 9px;
}

.chip-button.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.person-chip {
  border-radius: 8px;
  justify-content: space-between;
  width: 100%;
}

.selectable-chips {
  max-height: 142px;
  min-height: 38px;
  overflow: auto;
  padding-right: 2px;
}

.selected-people {
  margin-bottom: 8px;
  min-height: 30px;
}

.filter-empty {
  color: var(--muted);
  font-size: 13px;
}

.filter-picker {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.filter-picker summary {
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}

.filter-picker input {
  margin: 8px 0;
}

#personChips {
  align-content: start;
  display: grid;
  max-height: 180px;
  overflow: auto;
}

.filter-label {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}

.detected {
  color: var(--muted);
  font-size: 14px;
  margin: 4px 0 12px;
}

.subtle-field {
  opacity: 0.72;
}

.filters {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(160px, 1fr) minmax(240px, 1.4fr) repeat(2, minmax(120px, 0.7fr)) auto;
  align-items: end;
}

.filters label {
  margin-bottom: 0;
}

.filters > button {
  background: #344054;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 12px;
}

.list-view.active {
  align-content: start;
}

.list-items {
  display: grid;
  gap: 12px;
}

.event-node-group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  padding: 16px;
}

.event-node-group-single {
  background: #ffffff;
}

.event-node-group-topic {
  background: #f0f9ff;
  border-color: #7dd3fc;
}

.event-node-group-linked {
  background: #f7f3ff;
  border-color: #c4b5fd;
}

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

.event-node-list .event-card {
  border-left: 4px solid var(--primary);
  box-shadow: none;
}

.event-node-group-single .event-card {
  border-left-color: #98a2b3;
}

.event-node-group-topic .event-card {
  border-left-color: #0ea5e9;
}

.event-node-group-linked .event-card {
  border-left-color: #7c3aed;
}

.live-list-section {
  background: #f8fdfb;
  border: 1px solid #b7ebd2;
  border-radius: var(--radius);
  display: grid;
  gap: 10px;
  padding: 16px;
}

.live-list-section h2 {
  font-size: 18px;
  margin: 0;
}

.live-list-hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

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

.live-list-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-left: 4px solid #12b76a;
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 12px;
}

.live-list-card h3 {
  font-size: 16px;
  margin: 0;
}

.live-list-meta,
.live-excerpt,
.live-full p {
  color: var(--text);
}

.live-excerpt,
.live-full p {
  line-height: 1.7;
  margin: 0;
  white-space: pre-wrap;
}

.live-full summary {
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
}

.live-slice-source {
  cursor: text;
}

.live-slice-menu {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(16, 24, 40, 0.18);
  display: grid;
  gap: 4px;
  min-width: 160px;
  padding: 6px;
  position: fixed;
  z-index: 40;
}

.live-slice-menu button {
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
}

.live-slice-menu button:hover {
  background: #eef6ff;
  color: var(--primary);
}

.live-slice-list {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  padding: 10px;
}

.live-slice-title {
  color: var(--muted);
  font-size: 13px;
}

.live-slice-item {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text);
  display: grid;
  gap: 8px;
  grid-template-columns: max-content minmax(0, 1fr);
  padding: 8px;
  text-align: left;
}

.live-slice-item span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-card {
  display: grid;
  gap: 10px;
}

.program-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  padding: 16px;
}

.program-card summary {
  cursor: pointer;
}

.program-head {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 96px minmax(0, 1fr);
}

.program-head img,
.cover-preview img {
  border-radius: 6px;
  height: 72px;
  object-fit: cover;
  width: 96px;
}

.program-head h2 {
  margin-bottom: 4px;
}

.program-head p {
  color: var(--muted);
  margin-bottom: 0;
}

.live-card {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding-top: 12px;
}

.live-card h3 {
  font-size: 16px;
  margin: 0;
}

.schedule-card {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.graph-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  padding: 16px;
}

.graph-card-topic {
  background: #f0f9ff;
  border-color: #7dd3fc;
}

.graph-card-linked {
  background: #f7f3ff;
  border-color: #c4b5fd;
}

.graph-nodes {
  display: grid;
  gap: 10px;
}

.graph-node {
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  padding: 10px;
}

.graph-node time {
  color: var(--muted);
  font-size: 13px;
}

.graph-node p {
  margin-bottom: 0;
}

.graph-edges {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.graph-edges span {
  background: var(--primary-soft);
  border-radius: 6px;
  color: #183a9e;
  font-size: 13px;
  padding: 5px 7px;
}

.event-top {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.event-top time {
  color: var(--muted);
  font-size: 14px;
  margin-right: auto;
}

.edit-event,
.delete-event {
  background: transparent;
  padding: 4px 6px;
}

.edit-event {
  color: var(--primary);
}

.delete-event {
  color: var(--danger);
}

.event-text {
  line-height: 1.6;
  margin-bottom: 0;
  white-space: pre-wrap;
}

.event-relation-line {
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.inline-person {
  background: transparent;
  border: 0;
  color: var(--primary);
  display: inline;
  padding: 0 2px;
}

.inline-person:hover {
  filter: none;
  text-decoration: underline;
}

.clip-status {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 2px 7px;
}

button.clip-status {
  cursor: pointer;
}

.clip-status-none {
  background: #f8fafc;
  border-color: var(--line);
  color: #475467;
}

.clip-status-planned {
  background: #fff7e6;
  border-color: #f79009;
  color: #b54708;
}

.clip-status-done {
  background: #ecfdf3;
  border-color: #12b76a;
  color: #027a48;
}

.image-drafts {
  display: grid;
  gap: 8px;
  margin: -4px 0 12px;
}

.upload-status {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  padding: 8px;
}

.image-draft {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 8px;
  grid-template-columns: 64px 1fr;
  padding: 8px;
}

.image-draft img {
  border-radius: 4px;
  cursor: zoom-in;
  height: 64px;
  object-fit: cover;
  width: 64px;
}

.image-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.image-actions button {
  background: #475467;
  padding: 6px 8px;
}

.image-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.event-source {
  color: var(--primary);
  overflow-wrap: anywhere;
}

.clip-link {
  color: var(--primary);
  font-size: 14px;
  justify-self: start;
}

.related-event {
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--muted);
  justify-self: start;
  padding: 6px 8px;
  text-align: left;
}

.related-list {
  color: var(--muted);
  font-size: 13px;
}

.related-list button {
  background: transparent;
  color: var(--primary);
  padding: 0 2px;
}

.event-image-button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: block;
  overflow: hidden;
  padding: 0;
}

.event-image-button img {
  display: block;
  height: 96px;
  object-fit: cover;
  width: 96px;
}

.lightbox {
  align-items: center;
  background: rgba(16, 24, 40, 0.82);
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 24px;
  position: fixed;
  z-index: 30;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-height: 86vh;
  max-width: 92vw;
  object-fit: contain;
}

.lightbox button {
  position: absolute;
  right: 18px;
  top: 18px;
}

.empty {
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

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

.calendar-head button {
  background: #344054;
}

.calendar-head label {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.calendar-head input {
  margin-top: 6px;
  min-width: 150px;
}

.calendar-grid {
  display: grid;
  gap: 1px;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.calendar-cell {
  background: var(--panel);
  min-height: 118px;
  padding: 8px;
}

.calendar-cell.muted {
  background: #f0f2f5;
  color: var(--muted);
}

.calendar-day {
  font-size: 13px;
  font-weight: 700;
}

.calendar-item {
  background: var(--primary-soft);
  border-radius: 5px;
  font-size: 12px;
  line-height: 1.35;
  margin-top: 6px;
  padding: 5px;
}

.stat-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.chart-toggle {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: inline-flex;
  gap: 4px;
  justify-self: start;
  padding: 4px;
}

.chart-toggle button {
  background: transparent;
  color: var(--text);
  padding: 7px 10px;
}

.chart-toggle button.active {
  background: var(--primary);
  color: white;
}

.bar-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(70px, 120px) minmax(90px, 1fr) 36px;
  padding: 8px 0;
}

.bar-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  background: var(--primary-soft);
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
}

.bar-fill {
  background: var(--primary);
  border-radius: inherit;
  height: 100%;
}

.pie-chart-wrap {
  align-items: center;
  display: grid;
  gap: 18px;
  grid-template-columns: 180px minmax(0, 1fr);
}

.pie-chart {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
}

.pie-legend {
  display: grid;
  gap: 8px;
}

.pie-legend-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 12px minmax(0, 1fr) 36px;
}

.pie-legend-row span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pie-swatch {
  border-radius: 3px;
  height: 12px;
  width: 12px;
}

@media (max-width: 900px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .view-tabs {
    width: 100%;
  }

  .header-actions {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr auto auto;
  }

  .tab {
    flex: 1;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .header-actions {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .calendar-head {
    align-items: stretch;
    flex-direction: column;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .calendar-cell {
    min-height: 88px;
    padding: 5px;
  }

  .calendar-item {
    font-size: 11px;
  }

  .pie-chart-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .pie-legend {
    justify-self: stretch;
    width: 100%;
  }
}
