@import url("https://fonts.googleapis.com/css2?family=REM:wght@400;500;600;700;800;900&display=swap");

:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #f0f4f8;
  --border: #d9e1ec;
  --text: #1e2732;
  --muted: #6b7685;
  --accent: #3f6fbd;
  --accent-2: #2f7f91;
  --accent-3: #2f806b;
  --danger: #dc2626;
  --shadow: 0 14px 40px rgba(30, 39, 50, 0.08);
  --row-height: 48px;
  --day-width: 38px;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 28px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}

.logo {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.7rem);
  font-weight: 900;
  letter-spacing: 0.035em;
  line-height: 0.82;
  text-shadow: 0.45px 0 currentColor, -0.45px 0 currentColor, 0 0.45px currentColor;
}

.view-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
}

.view-toggle button,
.compact-toggle {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 0 12px;
}

.compact-toggle {
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0 6px 6px 0;
  background: transparent;
}

.view-toggle button.active,
.compact-toggle.active {
  background: var(--panel-soft);
  color: var(--text);
}

.title-head {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.collapse-all-toggle {
  width: 13px;
  height: 13px;
  margin-left: 1px;
  min-height: 0;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.38;
  padding: 0;
  position: relative;
}

.collapse-all-toggle:hover:not(:disabled),
.collapse-all-toggle:focus-visible {
  background: transparent;
  color: var(--text);
  opacity: 0.78;
  outline: none;
}

.collapse-all-toggle:disabled {
  cursor: default;
  opacity: 0.18;
}

.collapse-all-toggle.checked::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 5px;
  height: 8px;
  border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor;
  transform: rotate(45deg);
}

.planning-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}

.planning-toggle button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.planning-toggle button.active {
  background: var(--panel-soft);
  color: var(--text);
}

.primary-button,
.ghost-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.primary-button {
  background: #2f6fed;
  color: white;
  box-shadow: 0 8px 18px rgba(47, 111, 237, 0.16);
}

.ghost-button {
  background: white;
  color: var(--text);
  border-color: var(--border);
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 0 12px;
}

input:focus,
select:focus {
  outline: 3px solid rgba(37, 99, 235, 0.16);
  border-color: var(--accent);
}

input:invalid,
select:invalid {
  box-shadow: none;
}

.board {
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.task-list {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: #fbfcfe;
  overflow: hidden;
}

#taskRows {
  display: flex;
  flex-direction: column;
  overflow: auto;
}

#taskFooter {
  border-top: 1px solid #e9eef5;
  background: #fbfcfe;
}

.list-head,
.task-row,
.add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px 44px;
  align-items: center;
  min-height: var(--row-height);
  gap: 10px;
  padding: 0 14px;
}

.list-head {
  position: sticky;
  top: 0;
  z-index: 4;
  min-height: 72px;
  background: white;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 800;
}

.task-row {
  border-bottom: 1px solid #e9eef5;
  cursor: context-menu;
}

.task-row.starred {
  background: linear-gradient(90deg, rgba(245, 206, 92, 0.16), rgba(245, 206, 92, 0.07));
}

.task-row.subtask {
  grid-template-columns: minmax(0, 1fr) 28px;
}

.add-row {
  border: 0;
  background: #fbfcfe;
}

.add-row button {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-weight: 650;
  cursor: pointer;
  padding: 0;
}

.add-row.footer-add {
  border-top: 0;
}

.task-row.parent {
  background: linear-gradient(90deg, #f8fafc, var(--panel-soft));
  font-weight: 700;
  letter-spacing: 0.026em;
}

.task-row.parent.starred {
  background: linear-gradient(90deg, rgba(245, 206, 92, 0.18), rgba(240, 244, 248, 0.86));
}

.task-row.parent .task-dot {
  display: none;
}

.collapse-section {
  width: 16px;
  height: 16px;
  display: inline-grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: currentColor;
  cursor: pointer;
  opacity: 0.42;
  padding: 0;
  position: relative;
}

.collapse-section:hover,
.collapse-section:focus-visible {
  opacity: 0.82;
  outline: none;
}

.collapse-section::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
}

