* { box-sizing: border-box; }

:root {
  --bg: #ececec;
  --panel: #ffffff;
  --panel-2: #f7f7f7;
  --text: #111111;
  --border: #d3d3d3;
  --accent: #111111;
  --grid: rgba(0,0,0,0.05);
  --shadow: 0 10px 26px rgba(0,0,0,0.12);
}

body.dark {
  --bg: #17181b;
  --panel: #22252b;
  --panel-2: #2a2e35;
  --text: #f1f1f1;
  --border: #3a414b;
  --accent: #f1f1f1;
  --grid: rgba(255,255,255,0.08);
  --shadow: 0 10px 26px rgba(0,0,0,0.35);
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app { width: 100%; height: 100%; display: flex; flex-direction: column; }

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

.formatbar { background: var(--panel-2); }

.toolbar button,
.toolbar select,
.toolbar input[type="color"],
.toolbar textarea {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.toolbar button { cursor: pointer; }

.toolbar textarea {
  resize: vertical;
  min-width: 320px;
  min-height: 68px;
}

.toolbar input[type="color"] {
  padding: 3px;
  width: 44px;
  height: 40px;
}

.toolbar button.active {
  background: var(--accent);
  color: var(--panel);
  border-color: var(--accent);
}

.inline-check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.sep { width: 1px; height: 28px; background: var(--border); }
.grow { flex: 1; }

.text-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 340px;
}
.text-panel label {
  font-size: 12px;
  opacity: 0.8;
}

.range-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

#workspace {
  flex: 1;
  overflow: auto;
  padding: 20px;
}

.workspace-free {
  min-width: 2400px;
  min-height: 1600px;
  position: relative;
  border: 1px solid var(--border);
  background:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}

.page-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}

.page {
  position: relative;
  border: 1px solid var(--border);
  background: #ffffff;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}

.page.active-page {
  outline: 3px solid #4f8cff;
  outline-offset: 2px;
}

.page.portrait { width: 794px; height: 1123px; }
.page.landscape { width: 1123px; height: 794px; }

.board-surface,
.lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.lines { pointer-events: none; }

.item {
  position: absolute;
  border-style: solid;
  border-width: 2px;
  border-radius: 8px;
  user-select: none;
}

.item.selected { outline: 3px solid #4f8cff; }

.box-item { width: 160px; height: 80px; cursor: grab; }
.text-item { min-width: 160px; min-height: 80px; width: 260px; height: 130px; cursor: grab; }
.image-item { width: 240px; height: 180px; overflow: hidden; cursor: grab; }

.item-text {
  width: 100%;
  height: 100%;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  display: flex;
}

.item-text-inner {
  width: 100%;
}

.image-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: #4f8cff;
  border: 1px solid #ffffff;
  cursor: nwse-resize;
}

.page-label {
  position: absolute;
  left: 10px;
  bottom: -28px;
  font-size: 12px;
  color: var(--text);
  opacity: 0.8;
}

line { stroke: #111111; stroke-width: 2; }

@media print {
  html, body {
    overflow: visible;
    width: auto;
    height: auto;
    background: #ffffff !important;
  }

  body.dark { background: #ffffff !important; }
  .topbar, .formatbar { display: none !important; }

  #workspace {
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .page-stack {
    gap: 0 !important;
    align-items: stretch !important;
  }

  .page {
    box-shadow: none !important;
    border: none !important;
    outline: none !important;
    margin: 0 !important;
    page-break-after: always;
    page-break-inside: avoid;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
  }

  .page.portrait,
  .page.landscape {
    width: 100vw !important;
    height: 100vh !important;
  }

  .board-surface,
  .lines {
    width: 100% !important;
    height: 100% !important;
  }

  .page:last-child { page-break-after: auto; }
  .page-label, .resize-handle { display: none !important; }

  .workspace-free {
    border: none;
    width: auto;
    height: auto;
    min-width: 0;
    min-height: 0;
    background: #ffffff !important;
  }

  @page { margin: 0; }
}


.toolbar button:disabled,
.toolbar select:disabled,
.toolbar textarea:disabled,
.toolbar input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}


.board-bg-layer {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  pointer-events: none;
  z-index: 0;
}

.board-surface > .lines,
.workspace-free > .lines {
  z-index: 1;
}

.board-surface > .item,
.workspace-free > .item {
  z-index: 2;
}


.file-trigger {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  display: inline-block;
  line-height: 1.2;
  vertical-align: middle;
  user-select: none;
  text-decoration: none;
}



.task-item {
  width: 280px;
  min-height: 84px;
  cursor: grab;
}

.task-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
}

.task-marker {
  width: 46px;
  min-width: 46px;
  border-right: 2px solid rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  cursor: pointer;
  user-select: none;
}

.task-text-wrap {
  flex: 1;
  min-width: 0;
}

.task-item.state-progress .task-marker {
  color: #7a3e00;
}

.task-item.state-done .task-marker {
  color: #0b5a1e;
}


.toolbar button i {
  font-size: 16px;
  line-height: 1;
}

.deadline-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 260px;
}

.deadline-panel label {
  font-size: 12px;
  opacity: 0.8;
}

.deadline-panel input {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.task-deadline {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 6px;
}

.item.overdue {
  border-color: rgba(220, 38, 38, 0.95) !important;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.35);
}
