:root {
  --ink: #1d2430;
  --muted: #657083;
  --line: #dce2ea;
  --paper: #f7f8fb;
  --panel: #ffffff;
  --accent: #1677ff;
  --accent-2: #12b886;
  --warn: #f59f00;
  --danger: #e03131;
  --violet: #7950f2;
  --row-h: 42px;
  --print-scale: 0.62;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
}

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

.app-shell {
  height: 100vh;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #eef3f8;
  overflow: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: #16213a;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.25;
}

.brand p,
.preview-toolbar p,
.empty-state span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.field,
.mapping-grid label {
  display: grid;
  gap: 7px;
  color: #3b4656;
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 36px;
  padding: 0 10px;
}

textarea {
  min-height: 200px;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
  white-space: pre;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}

.panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel.compact {
  padding-bottom: 16px;
}

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

.panel h2,
.preview-toolbar h2 {
  font-size: 15px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.source-actions {
  margin-top: 8px;
}

button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 700;
}

.primary {
  background: var(--accent);
  color: #fff;
}

.secondary,
.ghost,
.icon-button {
  background: #fff;
  color: #263244;
  border-color: var(--line);
}

.ghost {
  min-height: 30px;
  padding: 0 10px;
}

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  color: #31506f;
  background: #e6f0ff;
  font-size: 12px;
  font-weight: 700;
}

.notice {
  margin-top: 8px;
  color: #5d6a7c;
  font-size: 12px;
  line-height: 1.5;
}

.notice.error {
  color: #b42318;
}

.notice.ok {
  color: #087f5b;
}

.mapping-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f6fa;
}

.segmented button {
  min-height: 32px;
  background: transparent;
}

.segmented button.active {
  color: #fff;
  background: #16213a;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  color: #3b4656;
  font-size: 13px;
  font-weight: 650;
}

.print-note {
  margin-top: 10px;
  color: #5d6a7c;
  font-size: 12px;
  line-height: 1.5;
}

.setting-row label {
  display: flex;
  align-items: center;
  gap: 7px;
}

.setting-row input {
  width: auto;
  min-height: auto;
}

.setting-row input:disabled {
  opacity: 1;
}

.wide-setting {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  color: #3b4656;
  font-size: 13px;
  font-weight: 650;
}

.wide-setting input {
  width: auto;
  min-height: auto;
}

.preview {
  min-width: 0;
  height: 100vh;
  padding: 22px;
  overflow: auto;
  background: #ffffff;
}

.preview-controls {
  position: sticky;
  top: 0;
  z-index: 8;
  padding: 0 0 14px;
  background: #fff;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 0 14px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.search-body {
  display: grid;
  gap: 12px;
  padding: 16px 20px 6px;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, auto);
  gap: 6px;
  margin-bottom: 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f6fa;
}

.view-tab {
  min-height: 32px;
  background: transparent;
}

.view-tab.active {
  color: #fff;
  background: #16213a;
}

.zoom-controls {
  display: none;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
}

.zoom-controls span {
  min-width: 48px;
  color: #3b4656;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.zoom-controls.visible {
  display: flex;
}

.icon-button {
  display: grid;
  width: 36px;
  padding: 0;
  place-items: center;
  font-size: 17px;
}

.empty-state {
  display: grid;
  min-height: 60vh;
  place-content: center;
  gap: 8px;
  text-align: center;
}

.hidden {
  display: none;
}

.chart {
  width: max-content;
  min-width: 100%;
  border: 1px solid var(--line);
  background: #fff;
}

.print-pages {
  display: grid;
  gap: 18px;
  overflow: auto;
  padding-bottom: 32px;
}

.print-pages.hidden {
  display: none;
}

.print-page {
  position: relative;
  width: 420mm;
  min-height: 297mm;
  padding: 10mm;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  color: #111827;
  transform: scale(var(--print-scale));
  transform-origin: top left;
  margin-bottom: calc(-297mm * (1 - var(--print-scale)));
}

.print-watermark {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.055;
  pointer-events: none;
  overflow: hidden;
}

.print-watermark-track {
  position: absolute;
  inset: -18mm;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 22mm 34mm;
  align-content: center;
  justify-items: center;
  transform: rotate(0deg) scale(1.04);
  transform-origin: center;
}

.print-watermark-track.track-a {
  translate: 0 0;
}

.print-watermark-track.track-b {
  translate: 34mm 22mm;
}

.print-watermark-item {
  display: inline-flex;
  align-items: center;
  gap: 3mm;
  white-space: nowrap;
}

.print-watermark-item img {
  width: 10mm;
  height: 10mm;
  object-fit: contain;
}

