:root {
  --bg: #f6f8fc;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-border: #d4dce8;
  --text: #0f172a;
  --muted: #334155;
  --blue: #2563eb;
  --amber: #f59e0b;
}

@font-face {
  font-family: 'Zaha Hadid Sans';
  src: url('/fonts/Zaha-Hadid-Sans.ttf') format('truetype');
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { font-family: "IBM Plex Sans", "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }

.shell {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 0% 0%, #f8fafc, #eef2ff 58%, #edf2f7 100%);
}

#board {
  width: 100%;
  height: 100%;
  display: block;
}

.topbar {
  position: absolute;
  top: 14px;
  left: 84px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
  padding: 6px 10px;
  backdrop-filter: blur(4px);
}

.brand-z {
  font-family: 'Zaha Hadid Sans', 'IBM Plex Sans', sans-serif;
  font-size: 38px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #111827;
  text-decoration: none;
  user-select: none;
}

.board-title {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #111827;
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  padding: 8px 10px;
  min-width: 220px;
  max-width: 42vw;
}

.board-title:focus {
  outline: none;
  border-color: #c7d2fe;
  background: #ffffff;
}

.topbar-menu-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: #111827;
  padding: 0;
}

.topbar-menu-btn:hover {
  background: #f3f4f6;
}

.main-menu {
  position: absolute;
  top: 62px;
  left: 84px;
  width: 286px;
  z-index: 12;
  padding: 10px;
  border: 1px solid #d4dce8;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.22);
}

.main-menu-item {
  width: 100%;
  height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  display: grid;
  grid-template-columns: 22px 1fr 18px;
  align-items: center;
  gap: 8px;
  text-align: left;
  color: #1f2937;
  font-size: 14px;
  padding: 0 8px;
}

.main-menu-item:hover {
  background: #f3f5f9;
}

.main-menu-item span:nth-child(2) {
  font-size: 14px;
}

.main-menu-item span:last-child {
  font-size: 16px;
  color: #374151;
  text-align: right;
}

.main-menu-item-single {
  grid-template-columns: 22px 1fr;
}

.main-menu-sep {
  height: 1px;
  background: #e5e7eb;
  margin: 6px 4px;
}

.side-toolbar {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.18);
}

.side-tool {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 23px;
  line-height: 1;
  color: #1f2937;
}

.side-tool:hover {
  background: #f3f6fb;
}

.side-tool-icon {
  width: 24px;
  height: 24px;
  display: block;
  margin: 0 auto;
  pointer-events: none;
}

.side-tool.active {
  border-color: #c7d2fe;
  background: #e7edff;
  color: #1d4ed8;
}

.side-tool-add {
  margin-top: 4px;
  background: #1f2937;
  color: #fff;
  font-weight: 700;
}

.side-tool-add:hover {
  background: #111827;
}

.pen-toolbar {
  position: absolute;
  left: 64px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.18);
}

.pen-tool,
.pen-size {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: #1f2937;
  font-size: 22px;
}

.pen-tool:hover,
.pen-size:hover {
  background: #f3f6fb;
}

.pen-tool.active,
.pen-size.active {
  border-color: #c7d2fe;
  background: #e7edff;
  color: #1d4ed8;
}

.pen-sep {
  height: 1px;
  margin: 2px 4px;
  background: #e2e8f0;
}

.pen-size .dot {
  display: inline-block;
  border-radius: 50%;
  background: currentColor;
}

.pen-size .dot.thin {
  width: 5px;
  height: 5px;
}

.pen-size .dot.thick {
  width: 12px;
  height: 12px;
}

.pen-palette {
  position: absolute;
  z-index: 11;
  width: 200px;
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.2);
}

.pen-palette-size {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5eaf2;
}

#penSizeSlider {
  width: 100%;
  accent-color: #2563eb;
}

.pen-palette-colors {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px;
}

.pen-palette-color {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid #cdd5e3;
  background: var(--swatch);
  padding: 0;
}

.pen-palette-color.active {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px #dbeafe inset;
}

.floating,
.menu,
.connection-toolbar,
.text-toolbar {
  position: absolute;
  z-index: 8;
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.18);
}