.collapse-section.collapsed::before {
  transform: rotate(-45deg) translate(-1px, 1px);
}

.icon-add {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 450;
  line-height: 1;
  cursor: pointer;
  padding: 0 0 1px;
  justify-self: end;
  opacity: 0;
  position: relative;
}

.task-row.parent:hover .icon-add,
.task-row.parent:focus-within .icon-add {
  opacity: 0.56;
}

.icon-add:hover,
.icon-add:focus-visible {
  opacity: 0.92;
  background: transparent;
  outline: none;
  box-shadow: none;
}

.icon-add::after,
.go-start-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 20;
  right: 0;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: 140px;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  box-shadow: 0 10px 22px rgba(30, 39, 50, 0.12);
  font-size: 0.68rem;
  font-weight: 550;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translateY(2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.icon-add:hover::after,
.icon-add:focus-visible::after,
.go-start-icon:hover::after,
.go-start-icon:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.section-length {
  width: max-content;
  max-width: 72px;
  padding: 0;
  color: var(--muted);
  border: 0;
  font-size: 0.68rem;
  font-weight: 550;
  white-space: nowrap;
}

.task-title {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.task-title-text {
  display: grid;
  min-width: 0;
  gap: 2px;
  max-width: 100%;
}

.task-title-text,
.task-title-text > :first-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-title-text {
  white-space: nowrap;
}

.subtask .task-title-text {
  font-size: 0.84rem;
  letter-spacing: 0.012em;
}

.task-title-text small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.1;
}

.compact-mode {
  --row-height: 34px;
}

.compact-mode .task-row.parent {
  min-height: var(--row-height);
}

.compact-mode .task-row.subtask {
  min-height: var(--row-height);
}

.compact-mode .task-title-text small {
  display: none;
}

.compact-mode .subtask .task-title {
  padding-left: 16px;
}

.compact-mode .subtask .task-title-text {
  font-size: 0.78rem;
  font-weight: 450;
}

.compact-mode .task-row.parent {
  font-size: 0.9rem;
  font-weight: 650;
}

.compact-mode .status-pie {
  width: 10px;
  height: 10px;
}

.compact-mode .bar {
  top: 5px;
  height: 24px;
  cursor: default;
}

.compact-mode .bar-resize {
  display: none;
}

.task-dot,
.status-pie {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 999px;
}

.task-dot {
  background: currentColor;
}

.status-pie {
  border: 1.5px solid currentColor;
  background: conic-gradient(currentColor var(--progress), transparent 0);
}

.status-pie.empty {
  background: transparent;
}

.subtask .task-title {
  padding-left: 26px;
}

.subtask .task-title-text {
  overflow: hidden;
}

.go-start-icon {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  justify-self: end;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  opacity: 0;
  padding: 0;
  position: relative;
}

.task-row.subtask:hover .go-start-icon,
.task-row.subtask:focus-within .go-start-icon {
  opacity: 0.46;
}

.go-start-icon:hover,
.go-start-icon:focus-visible {
  opacity: 0.9;
  background: #f0f4f8;
  outline: none;
}

.status-pill {
  width: 54px;
  min-height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: white;
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 800;
}

.timeline-wrap {
  overflow: auto;
  position: relative;
  min-height: 0;
}

.timeline-header,
.timeline-grid {
  min-width: max-content;
  width: 100%;
}

.timeline-header {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 72px;
  background: white;
  border-bottom: 1px solid var(--border);
}

.month-row,
.day-row {
  display: grid;
}

.month-row {
  min-height: 32px;
}

.day-row {
  min-height: 36px;
}

.month-cell {
  display: flex;
  align-items: center;
  padding: 0 18px;
  min-width: 0;
  border-left: 1px solid #d8deea;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.day-cell {
  display: grid;
  grid-template-columns: minmax(10px, auto) minmax(18px, auto);
  align-content: center;
  justify-content: center;
  justify-items: center;
  width: var(--day-width);
  min-height: 38px;
  border-right: 1px solid #edf1f6;
  color: var(--muted);
  font-size: 0.76rem;
  gap: 5px;
  padding: 0 10px;
  overflow: hidden;
  white-space: nowrap;
}

.day-cell strong {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 650;
}

.day-cell.month-start {
  box-shadow: inset 1px 0 0 #cbd5e1;
}

.day-cell.before-month-boundary {
  border-right-color: transparent;
}

.day-cell.month-marker {
  background: #fbfcfe;
}

.timeline-grid {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: calc(100% - 72px);
}

.timeline-row {
  position: relative;
  flex: 0 0 var(--row-height);
  min-height: var(--row-height);
  border-bottom: 1px solid #e9eef5;
  background-image: linear-gradient(to right, #edf1f6 1px, transparent 1px);
  background-size: var(--day-width) 100%;
}

.timeline-row.starred {
  background-color: rgba(245, 206, 92, 0.11);
}

.timeline-row.add-slot {
  background: #fbfcfe;
}

.timeline-row.footer-slot {
  margin-top: auto;
}

.timeline-row.parent {
  background-color: rgba(240, 244, 248, 0.76);
}

.timeline-row.parent.starred {
  background-color: rgba(245, 206, 92, 0.13);
}

.section-summary-line {
  position: absolute;
  top: calc(50% - 1px);
  height: 2px;
  border-radius: 999px;
  background-image: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px);
  opacity: 0.72;
}

.bar {
  position: absolute;
  top: 12px;
  height: 24px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(105, 126, 160, 0.12);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.bar.dragging {
  cursor: grabbing;
  opacity: 0.88;
}

.bar-resize {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  width: 12px;
  height: 100%;
  cursor: ew-resize;
}

.bar-resize::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 5px;
  width: 2px;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
}

.bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--progress);
  background: rgba(255, 255, 255, 0.32);
}

