:root {
  color-scheme: light;
  --bg: #f8f5ef;
  --panel: #fffdf8;
  --panel-2: #f0f6f4;
  --ink: #1d2a2f;
  --muted: #607077;
  --line: #d9ddd7;
  --line-strong: #bec8c3;
  --teal: #315f72;
  --teal-2: #d9e9e8;
  --green: #2f7a5f;
  --green-soft: #dceee4;
  --red: #b84f45;
  --red-soft: #f5dfdb;
  --amber: #9b6728;
  --amber-soft: #f7ead8;
  --blue: #3b6597;
  --blue-soft: #e0ebf7;
  --shadow: 0 18px 50px rgba(29, 42, 47, 0.12);
  --radius: 8px;
  --tap: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  overflow-wrap: anywhere;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.35;
}

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

button {
  cursor: pointer;
  overflow-wrap: normal;
  white-space: nowrap;
}

.shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 68px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 245, 239, 0.92);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 8px;
  display: block;
  object-fit: cover;
  box-shadow: 0 1px 0 rgba(29, 42, 47, 0.12);
}

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

h1 {
  font-size: 17px;
  line-height: 1.1;
}

h2 {
  font-size: 24px;
  line-height: 1.1;
}

h3 {
  font-size: 17px;
}

.brand p,
.muted,
.task-meta,
.empty-state,
.small {
  color: var(--muted);
}

.brand p {
  margin-top: 2px;
  font-size: 12px;
}

.icon-button {
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  display: grid;
  place-items: center;
  box-shadow: 0 1px 0 rgba(29, 42, 47, 0.04);
}

.icon-button:active,
.nav-item:active,
.task-card:active,
.chip-button:active,
.primary-button:active {
  transform: translateY(1px);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: min(310px, 88vw);
  padding: max(18px, env(safe-area-inset-top)) 14px 18px;
  background: #fbfaf6;
  border-right: 1px solid var(--line);
  transform: translateX(-105%);
  transition: transform 180ms ease;
  overflow: auto;
}

.sidebar.open {
  transform: translateX(0);
  box-shadow: var(--shadow);
}

.sidebar-header,
.view-header,
.planner-sheet header,
.detail-header,
.section-title-row,
.filter-row,
.task-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-header {
  margin-bottom: 18px;
}

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

.nav-item {
  min-height: 46px;
  width: 100%;
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 9px 10px;
}

.nav-item.active {
  border-color: var(--line);
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(29, 42, 47, 0.04);
}

.nav-count {
  min-width: 28px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--teal-2);
  color: var(--teal);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.sidebar-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.section-kicker {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.load-meter {
  display: grid;
  gap: 8px;
}

.load-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  font-size: 13px;
}

.load-bar {
  grid-column: 1 / -1;
  height: 8px;
  border-radius: 999px;
  background: #e5e2da;
  overflow: hidden;
}

.load-bar span {
  display: block;
  height: 100%;
  background: var(--green);
}

.workspace {
  min-width: 0;
  padding: 12px 12px 88px;
}

.quick-add {
  position: sticky;
  top: 68px;
  z-index: 20;
  margin: 0 auto 12px;
  max-width: 1180px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 8px 28px rgba(29, 42, 47, 0.06);
}

.quick-add label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.quick-row input,
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
}

.quick-row input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 3px solid rgba(49, 95, 114, 0.18);
  border-color: var(--teal);
}

.quick-row button,
.primary-button {
  flex: 0 0 auto;
  min-height: var(--tap);
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: var(--teal);
  color: white;
  padding: 0 16px;
  font-weight: 800;
}