.print-watermark-item span {
  color: #111827;
  font-size: 8pt;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.print-title {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 8mm;
  margin-bottom: 3mm;
  font-size: 10pt;
  line-height: 1.25;
}

.print-title strong {
  display: block;
  font-size: 13pt;
}

.print-title small {
  display: block;
  margin-bottom: 0.8mm;
  color: #4b5563;
  font-size: 8pt;
  font-weight: 800;
}

.print-title span {
  color: #4b5563;
}

.print-grid {
  position: relative;
  z-index: 1;
  display: grid;
  border-top: 0.25mm solid #9ca3af;
  border-left: 0.25mm solid #9ca3af;
  font-size: 10pt;
  letter-spacing: 0;
  background: rgba(255, 255, 255, 0.18);
}

.print-head,
.print-task,
.print-line {
  min-height: 8mm;
  border-right: 0.25mm solid #c7ced8;
  border-bottom: 0.25mm solid #c7ced8;
}

.print-head {
  display: grid;
  place-items: center;
  min-height: 8mm;
  padding: 0 1mm;
  background: #c8d7ea;
  font-size: 8.5pt;
  font-weight: 800;
  text-align: center;
}

.print-task-head {
  justify-items: start;
  padding-left: 2mm;
}

.print-task {
  display: grid;
  align-content: center;
  gap: 0.7mm;
  padding: 1mm 2mm;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.56);
}

.print-task strong,
.print-task span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-task strong {
  font-size: 9.5pt;
  line-height: 1.15;
}

.print-task span {
  color: #4b5563;
  font-size: 8pt;
}

.print-group,
.print-group-line {
  min-height: 7mm;
  background: rgba(243, 246, 250, 0.76);
}

.print-group {
  color: #1f2937;
  font-size: 9pt;
  font-weight: 850;
}

.print-line {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(217, 224, 234, 0.95) 0.25mm, transparent 0.25mm) 0 0 / var(--print-cell) 100%,
    rgba(255, 255, 255, 0.38);
}

.print-outside-label {
  position: absolute;
  top: 1.45mm;
  max-width: 58mm;
  overflow: hidden;
  color: #1f2937;
  font-size: 7.3pt;
  font-weight: 800;
  line-height: 5mm;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-outside-label.before {
  text-align: right;
}

.print-outside-label.below {
  top: 5.7mm;
}

.print-line.has-below-label {
  min-height: 11.5mm;
}

.print-outside-label em {
  color: #4b5563;
  font-style: normal;
  font-weight: 760;
}

.print-bar {
  position: absolute;
  top: 1.6mm;
  height: 4.8mm;
  border-radius: 1.2mm;
  padding: 0 1.5mm;
  overflow: hidden;
  color: #fff;
  background: var(--accent);
  font-size: 7.5pt;
  font-weight: 800;
  line-height: 4.8mm;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-bar-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-bar.done {
  background: var(--accent-2);
}

.print-bar.risk {
  background: var(--warn);
}

.print-bar.blocked {
  background: var(--danger);
}

.print-bar.other {
  background: var(--violet);
}

.chart-grid {
  display: grid;
  grid-template-columns: 250px repeat(var(--cols), minmax(var(--cell-w), 1fr));
}

.chart-cell {
  min-height: var(--row-h);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.chart-head {
  position: sticky;
  top: 66px;
  z-index: 3;
  display: grid;
  align-items: center;
  min-height: 38px;
  padding: 0 8px;
  background: #c8d7ea;
  color: #1f2a3a;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.task-head {
  text-align: left;
}

.task-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 7px 10px;
  background: #fff;
}

.task-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 760;
}

.task-sub {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-row {
  position: relative;
  grid-column: 2 / -1;
  min-height: var(--row-h);
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(220, 226, 234, 0.8) 1px, transparent 1px) 0 0 / var(--cell-w) 100%,
    #fff;
}

.timeline-row.has-below-label {
  min-height: 58px;
}

.bar {
  position: absolute;
  top: 9px;
  height: 24px;
  border-radius: 6px;
  padding: 0 8px;
  color: #fff;
  background: var(--accent);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.16);
  font-size: 11px;
  font-weight: 800;
  line-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar.label-outside,
.print-bar.label-outside {
  min-width: 0;
  padding: 0;
}

.outside-label {
  position: absolute;
  top: 8px;
  max-width: 280px;
  overflow: hidden;
  color: #233044;
  font-size: 11px;
  font-weight: 800;
  line-height: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outside-label.before {
  text-align: right;
}

.outside-label.below {
  top: 32px;
}

.outside-label em {
  color: #64748b;
  font-style: normal;
  font-weight: 750;
}

.bar-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-overview {
  position: absolute;
  right: 10mm;
  bottom: 10mm;
  z-index: 1;
  width: 84mm;
  padding: 1.6mm;
  border: 0.25mm solid #d4dbe4;
  border-radius: 2mm;
  background: rgba(255, 255, 255, 0.82);
}

.print-overview strong {
  display: block;
  margin-bottom: 1.2mm;
  color: #334155;
  font-size: 7.2pt;
}

.print-overview strong span {
  display: block;
  margin-top: 0.6mm;
  color: #64748b;
  font-size: 6.6pt;
  font-weight: 700;
}

.print-overview svg {
  display: block;
  width: 100%;
  height: 20mm;
}

.merge-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.merge-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.merge-dialog form {
  display: grid;
  max-height: inherit;
}

.search-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.search-dialog::backdrop {
  background: rgba(15, 23, 42, 0.32);
}

.search-hit {
  padding: 0 1px;
  border-radius: 3px;
  background: rgba(255, 224, 102, 0.72);
}

.search-hit.active {
  background: rgba(250, 82, 82, 0.22);
  outline: 2px solid rgba(250, 82, 82, 0.72);
}

.merge-head {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}

.merge-head h2 {
  font-size: 18px;
}

.merge-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.merge-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding: 14px 20px;
}

.merge-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.merge-option input {
  width: auto;
  min-height: auto;
  margin-top: 3px;
}

.merge-option strong {
  font-size: 14px;
}

.merge-option p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.merge-option ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: #344256;
  font-size: 12px;
  line-height: 1.55;
}