.floating {
  align-items: center;
  padding: 6px 8px;
}

.floating select,
.floating input[type="number"],
.floating button {
  height: 30px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #fff;
  color: #111827;
}

.floating select,
.floating input[type="number"] {
  font-size: 13px;
  padding: 0 8px;
}

.floating input[type="number"] {
  width: 64px;
}

.connection-toolbar {
  transform: translateX(-50%);
  align-items: center;
  gap: 8px;
  max-width: 520px;
  padding: 6px 8px;
}

.text-toolbar {
  transform: translateX(-50%);
  align-items: center;
  gap: 6px;
  padding: 6px;
}

.text-toolbar select,
.text-toolbar input[type="number"],
.text-toolbar button {
  height: 30px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #fff;
  color: #111827;
}

.text-toolbar select,
.text-toolbar input[type="number"] {
  padding: 0 8px;
  font-size: 13px;
}

.text-toolbar button {
  min-width: 30px;
  padding: 0 8px;
  font-size: 14px;
}

.text-toolbar button.active {
  border-color: #c7d2fe;
  background: #e7edff;
  color: #1d4ed8;
}

.text-swatch-btn {
  width: 30px;
  min-width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid #cfd8e6;
  background: #ffffff;
  padding: 0;
  position: relative;
}

.text-swatch-btn::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--swatch, #111827);
}

.text-swatch-transparent::after {
  background:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%) 0 0/8px 8px,
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%) 0 0/8px 8px,
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%) 0 0/8px 8px,
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%) 0 0/8px 8px,
    #ffffff;
}

.text-swatch-palette {
  position: absolute;
  z-index: 11;
  width: 196px;
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.2);
}

.swatch-label {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 8px;
}

.text-swatch-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px;
}

.text-swatch-item {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid #cfd8e6;
  background: var(--swatch, #111827);
  padding: 0;
  display: grid;
  place-items: center;
}

.text-swatch-item.transparent {
  background:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%) 0 0/8px 8px,
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%) 0 0/8px 8px,
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%) 0 0/8px 8px,
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%) 0 0/8px 8px,
    #ffffff;
}

.text-swatch-item .check {
  color: #ffffff;
  font-size: 16px;
  line-height: 1;
  opacity: 0;
}

.text-swatch-item.active .check {
  opacity: 1;
}

.text-swatch-item.active {
  border-color: #111827;
}

.text-editor {
  position: absolute;
  z-index: 10;
  border: 1px solid #60a5fa;
  border-radius: 2px;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: #0f172a;
  line-height: 1.3;
  padding: 6px;
  font-family: Arial, sans-serif;
}

.conn-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.conn-colors {
  gap: 6px;
}

.swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #e2e8f0;
  background: var(--swatch);
  padding: 0;
}

.swatch.active {
  border-color: #0f172a;
  box-shadow: 0 0 0 2px #ffffff inset;
}

.conn-icon {
  min-width: 34px;
  height: 30px;
  padding: 4px 8px;
  font-size: 14px;
  line-height: 1;
  border-radius: 8px;
  background: #f8fafc;
}

#pdfToolbar input[type="number"] {
  width: 62px;
  height: 30px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0 8px;
  font-size: 13px;
}

.pdf-page-count {
  min-width: 48px;
  color: #475569;
  font-size: 13px;
  text-align: center;
}

#pdfToolbar {
  transform: none;
}

.conn-move {
  cursor: grab;
}

.conn-move:active {
  cursor: grabbing;
}

.menu {
  display: grid;
  min-width: 120px;
}

button {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #fff;
  padding: 6px 10px;
  color: var(--text);
  cursor: pointer;
}

button.active:not(.side-tool):not(.pen-tool):not(.pen-size):not(.pen-palette-color) {
  border-color: var(--amber);
  background: #fffbeb;
}

.timeline-view {
  position: absolute;
  left: 82px;
  top: 74px;
  width: 980px;
  height: 560px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(250, 251, 255, 0.98);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
  overflow: hidden;
  transform: none;
  transform-origin: top left;
  user-select: none;
}

.timeline-template {
  display: none !important;
}

