:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #f9faf7;
  --ink: #1e2520;
  --muted: #687169;
  --line: #dfe5dc;
  --teal: #246f68;
  --teal-dark: #164f4a;
  --amber: #b86f16;
  --rose: #9b3d55;
  --shadow: 0 12px 30px rgba(30, 37, 32, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--teal);
}

button.danger {
  border-color: #e2b6c1;
  color: var(--rose);
}

button.danger:hover {
  border-color: var(--rose);
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.auth-panel {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 22px;
}

.auth-heading h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.auth-notice {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.auth-actions {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.primary:hover {
  background: var(--teal-dark);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(360px, 1fr) minmax(320px, 430px);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.app-navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}

.nav-account {
  min-width: 0;
}

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

.sidebar,
.plan-panel,
.report-panel,
.admin-page {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.brand h1,
.panel-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
}

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

.icon-button {
  min-width: 62px;
  padding: 0 12px;
}

.project-box {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.account-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.account-name {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-role,
.day-status {
  color: var(--muted);
  font-size: 12px;
}

.project-select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: center;
}

.project-control-wrap {
  position: relative;
}

.round-icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.user-create-panel,
.invite-panel {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.members-list,
.received-invites,
.invite-output {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.member-row,
.received-invite {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 8px;
  font-size: 12px;
}

.member-row.editable {
  cursor: pointer;
}

.member-summary,
.received-invite {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.member-row strong,
.received-invite span {
  color: var(--muted);
  font-size: 11px;
}

.member-editor {
  display: grid;
  grid-template-columns: 1fr 1fr 36px auto;
  gap: 6px;
  align-items: center;
}

.member-editor label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
}

.member-save {
  min-width: 36px;
  padding: 0;
  border-color: var(--teal);
  color: var(--teal-dark);
  font-weight: 800;
}

.received-invite button {
  min-height: 30px;
  padding: 0 8px;
}

.invite-output {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.invite-link {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--ink);
}

.popover-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.days {
  overflow: auto;
  padding: 10px;
}

.day-button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
  padding: 11px 12px;
  text-align: left;
}

.day-button.active {
  border-color: var(--teal);
  background: #eef7f4;
}

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

.day-date {
  display: block;
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
}

.day-name {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-status {
  display: block;
  margin-top: 3px;
}

.day-markers {
  display: flex;
  align-items: center;
  gap: 4px;
}

.day-progress {
  margin-right: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.marker {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--line);
}

.marker.plan {
  background: var(--teal);
}

.marker.report {
  background: var(--amber);
}

.marker.discussion {
  background: var(--rose);
}

.plan-panel,
.report-panel,
.admin-page {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 104px);
  overflow: hidden;
}

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

.header-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.plan-status-badge {
  min-width: 98px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef7f4;
  color: var(--teal-dark);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.plan-status-badge[data-status="rewrite_requested"],
.plan-status-badge[data-status="reported"] {
  background: #fff8ee;
  color: var(--amber);
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.top-action-button {
  min-width: 0;
  padding: 0 12px;
  font-weight: 700;
  white-space: nowrap;
}

.top-action-button.active {
  border-color: var(--teal);
  background: #eef7f4;
  color: var(--teal-dark);
}

.popover-wrap {
  position: relative;
}

.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  display: grid;
  width: min(320px, calc(100vw - 32px));
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px;
}

.popover .user-create-panel,
.popover .invite-panel {
  margin-top: 0;
}

.invite-panel.popover {
  left: 0;
  right: 0;
  width: auto;
}

.popover-title,
.workspace-subhead {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.bell-button {
  position: relative;
  min-width: 42px;
}

.invite-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--rose);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-weight: 800;
}

.bell-button.has-unread {
  animation: bell-shake 1.6s ease-in-out infinite;
}

@keyframes bell-shake {
  0%,
  78%,
  100% {
    transform: rotate(0);
  }
  82% {
    transform: rotate(8deg);
  }
  86% {
    transform: rotate(-8deg);
  }
  90% {
    transform: rotate(5deg);
  }
}

.plan-status-badge[data-status="approved"],
.plan-status-badge[data-status="analyzed"] {
  background: #f3fbf6;
  color: var(--teal-dark);
}

.approval-bar {
  display: grid;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.approval-context {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.approval-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
}

.approval-actions button {
  min-width: 0;
  padding: 0 8px;
}

.plan-scroll {
  flex: 1;
  overflow: auto;
}

.markdown-view {
  padding: 20px;
  line-height: 1.58;
}

.item-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 14px 20px 0;
}

.summary-metric,
.summary-empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.summary-metric strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.1;
}

.summary-metric span,
.summary-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.plan-items {
  display: grid;
  gap: 10px;
  padding: 14px 20px 0;
}

.plan-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.plan-item.done {
  border-color: #9ac9af;
  background: #f3fbf6;
}

.plan-item.partial {
  border-color: #d7bd83;
  background: #fffaf0;
}

.plan-item.blocked {
  border-color: #d9a2b1;
  background: #fff6f8;
}

.plan-item.skipped {
  background: #f5f6f4;
}

.item-topline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.item-status {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 6px 8px;
}

.item-kind {
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef7f4;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
}

.item-kind.optional {
  background: #f4efe7;
  color: var(--amber);
}

.item-updated {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

.item-text {
  line-height: 1.45;
  font-weight: 700;
}

.item-section {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.item-comment,
.item-blocker,
.item-artifact {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.item-comment {
  min-height: 64px;
  resize: vertical;
  padding: 9px;
  line-height: 1.45;
}

.item-blocker,
.item-artifact {
  min-height: 36px;
  padding: 8px 9px;
}

.item-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.item-actions button {
  min-height: 34px;
  padding: 0 12px;
}

.markdown-view h1,
.markdown-view h2,
.markdown-view h3 {
  margin: 0 0 12px;
  line-height: 1.25;
}

.markdown-view h1 {
  font-size: 26px;
}

.markdown-view h2 {
  margin-top: 22px;
  font-size: 19px;
}

.markdown-view h3 {
  margin-top: 18px;
  font-size: 16px;
}

.markdown-view p,
.markdown-view ul,
.markdown-view pre {
  margin: 0 0 13px;
}

.markdown-view ul {
  padding-left: 22px;
}

.markdown-view code,
.markdown-view pre {
  border-radius: 8px;
  background: #f0f3ee;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.markdown-view code {
  padding: 2px 5px;
}

.markdown-view pre {
  overflow: auto;
  padding: 12px;
}

.report-panel {
  padding: 0 18px 18px;
  overflow: visible;
}

.report-panel .panel-header {
  margin: 0 -18px 16px;
}

.admin-page {
  grid-column: 1 / -1;
}

.admin-content {
  width: min(980px, 100%);
  padding: 18px 20px 22px;
}

.admin-route,
.plan-route {
  grid-template-columns: 1fr;
}

.plan-route .report-panel {
  grid-column: 1 / -1;
  min-height: calc(100vh - 104px);
}

.plan-workspace {
  display: block;
}

.plan-workspace-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.2fr) minmax(320px, 0.8fr);
  gap: 16px;
  min-height: 0;
}

.plan-editor-pane,
.plan-chat-pane {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.workspace-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.field-label.compact {
  margin: 0;
}

.plan-workspace-items {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.workspace-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
  font-size: 13px;
}

.workspace-item strong {
  border-radius: 999px;
  background: #eef7f4;
  color: var(--teal-dark);
  padding: 3px 7px;
  font-size: 11px;
}

.workspace-item.optional strong {
  background: #f4efe7;
  color: var(--amber);
}

.admin-users-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.admin-user-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(150px, 1fr) 150px minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.admin-user-title {
  min-width: 0;
}

.admin-user-title strong,
.admin-user-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-user-title span {
  color: var(--muted);
  font-size: 12px;
}

.admin-user-actions {
  display: flex;
  gap: 6px;
}

.panel-tabs,
.mode-switch {
  display: grid;
  gap: 8px;
}

.panel-tabs {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 12px;
}

.mode-switch {
  grid-template-columns: 1fr 1fr;
  margin: 12px 0;
}

.tab-button,
.mode-button {
  min-width: 0;
  padding: 8px 10px;
  color: var(--muted);
  font-weight: 700;
}

.tab-button.active,
.mode-button.active {
  border-color: var(--teal);
  background: #eef7f4;
  color: var(--teal-dark);
}

.tool-section,
.plan-mode {
  min-height: 0;
}

.tool-section {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.field-label {
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.text-input,
.report-input,
.guided-input,
.plan-input,
.discussion-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.text-input {
  min-height: 40px;
  padding: 9px 11px;
}

.report-input {
  min-height: 120px;
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

.guided-input {
  min-height: 76px;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
}

.plan-input,
.discussion-input {
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

.plan-input {
  min-height: 310px;
}

.discussion-input {
  min-height: 130px;
}

.file-input {
  width: 100%;
  min-height: 40px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel-soft);
  color: var(--muted);
}

.discussion-messages {
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.discussion-message {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.discussion-message.operator {
  border-color: #e3c9a5;
  background: #fff8ee;
}

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

.message-body {
  margin-top: 5px;
  white-space: pre-wrap;
  line-height: 1.45;
}

.message-path {
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.actions.single {
  grid-template-columns: 1fr;
}

.status-output {
  min-height: 86px;
  max-height: 170px;
  margin: 12px 0 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1e2520;
  color: #eaf0e8;
  padding: 10px;
  white-space: pre-wrap;
  font-size: 12px;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 280px minmax(360px, 1fr);
  }

  .report-panel {
    grid-column: 1 / -1;
    min-height: 520px;
  }

  .plan-workspace-grid,
  .admin-user-row {
    grid-template-columns: 1fr;
  }

  .admin-user-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .app-navbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .nav-actions .top-action-button {
    flex: 1 1 auto;
  }

  .panel-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions .popover-wrap {
    flex: 1;
  }

  .top-action-button {
    width: 100%;
  }

  .popover {
    left: 0;
    right: auto;
    width: min(100%, calc(100vw - 32px));
  }

  .invite-panel.popover {
    left: 0;
    right: 0;
    width: auto;
  }

  .sidebar,
  .plan-panel,
  .report-panel,
  .admin-page {
    min-height: auto;
  }

  .days {
    max-height: 260px;
  }

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

  .approval-actions {
    grid-template-columns: 1fr 1fr;
  }

  .item-summary {
    grid-template-columns: 1fr;
  }

  .item-topline {
    align-items: stretch;
    flex-direction: column;
  }

  .item-updated {
    margin-left: 0;
  }

  .member-editor,
  .workspace-row {
    grid-template-columns: 1fr;
  }
}