.merge-option li span {
  color: var(--muted);
}

.merge-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
}

.bar.done {
  background: var(--accent-2);
}

.bar.risk {
  background: var(--warn);
}

.bar.blocked {
  background: var(--danger);
}

.bar.other {
  background: var(--violet);
}

.today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fa5252;
  z-index: 1;
}

.group-row {
  display: contents;
}

.group-row .task-cell,
.group-row .timeline-row {
  min-height: 30px;
  background: #f8fafc;
}

.group-label {
  color: #29364a;
  font-size: 12px;
  font-weight: 850;
}

@media (max-width: 900px) {
  body,
  .app-shell,
  .workspace {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

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

  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview {
    height: auto;
  }

  .preview-controls {
    top: 0;
  }
}

@page {
  size: 420mm 297mm;
  margin: 10mm;
}

@media print {
  body {
    background: #fff;
    overflow: visible;
  }

  .sidebar,
  .chart,
  .view-tabs,
  .zoom-controls,
  .preview-toolbar,
  .empty-state {
    display: none !important;
  }

  .workspace {
    display: block;
    min-height: auto;
  }

  .preview {
    padding: 0;
    overflow: visible;
  }

  .preview-toolbar {
    position: static;
    padding-bottom: 8px;
  }

  .print-pages {
    display: block;
    overflow: visible;
    padding: 0;
  }

  .print-pages.hidden {
    display: block;
  }

  .print-page {
    width: auto;
    min-height: auto;
    padding: 0;
    border: 0;
    box-shadow: none;
    transform: none;
    margin: 0;
    overflow: hidden;
    break-inside: avoid-page;
    page-break-after: always;
    break-after: page;
  }

  .print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .print-head,
  .print-task,
  .print-line {
    min-height: 8mm;
    break-inside: avoid;
    page-break-inside: avoid;
    border-right: 0.25mm solid #c7ced8;
    border-bottom: 0.25mm solid #c7ced8;
  }

  .print-head {
    display: grid;
    place-items: center;
    min-height: 8mm;
    padding: 0 1mm;
    background: #c8d7ea;
    font-size: 8.5pt;
    font-weight: 800;
    text-align: center;
  }

  .print-task-head {
    justify-items: start;
    padding-left: 2mm;
  }

  .print-task {
    display: grid;
    align-content: center;
    gap: 0.7mm;
    padding: 1mm 2mm;
    overflow: hidden;
  }

  .print-task strong,
  .print-task span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .print-task strong {
    font-size: 9.5pt;
    line-height: 1.15;
  }

  .print-task span {
    color: #4b5563;
    font-size: 8pt;
  }

  .print-group,
  .print-group-line {
    min-height: 7mm;
    background: #f3f6fa;
  }

  .print-group {
    color: #1f2937;
    font-size: 9pt;
    font-weight: 850;
  }

  .print-line {
    position: relative;
    overflow: hidden;
    background:
      linear-gradient(90deg, #d9e0ea 0.25mm, transparent 0.25mm) 0 0 / var(--print-cell) 100%,
      #fff;
  }

  .print-outside-label {
    position: absolute;
    top: 1.45mm;
    max-width: 58mm;
    overflow: hidden;
    color: #1f2937;
    font-size: 7.3pt;
    font-weight: 800;
    line-height: 5mm;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .print-outside-label.before {
    text-align: right;
  }

  .print-outside-label.below {
    top: 5.7mm;
  }

  .print-line.has-below-label {
    min-height: 11.5mm;
  }

  .print-outside-label em {
    color: #4b5563;
    font-style: normal;
    font-weight: 760;
  }

  .print-bar {
    position: absolute;
    top: 1.6mm;
    height: 4.8mm;
    border-radius: 1.2mm;
    padding: 0 1.5mm;
    overflow: hidden;
    color: #fff;
    background: var(--accent);
    font-size: 7.5pt;
    font-weight: 800;
    line-height: 4.8mm;
    text-overflow: ellipsis;
    white-space: nowrap;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .print-bar-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .print-bar.done {
    background: var(--accent-2);
  }

  .print-bar.risk {
    background: var(--warn);
  }

  .print-bar.blocked {
    background: var(--danger);
  }

  .print-bar.other {
    background: var(--violet);
  }
}
