:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef1f5;
  --text: #1f2933;
  --muted: #687586;
  --line: #d8dee8;
  --shadow: 0 10px 28px rgba(31, 41, 51, 0.08);
  --focus: #2b6cb0;
}

* {
  box-sizing: border-box;
}

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

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 249, 0.96);
  backdrop-filter: blur(8px);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.view-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.view-button {
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
}

.view-button.active {
  background: #1f2933;
  color: #fff;
}

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

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(240px, 280px);
  align-items: start;
  gap: 14px;
  overflow-x: auto;
  min-height: calc(100vh - 76px);
  padding: 16px 20px 24px;
}

.column {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 116px);
  max-height: calc(100vh - 116px);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--surface-soft);
}

.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.column-title {
  min-width: 0;
}

.column-title h2 {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-title span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.card-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.card-list.drag-over {
  outline: 2px solid var(--focus);
  outline-offset: -4px;
}

.empty-column {
  display: grid;
  min-height: 84px;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  border: 1px dashed #c5ceda;
  border-radius: 8px;
}

.task-card {
  display: grid;
  gap: 8px;
  width: 100%;
  margin-bottom: 10px;
  padding: 0;
  border: 1px solid #d5dce6;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(31, 41, 51, 0.06);
  cursor: default;
  overflow: hidden;
}

.task-card.dragging:active {
  cursor: grabbing;
}

.task-card.dragging {
  opacity: 0.45;
}

.card-color-bar {
  height: 7px;
  background: var(--card-color);
}

.card-summary {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px 10px 10px;
}

.card-toggle {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}

.task-title {
  margin: 0;
  display: -webkit-box;
  overflow-wrap: anywhere;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.card-title-content {
  display: grid;
  gap: 6px;
  min-width: 0;
  cursor: grab;
}

.card-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.card-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.card-flag.priority {
  border-color: #e0a3a3;
  background: #fff1f1;
  color: #8f2424;
}

.card-flag.important {
  border-color: #a8cbbd;
  background: #eef9f4;
  color: #21604d;
}

.card-title-content:active {
  cursor: grabbing;
}

.due-badge {
  justify-self: start;
  max-width: 100%;
  padding: 3px 7px;
  border: 1px solid #cbd6e2;
  border-radius: 999px;
  background: #eef5ff;
  color: #264b78;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.due-badge.due-soon {
  border-color: #e4c36b;
  background: #fff8df;
  color: #6f4e00;
}

.due-badge.overdue {
  border-color: #e0a3a3;
  background: #fff1f1;
  color: #8f2424;
}

.due-badge.done-window {
  border-color: #a8cbbd;
  background: #eef9f4;
  color: #21604d;
}

.task-card.expanded .task-title {
  display: block;
  overflow: visible;
}

.card-details {
  display: grid;
  gap: 10px;
  padding: 0 10px 10px;
}

.card-details[hidden] {
  display: none;
}

.task-notes {
  margin: 0;
  overflow-wrap: anywhere;
  color: #3f4d5d;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.muted-note {
  color: var(--muted);
  font-style: italic;
}

.task-meta {
  color: var(--muted);
  font-size: 12px;
}

.task-source {
  color: #4f5e70;
  font-size: 12px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.project-path {
  padding: 7px 8px;
  border: 1px solid #d8e0ea;
  border-radius: 6px;
  background: #f8fafc;
  color: #3d4d60;
  font-size: 12px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.task-attachments {
  display: grid;
  gap: 6px;
  color: #4f5e70;
  font-size: 12px;
  font-weight: 650;
}

.task-attachment-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
}

.attachment-order-controls {
  display: grid;
  gap: 4px;
}

.attachment-order-controls button {
  width: 26px;
  min-height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: #3d4d60;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.attachment-order-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

.attachment-open {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #d8e0ea;
  border-radius: 6px;
  background: #fff;
  color: #344255;
  cursor: pointer;
  text-align: left;
}

.attachment-open:hover {
  border-color: #9fb4cc;
  background: #f8fafc;
}

.attachment-name {
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 750;
}

.attachment-meta {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
}

.duplicate-target {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.primary-button,
.ghost-button,
.small-button,
.danger-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 650;
  letter-spacing: 0;
}

.primary-button {
  min-height: 38px;
  padding: 0 14px;
  background: #2563a9;
  color: #fff;
}

.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.vault-btn { font-size: 0.8rem; padding: 0 10px; }
.vault-connected { border-color: #22863a; color: #22863a; background: #f0fff4; }
.vault-disconnected { border-color: #e3a008; color: #92540c; background: #fffbeb; }
.remote-sync-btn { font-size: 0.8rem; padding: 0 10px; }
.remote-connected { border-color: #22863a; color: #22863a; background: #f0fff4; }
.remote-disconnected { border-color: #e3a008; color: #92540c; background: #fffbeb; }
.remote-pending { border-color: #2f6fb2; color: #2f6fb2; background: #eef5ff; }

.small-button,
.danger-button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

.small-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.danger-button {
  border-color: #e3b4b4;
  background: #fff6f6;
  color: #9a2a2a;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  background: #fff;
  border-color: var(--line);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

button:hover,
.file-button:hover,
select:hover {
  filter: brightness(0.98);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.file-button:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.hidden-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.card-dialog {
  width: min(560px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card-dialog::backdrop {
  background: rgba(31, 41, 51, 0.36);
}

.card-dialog form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-actions {
  justify-content: flex-end;
}

.dialog-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input[type="text"],
input[type="date"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

input[type="text"] {
  height: 40px;
  padding: 0 10px;
}

input[type="date"] {
  height: 40px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  min-height: 140px;
  padding: 10px;
  line-height: 1.45;
}

.file-link-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.source-status {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.attachments-list {
  display: grid;
  gap: 6px;
}

.attachment-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.attachment-chip.dragging {
  opacity: 0.5;
}

.attachment-chip.drop-before {
  box-shadow: inset 0 3px 0 var(--focus);
}

.attachment-chip.drop-after {
  box-shadow: inset 0 -3px 0 var(--focus);
}

.attachment-chip-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.attachment-drag-handle {
  min-width: 52px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: #4f5e70;
  cursor: grab;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.attachment-drag-handle:active {
  cursor: grabbing;
}

.attachment-chip span {
  overflow-wrap: anywhere;
  color: #344255;
  font-size: 13px;
  font-weight: 650;
}

.attachment-chip input {
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
  cursor: text;
}

.attachment-chip button {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid #e3b4b4;
  border-radius: 6px;
  background: #fff6f6;
  color: #9a2a2a;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.flag-field,
.color-field {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.flag-field legend,
.color-field legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.flag-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.flag-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.flag-option input {
  margin: 0;
}

.color-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="color"] {
  width: 42px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

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

.swatch {
  width: 28px;
  height: 28px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
}

.calendar-view,
.deadlines-view {
  min-height: calc(100vh - 76px);
  padding: 16px 20px 24px;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.view-header h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.view-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.month-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.month-controls strong {
  min-width: 160px;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  gap: 8px;
  overflow-x: auto;
}

.weekday {
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.calendar-day {
  min-height: 132px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.calendar-day.outside-month {
  background: #f0f3f6;
  color: var(--muted);
}

.calendar-day.today {
  border-color: var(--focus);
  box-shadow: inset 0 0 0 1px var(--focus);
}

.day-number {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
}

.calendar-card {
  display: grid;
  gap: 4px;
  margin-bottom: 6px;
  padding: 7px;
  border-left: 5px solid var(--card-color);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
}

.calendar-card strong {
  overflow-wrap: anywhere;
}

.calendar-card span {
  color: var(--muted);
}

.deadline-list {
  display: grid;
  gap: 10px;
  max-width: 960px;
}

.deadline-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 7px solid var(--card-color);
  border-radius: 8px;
  background: #fff;
}

.deadline-item h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
  letter-spacing: 0;
}

.deadline-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.days-left {
  min-width: 112px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #eef5ff;
  color: #264b78;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.days-left.due-soon {
  background: #fff8df;
  color: #6f4e00;
}

.days-left.overdue {
  background: #fff1f1;
  color: #8f2424;
}

.days-left.done-window {
  background: #eef9f4;
  color: #21604d;
}

.empty-view {
  display: grid;
  min-height: 180px;
  place-items: center;
  border: 1px dashed #c5ceda;
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
}

@media (max-width: 760px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .board {
    grid-auto-columns: minmax(260px, 86vw);
    min-height: calc(100vh - 122px);
    padding: 12px;
  }

  .column {
    min-height: calc(100vh - 154px);
    max-height: calc(100vh - 154px);
  }

  .view-header,
  .deadline-item {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .calendar-grid {
    grid-template-columns: repeat(7, minmax(118px, 1fr));
  }

  .month-controls {
    width: 100%;
    justify-content: space-between;
  }
}
