:root {
  --bg: #ffffff;
  --surface: #f5f6f8;
  --border: #e2e4e8;
  --text: #1d2026;
  --text-muted: #6b7280;
  --accent: #2f6fd6;
  --danger: #d64545;
  --tone-todo: #6b7280;
  --tone-progress: #2f6fd6;
  --tone-waiting: #b7791f;
  --tone-done: #2a9d6f;
  --tone-folded: #9ca3af;
  --link-parent: #a3aab5;
  --link-same-work: #7a5af0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2127;
    --border: #2d3139;
    --text: #e6e8eb;
    --text-muted: #9aa1ab;
    --accent: #6b9cf0;
    --danger: #f07070;
    --tone-todo: #9aa1ab;
    --tone-progress: #6b9cf0;
    --tone-waiting: #e0a84a;
    --tone-done: #4cc493;
    --tone-folded: #6b7280;
    --link-parent: #59606b;
    --link-same-work: #a48cf5;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", sans-serif;
}

button,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: progress;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.toolbar h1 {
  margin: 0;
  font-size: 16px;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.filter-toggle::after {
  content: "▴";
  color: var(--text-muted);
}

.filter-toggle[aria-expanded="false"]::after {
  content: "▾";
}

.active-filter-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.active-filter-count[hidden] {
  display: none;
}

.filter-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.filter-panel[hidden] {
  display: none;
}

.control-group {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.control-group-title {
  flex: none;
  margin: 0;
  padding-top: 7px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.control-group-items {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  min-width: 0;
}

.control-group-items > label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 4px 10px;
  background: var(--bg);
  cursor: pointer;
}

.segmented label + label span {
  border-left: 1px solid var(--border);
}

.segmented input:checked + span {
  background: var(--accent);
  color: #ffffff;
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.multi-picker {
  position: relative;
}

.multi-picker-button::after {
  content: "▾";
  margin-left: 6px;
  color: var(--text-muted);
}

.multi-picker-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 10;
  min-width: 180px;
  max-height: min(420px, 70vh);
  overflow-y: auto;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 20, 30, 0.12);
}

.multi-picker-menu[hidden] {
  display: none;
}

.multi-picker-menu .multi-picker-option {
  display: flex;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.multi-picker-option:hover {
  background: var(--surface);
}

.multi-picker-clear {
  width: 100%;
  margin-top: 4px;
}

.freshness {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: var(--text-muted);
}

.error-message {
  margin: 0;
  padding: 8px 16px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.error-message[hidden] {
  display: none;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#graph-view {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#graph-canvas {
  position: relative;
  flex: 1;
  min-height: 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 20px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.legend-links,
.legend-owners {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.legend-line {
  display: inline-block;
  width: 18px;
  margin-right: 6px;
  vertical-align: middle;
  border-top: 2px solid;
}

.legend-parent {
  border-color: var(--link-parent);
}

.legend-blocker {
  border-color: var(--danger);
}

.legend-same-work {
  border-color: var(--link-same-work);
  border-top-style: dashed;
}

.legend-owner::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--owner-color);
}

.legend-hint {
  margin: 0;
}

.detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  width: min(400px, 100%);
  padding: 14px 24px 32px;
  overflow-y: auto;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(15, 20, 30, 0.12);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.2s ease, visibility 0.2s;
}

.detail-panel.is-open {
  transform: none;
  visibility: visible;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-kind {
  color: var(--text-muted);
  font-size: 12px;
}

.detail-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.detail-close:hover {
  background: var(--surface);
}

.detail-title {
  margin: 10px 0 6px;
  font-size: 22px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.detail-notion-link {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--accent);
  font-size: 13px;
}

.detail-properties {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px 12px;
  margin: 0 0 20px;
}

.detail-properties dt {
  color: var(--text-muted);
}

.detail-properties dd {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0;
}

.detail-section h3 {
  margin: 16px 0 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.relation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.relation-item:hover {
  background: var(--surface);
}

.relation-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relation-status {
  flex: none;
  color: var(--text-muted);
  font-size: 12px;
}

.detail-empty {
  color: var(--text-muted);
}

.color-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-color);
}

.graph-tooltip {
  position: absolute;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 320px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(15, 20, 30, 0.12);
  font-size: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.graph-tooltip[hidden] {
  display: none;
}

.graph-tooltip strong {
  color: var(--text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.detail-input {
  min-width: 0;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.detail-input:disabled {
  opacity: 0.5;
  cursor: progress;
}

.detail-schedule {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.detail-date {
  width: 9.5em;
}

.detail-edit-status {
  min-height: 1.5em;
  margin: -12px 0 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.detail-edit-status.is-done {
  color: var(--tone-done);
}

.detail-edit-status.is-error {
  color: var(--danger);
}
