:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #66727b;
  --line: #dbe2e7;
  --surface: #ffffff;
  --surface-soft: #f4f7f8;
  --field: #fbfcfc;
  --teal: #2a9d8f;
  --coral: #e76f51;
  --gold: #f3c14b;
  --blue: #4f7cac;
  --plum: #5b5474;
  --shadow: 0 16px 46px rgba(23, 32, 38, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(42, 157, 143, 0.08), transparent 32%),
    linear-gradient(315deg, rgba(231, 111, 81, 0.09), transparent 34%),
    #eef3f5;
}

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

button {
  border: 0;
  cursor: pointer;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(79, 124, 172, 0.36);
  outline-offset: 2px;
}

.icon-sprite {
  display: none;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  width: min(1680px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 18px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(42, 157, 143, 0.24);
}

.brand-icon svg {
  width: 25px;
  height: 25px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 1.9vw, 2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand-mark p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.top-actions,
.button-row,
.summary-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-button,
.primary-action,
.secondary-action,
.wide-action,
.icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: var(--radius);
  font-weight: 750;
  letter-spacing: 0;
  white-space: nowrap;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.icon-button,
.secondary-action,
.wide-action {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
}

.icon-button {
  padding: 0 13px;
  text-decoration: none;
}

.icon-button.subtle {
  color: #8d3f2e;
}

.icon-button.danger-confirm {
  color: #fff;
  background: #a9442f;
  border-color: #a9442f;
}

.primary-action {
  color: #fff;
  background: #172026;
  padding: 0 16px;
  box-shadow: 0 12px 24px rgba(23, 32, 38, 0.16);
}

.secondary-action {
  padding: 0 15px;
}

.wide-action {
  width: 100%;
  margin-top: 12px;
  padding: 0 14px;
}

.icon-only {
  width: 44px;
  min-width: 44px;
  color: #fff;
  background: var(--teal);
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.88fr) minmax(420px, 1.52fr) minmax(300px, 0.88fr);
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(219, 226, 231, 0.96);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.inbox-panel,
.loop-panel,
.now-panel {
  padding: 16px;
}

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

.panel-title h2 {
  margin-top: 2px;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.eyebrow,
.field-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field-label {
  display: block;
  margin: 14px 0 7px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 9px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

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

textarea {
  min-height: 248px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

.button-row {
  margin-top: 10px;
}

.quick-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input {
  min-height: 44px;
  padding: 0 12px;
}

.mode-block {
  margin-top: 14px;
}

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

.segment {
  min-width: 0;
  min-height: 36px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  border-radius: 6px;
  font-weight: 800;
}

.segment.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 6px 18px rgba(23, 32, 38, 0.08);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.loop-title {
  align-items: center;
}

.summary-strip {
  justify-content: flex-end;
}

.summary-tile {
  display: grid;
  min-width: 76px;
  padding: 8px 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.summary-tile strong {
  font-size: 1rem;
  line-height: 1;
}

.summary-tile span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.route-rail {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

.route-node {
  position: relative;
  display: grid;
  min-height: 78px;
  padding: 10px 8px;
  align-content: center;
  justify-items: center;
  gap: 6px;
  overflow: hidden;
  text-align: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.route-node::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--accent, var(--teal));
  opacity: 0.9;
}

.route-node.current {
  background: #fff;
  border-color: color-mix(in srgb, var(--accent, var(--teal)) 54%, var(--line));
  box-shadow: 0 12px 26px rgba(23, 32, 38, 0.12);
}

.route-node.done {
  opacity: 0.58;
}

.route-dot {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: #fff;
  background: var(--accent, var(--teal));
  border-radius: 50%;
}

.route-dot svg {
  width: 17px;
  height: 17px;
}

.route-node span {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 0.76rem;
  font-weight: 850;
  line-height: 1.05;
}

.route-node small {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 750;
}

.stop-stack {
  display: grid;
  gap: 12px;
}

.stop-lane {
  background: rgba(244, 247, 248, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.stop-lane.drag-over {
  border-color: var(--accent, var(--teal));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, var(--teal)) 20%, transparent);
}

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

.stop-name {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.stop-name .route-dot {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
}

.stop-name h3 {
  overflow-wrap: anywhere;
  font-size: 0.98rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.stop-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.task-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.task-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(112px, 142px) auto auto;
  gap: 8px;
  align-items: center;
  min-height: 58px;
  padding: 8px;
  background: #fff;
  border: 1px solid rgba(219, 226, 231, 0.92);
  border-left: 5px solid var(--accent, var(--teal));
  border-radius: var(--radius);
}

.task-card.priority {
  border-top-color: color-mix(in srgb, var(--coral) 48%, var(--line));
  box-shadow: inset 0 0 0 1px rgba(231, 111, 81, 0.12);
}

.task-card.done {
  opacity: 0.55;
}

.task-card.done .task-title {
  text-decoration: line-through;
}

.check-button,
.task-action {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.check-button.checked {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.task-body {
  min-width: 0;
}

.task-title {
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.2;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 5px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 23px;
  padding: 0 7px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

.chip.priority-chip {
  color: #9a402d;
  background: rgba(231, 111, 81, 0.12);
  border-color: rgba(231, 111, 81, 0.24);
}

select {
  min-height: 36px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

#routeCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1.95 / 1;
  margin: 2px 0 14px;
  background: #f6f8f6;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.next-card {
  min-height: 172px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.next-card.empty {
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.next-stop {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 9px;
  color: #fff;
  background: var(--accent, var(--teal));
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 850;
}

.next-card h3 {
  margin-top: 12px;
  overflow-wrap: anywhere;
  font-size: clamp(1.2rem, 2.2vw, 1.68rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.next-card .task-meta {
  margin-top: 12px;
}

.compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 11px 13px;
  color: #fff;
  background: #172026;
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(23, 32, 38, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  font-size: 0.92rem;
  font-weight: 750;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed #c7d0d7;
  border-radius: var(--radius);
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 1.05rem;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(300px, 0.86fr) minmax(420px, 1.14fr);
  }

  .now-panel {
    grid-column: 1 / -1;
  }

  .now-panel {
    display: grid;
    grid-template-columns: minmax(280px, 0.95fr) minmax(300px, 1.05fr);
    gap: 14px;
  }

  .now-panel .panel-title,
  .now-panel #routeCanvas {
    grid-column: 1;
  }

  .now-panel .next-card,
  .now-panel .button-row,
  .now-panel .wide-action {
    grid-column: 2;
  }
}

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

  .topbar,
  .workspace,
  .now-panel {
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: stretch;
  }

  .icon-button {
    flex: 1 1 30%;
  }

  .now-panel .panel-title,
  .now-panel #routeCanvas,
  .now-panel .next-card,
  .now-panel .button-row,
  .now-panel .wide-action {
    grid-column: 1;
  }

  .route-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .task-card {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
  }

  .task-card select {
    grid-column: 2 / -1;
  }

  textarea {
    min-height: 210px;
  }
}

@media (max-width: 520px) {
  .panel {
    box-shadow: 0 10px 28px rgba(23, 32, 38, 0.1);
  }

  .inbox-panel,
  .loop-panel,
  .now-panel {
    padding: 12px;
  }

  .summary-strip {
    width: 100%;
  }

  .summary-tile {
    min-width: 0;
    flex: 1 1 30%;
  }

  .route-rail {
    grid-template-columns: 1fr;
  }

  .button-row:not(.compact) {
    display: grid;
    grid-template-columns: 1fr;
  }
}