.timeline-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.timeline-layer .timeline-view {
  pointer-events: auto;
}

.timeline-view.timeline-selected {
  border-color: #2563eb;
}

.timeline-toolbar {
  height: 50px;
  padding: 8px 10px;
  border-bottom: 1px solid #d9e0ec;
  background: rgba(255, 255, 255, 0.96);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timeline-left,
.timeline-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timeline-title {
  font-size: 20px;
  font-weight: 600;
  color: #1f2937;
  line-height: 1;
}

.timeline-btn {
  height: 32px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #fff;
  color: #111827;
  padding: 0 10px;
  font-size: 13px;
}

.timeline-toolbar select {
  height: 32px;
  min-width: 150px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #fff;
  color: #111827;
  padding: 0 8px;
  font-size: 13px;
}

.timeline-btn-primary {
  border-color: #bfdbfe;
  background: #eaf2ff;
  color: #1d4ed8;
  font-weight: 600;
}

.timeline-btn.active {
  border-color: #c7d2fe;
  background: #e7edff;
  color: #1d4ed8;
}

.timeline-body {
  flex: 1;
  position: relative;
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 56px 42px 1fr;
  min-height: 0;
}

.timeline-controls {
  grid-column: 1 / span 2;
  grid-row: 1;
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid #d9e0ec;
  background: #fbfcfe;
}

.timeline-controls .timeline-view-mode {
  height: 44px;
  min-width: 160px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: #f2f4f7;
  color: #273243;
  padding: 0 16px;
  font-size: 18px;
  font-weight: 500;
}

.timeline-control-btn {
  width: 44px;
  height: 44px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: #f2f4f7;
  color: #273243;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.timeline-control-btn svg {
  width: 24px;
  height: 24px;
}

.timeline-range-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 10px;
  z-index: 20;
  width: 260px;
  border: 1px solid #d8dfeb;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.14);
  padding: 10px;
  display: grid;
  gap: 8px;
}

.timeline-range-popover label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: #4b5563;
}

.timeline-range-popover input[type="date"] {
  height: 32px;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  padding: 0 8px;
  color: #111827;
  background: #fff;
}

.timeline-range-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.timeline-task-toolbar {
  position: absolute;
  left: 8px;
  top: 62px;
  z-index: 22;
  width: min(560px, calc(100% - 16px));
  border: 1px solid #d8dfeb;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.14);
  overflow: visible;
}

.timeline-task-toolbar-head {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-bottom: 1px solid #e5eaf2;
}

.timeline-task-icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #d6dde9;
  border-radius: 8px;
  background: #f8fafc;
  color: #556171;
  padding: 0;
  font-size: 14px;
}

.timeline-task-color-btn {
  width: 24px;
  height: 24px;
  border: 1.5px solid #b48d12;
  border-radius: 999px;
  background: var(--swatch, #f8e9aa);
  padding: 0;
}

.timeline-task-date-range {
  font-size: 14px;
  color: #3c4655;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-task-name-input {
  width: calc(100% - 8px);
  margin: 4px;
  border: 2px solid #5a7cf1;
  border-radius: 8px;
  height: 42px;
  padding: 0 12px;
  font-size: 18px;
  color: #303b49;
  background: #fff;
}

.timeline-task-name-input:focus {
  outline: none;
  border-color: #4f71e4;
}

.timeline-task-global-palette {
  z-index: 40;
  width: 236px;
}

.timeline-task-global-grid {
  grid-template-columns: repeat(5, 1fr);
  max-height: 220px;
  overflow-y: auto;
}

.timeline-list-head,
.timeline-grid-head {
  border-bottom: 1px solid #d9e0ec;
  background: #f8fafc;
  display: flex;
  align-items: center;
}

.timeline-list-head {
  grid-column: 1;
  grid-row: 2;
  border-right: 1px solid #d9e0ec;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
}

.timeline-grid-head {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  overflow: hidden;
}

.timeline-head-track {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
}

.timeline-head-cell {
  position: absolute;
  top: 0;
  bottom: 0;
  border-right: 1px solid #d6deea;
  background: #f4f7fb;
  padding: 5px 8px;
  font-size: 12px;
  color: #475569;
}

.timeline-list {
  grid-column: 1;
  grid-row: 3;
  overflow-y: auto;
  border-right: 1px solid #d9e0ec;
  background: rgba(255, 255, 255, 0.9);
}

.timeline-row {
  height: var(--timeline-row-height, 46px);
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-bottom: 1px solid #edf1f7;
  gap: 8px;
}

.timeline-row.active {
  background: #eef4ff;
}

.timeline-row input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  height: 28px;
  background: transparent;
  color: #1f2937;
  font-size: 13px;
  padding: 0 6px;
}