.quick-hints {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.auth-panel {
  margin-top: 10px;
}

.auth-form,
.auth-status {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.auth-form input {
  min-height: 36px;
  flex: 1 1 190px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 7px 9px;
}

.quick-hints span,
.pill,
.tag,
.status-pill,
.priority-pill,
.area-pill,
.source-pill,
.chip-button {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8f6f0;
  color: var(--muted);
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.content {
  max-width: 1180px;
  margin: 0 auto;
}

.view {
  display: grid;
  gap: 14px;
}

.view-header {
  align-items: flex-start;
  padding: 12px 2px;
}

.view-header p {
  margin-top: 5px;
  max-width: 760px;
  color: var(--muted);
}

.summary-grid,
.insight-grid,
.project-grid,
.brief-grid {
  display: grid;
  gap: 10px;
}

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

.metric,
.task-card,
.brief-card,
.project-card,
.calendar-day,
.filter-panel,
.empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(29, 42, 47, 0.04);
}

.metric {
  min-height: 96px;
  padding: 14px;
}

.metric strong {
  display: block;
  margin-bottom: 5px;
  font-size: 28px;
  line-height: 1;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.panel {
  padding: 4px 0;
}

.section-title-row {
  margin-bottom: 10px;
}

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

.task-card {
  min-width: 0;
  max-width: 100%;
  padding: 12px;
  display: grid;
  gap: 10px;
  overflow: hidden;
}

.task-card.selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(49, 95, 114, 0.14);
}

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

.task-title {
  min-width: 0;
  max-width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
  font-weight: 800;
  overflow-wrap: anywhere;
  white-space: normal;
}

.task-title.done {
  color: var(--muted);
  text-decoration: line-through;
}

.task-meta,
.task-actions,
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.task-meta {
  font-size: 12px;
  min-width: 0;
}

.task-actions {
  justify-content: space-between;
}

.chip-button {
  white-space: nowrap;
  min-height: 34px;
  background: white;
  color: var(--ink);
}

.chip-button.is-active,
.status-pill.status-in-progress,
.priority-pill.priority-p1 {
  border-color: transparent;
  background: var(--teal);
  color: white;
}

.status-pill.status-blocked,
.priority-pill.priority-p2 {
  border-color: transparent;
  background: var(--red-soft);
  color: var(--red);
}

.status-pill.status-waiting,
.status-pill.status-delegated,
.priority-pill.priority-p3 {
  border-color: transparent;
  background: var(--amber-soft);
  color: var(--amber);
}

.status-pill.status-done {
  border-color: transparent;
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.status-scheduled {
  border-color: transparent;
  background: var(--blue-soft);
  color: var(--blue);
}

.source-pill {
  max-width: 100%;
  background: var(--panel-2);
  color: var(--teal);
  overflow-wrap: anywhere;
  white-space: normal;
}

.area-pill {
  border-color: transparent;
  background: var(--green-soft);
  color: var(--green);
}

.save-pill {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--green-soft);
  color: var(--green);
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
}

.detail-save-note {
  margin-top: 6px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.task-card .muted {
  overflow-wrap: anywhere;
}

@media (max-width: 719px) {
  .task-title {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }

  .source-pill {
    max-width: min(100%, 330px);
  }
}

.horizon-board {
  display: grid;
  gap: 12px;
}

.horizon-column {
  min-height: 220px;
}

.drop-zone {
  min-height: 120px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.drop-zone.drag-over {
  outline: 3px solid rgba(49, 95, 114, 0.2);
  outline-offset: 4px;
}

.filter-panel {
  padding: 10px;
  display: grid;
  gap: 10px;
}

.filter-row {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.filter-row select,
.filter-row input {
  min-height: 38px;
  max-width: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 7px 9px;
}

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

.project-card,
.brief-card,
.calendar-day {
  padding: 13px;
}

.project-card {
  display: grid;
  gap: 10px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: #e5e2da;
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  background: var(--green);
}

.timeline {
  display: grid;
  gap: 10px;
}

.calendar-day {
  display: grid;
  gap: 8px;
}

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

.brief-body {
  white-space: pre-wrap;
  color: #2b383d;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.brief-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.empty-state {
  padding: 18px;
  text-align: center;
}

.detail-pane {
  display: none;
}

.detail-pane.open {
  display: block;
  position: fixed;
  inset: auto 0 0;
  z-index: 45;
  width: 100dvw;
  max-width: 100dvw;
  max-height: 82svh;
  overflow-y: auto;
  overflow-x: hidden;
  border-top: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
  overscroll-behavior-x: contain;
}

.detail-form {
  min-width: 0;
  max-width: 100%;
  display: grid;
  gap: 12px;
}

.field {
  min-width: 0;
  max-width: 100%;
  display: grid;
  gap: 6px;
}

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

.field textarea {
  min-height: 94px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(29, 42, 47, 0.32);
}

.planner-sheet {
  position: absolute;
  inset: auto 0 0;
  max-height: 88svh;
  overflow: auto;
  border-radius: 8px 8px 0 0;
  background: var(--bg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.planner-grid {
  display: grid;
  gap: 12px;
}

.planner-warning {
  border: 1px solid var(--amber);
  border-radius: var(--radius);
  background: var(--amber-soft);
  color: #5c3e18;
  padding: 10px;
}

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 90;
  min-height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #203940;
  color: white;
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

.toast.show {
  display: flex;
}

@media (min-width: 720px) {
  .shell {
    grid-template-columns: 236px minmax(0, 1fr);
    grid-template-rows: 1fr;
  }

  .topbar {
    display: none;
  }

  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: 100vh;
    transform: none;
    box-shadow: none;
  }

  .sidebar-header .icon-button,
  .sidebar-toggle {
    display: none;
  }

  .workspace {
    padding: 18px 18px 40px;
  }

  .quick-add {
    top: 18px;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .horizon-board {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .brief-grid {
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  }

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

  .planner-sheet {
    inset: 50% auto auto 50%;
    width: min(840px, calc(100vw - 48px));
    max-height: min(760px, calc(100vh - 48px));
    transform: translate(-50%, -50%);
    border-radius: var(--radius);
  }
}

@media (min-width: 1020px) {
  .shell {
    grid-template-columns: 248px minmax(0, 1fr) 360px;
  }

  .detail-pane {
    display: block;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    border-left: 1px solid var(--line);
    background: #fbfaf6;
    padding: 18px;
  }

  .detail-pane.open {
    position: sticky;
    inset: auto;
    max-height: none;
    box-shadow: none;
    border-top: 0;
  }

  .project-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