.bar-label {
  position: relative;
  z-index: 1;
  display: block;
  padding: 3px 10px 0;
  color: white;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 420px;
  text-align: center;
  padding: 40px;
}

.empty-state h2 {
  margin: 0 0 8px;
}

.login-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  background: white;
  box-shadow: 0 24px 70px rgba(30, 39, 50, 0.22);
}

.login-dialog::backdrop {
  background: rgba(30, 39, 50, 0.42);
  backdrop-filter: blur(2px);
}

.login-dialog form {
  display: grid;
  gap: 16px;
  padding: 26px;
}

.login-dialog h2 {
  margin: 0;
  font-size: 1.35rem;
}

.login-error {
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 650;
}

.context-menu {
  position: fixed;
  z-index: 20;
  width: 220px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  box-shadow: 0 18px 50px rgba(30, 39, 50, 0.18);
}

.context-menu button {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0 10px;
  cursor: pointer;
}

.context-menu button:hover {
  background: var(--panel-soft);
}

.context-menu .danger-action {
  color: var(--danger);
}

.menu-group {
  position: relative;
}

.menu-group::after {
  content: "";
  position: absolute;
  top: -8px;
  left: 100%;
  width: 18px;
  height: calc(100% + 16px);
}

.submenu-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.submenu-trigger span {
  color: var(--muted);
  font-size: 0.9rem;
}

.submenu {
  position: absolute;
  top: 0;
  left: calc(100% + 14px);
  width: 112px;
  display: none;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  box-shadow: 0 18px 50px rgba(30, 39, 50, 0.18);
}

.menu-group:hover .submenu,
.submenu:hover {
  display: block;
}

.edit-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(30, 39, 50, 0.24);
}

.edit-dialog::backdrop {
  background: rgba(30, 39, 50, 0.32);
}

.edit-dialog form {
  display: grid;
  gap: 14px;
}

.edit-dialog h2 {
  margin: 0;
  font-size: 1.2rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

@media (max-width: 920px) {
  .app-shell {
    padding: 16px;
  }

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

  .task-list {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}