.timeline-row input:focus {
  outline: none;
  border-color: #c7d2fe;
  background: #fff;
}

.timeline-grid-scroll {
  grid-column: 2;
  grid-row: 3;
  position: relative;
  overflow: auto;
  background: #fff;
}

.timeline-grid,
.timeline-bars {
  position: relative;
}

.timeline-grid {
  background-image:
    linear-gradient(to bottom, #edf1f7 1px, transparent 1px),
    linear-gradient(to right, #e2e8f0 1px, transparent 1px),
    linear-gradient(to right, rgba(148, 163, 184, 0.13) 1px, transparent 1px);
  background-size:
    100% var(--timeline-row-height, 46px),
    var(--timeline-day-width, 34px) 100%,
    calc(var(--timeline-day-width, 34px) * 7) 100%;
  background-position: 0 0, 0 0, 0 0;
}

.timeline-bars {
  position: absolute;
  left: 0;
  top: 0;
}

.timeline-bar {
  position: absolute;
  height: calc(var(--timeline-row-height, 46px) - 14px);
  top: 7px;
  border: 1px solid #d5b253;
  border-radius: 4px;
  background: #f8e9aa;
  color: #624500;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  cursor: grab;
  user-select: none;
}

.timeline-bar.active {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.timeline-bar-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
}

.timeline-bar-handle.left { left: 0; }
.timeline-bar-handle.right { right: 0; }

.timeline-today {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #ef4444;
  pointer-events: none;
  z-index: 3;
}

.timeline-move-btn {
  min-width: 30px;
  width: 30px;
  padding: 0;
  cursor: grab;
}

.timeline-move-btn:active {
  cursor: grabbing;
}

.timeline-scale-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #2563eb;
  background: #ffffff;
  padding: 0;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
}

.timeline-view.timeline-selected .timeline-scale-handle {
  opacity: 1;
  pointer-events: auto;
}

.timeline-scale-handle.nw { left: -6px; top: -6px; cursor: nwse-resize; }
.timeline-scale-handle.n { left: 50%; top: -6px; transform: translateX(-50%); cursor: ns-resize; }
.timeline-scale-handle.ne { right: -6px; top: -6px; cursor: nesw-resize; }
.timeline-scale-handle.e { right: -6px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.timeline-scale-handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.timeline-scale-handle.s { left: 50%; bottom: -6px; transform: translateX(-50%); cursor: ns-resize; }
.timeline-scale-handle.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.timeline-scale-handle.w { left: -6px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.hidden { display: none !important; }

@media (max-width: 860px) {
  .topbar {
    left: 14px;
    top: 74px;
    max-width: calc(100vw - 28px);
  }

  .side-toolbar {
    top: 14px;
    transform: none;
  }

  .pen-toolbar {
    top: 14px;
    left: 64px;
    transform: none;
  }

  .pen-palette {
    width: 188px;
  }

  .timeline-view {
    left: 14px;
    top: 126px;
    width: calc(100vw - 28px);
    height: calc(100vh - 140px);
  }

  .timeline-body {
    grid-template-columns: 220px 1fr;
    grid-template-rows: 52px 38px 1fr;
  }

  .timeline-controls .timeline-view-mode {
    min-width: 132px;
    font-size: 16px;
  }

  .timeline-control-btn {
    width: 40px;
    height: 40px;
  }

  .timeline-task-toolbar {
    width: calc(100% - 16px);
  }

  .timeline-task-name-input {
    height: 36px;
    font-size: 16px;
  }

  .timeline-task-date-range {
    font-size: 13px;
  }
}
