/* ==========================================================================
   TRACE — persistent open-tasks terminal
   Clean Option C implementation
   ========================================================================== */

.ot,
.ot * {
  box-sizing: border-box;
}

.ot {
  --ot-bg: #0b0f17;
  --ot-header: #161b22;
  --ot-border: #30363d;
  --ot-accent: #7ee787;
  --ot-text: #e6edf3;
  --ot-meta: #8b949e;
  --ot-link: #ffb454;
  --ot-hover: rgba(255, 255, 255, 0.045);
  --ot-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);

  --ot-registration-accent: #c084fc;
  --ot-registration-icon-bg: rgba(168, 85, 247, 0.18);
  --ot-registration-icon-text: #d8b4fe;
  --ot-registration-pill-bg: #eef2ff;
  --ot-registration-pill-text: #4338ca;

  --ot-access-accent: #facc15;
  --ot-access-icon-bg: rgba(234, 179, 8, 0.18);
  --ot-access-icon-text: #fde047;
  --ot-access-pill-bg: #faf5ff;
  --ot-access-pill-text: #7e22ce;

  --ot-action-bg: #fef3c7;
  --ot-action-text: #92400e;

  position: relative;
  width: 100%;
  margin-top: 0.55rem;
}

.ot[data-ot-theme="light"] {
  --ot-bg: #ffffff;
  --ot-header: var(--sidebar-bg);
  --ot-border: var(--sidebar-border);
  --ot-accent: var(--trace-blue);
  --ot-text: var(--text-main);
  --ot-meta: var(--text-muted);
  --ot-link: var(--trace-blue-dark);
  --ot-hover: #eef2f7;
  --ot-shadow: 0 18px 50px rgba(16, 24, 40, 0.2);
}

/* ---------- Sidebar trigger ---------- */

.ot-trigger {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.42rem 0.55rem;
  border: 1px solid var(--sidebar-border);
  border-radius: 0.5rem;
  background: transparent;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.ot-trigger:hover,
.ot-trigger:focus-visible {
  background: #eef2f7;
  color: var(--text-main);
}

.ot-trigger:focus-visible {
  outline: 2px solid var(--trace-blue);
  outline-offset: 2px;
}

.ot-trigger-icon,
.ot-minimized-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #1e293b, #0b1020);
}

.ot-trigger-icon {
  width: 28px;
  height: 28px;
  flex-basis: 28px;
}

.ot-trigger-icon .bi,
.ot-minimized-icon > .bi {
  width: auto;
  color: #fca5a5;
  line-height: 1;
  animation: ot-heartbeat 0.9s ease-in-out infinite;
}

.ot-trigger-icon .bi {
  font-size: 0.95rem;
}

.ot-trigger-dot,
.ot-minimized-dot {
  position: absolute;
  top: 1px;
  right: 0;
  width: 7px;
  height: 7px;
  border: 1px solid #fff;
  border-radius: 50%;
  background: #ef4444;
}

.ot-trigger-dot::after,
.ot-minimized-dot::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid #ef4444;
  border-radius: inherit;
  animation: ot-pulse-ring 1.35s ease-out infinite;
}

.ot-trigger-label {
  min-width: 0;
  flex: 1 1 auto;
}

.ot-trigger-count,
.ot-minimized-count {
  min-width: 1.55rem;
  height: 1.35rem;
  padding: 0 0.42rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

/* ---------- Terminal window ---------- */

.ot-window {
  position: fixed;
  left: 0;
  bottom: 64px;
  z-index: 1080;
  width: 600px;
  max-width: calc(100vw - 1rem);
  overflow: hidden;
  border: 1px solid var(--ot-border);
  border-radius: 10px;
  background: var(--ot-bg);
  color: var(--ot-text);
  box-shadow: var(--ot-shadow);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    width 0.2s ease,
    opacity 0.16s ease,
    transform 0.16s ease,
    visibility 0s linear 0.16s;
}

.ot[data-ot-open="true"] .ot-window {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
  transition:
    width 0.2s ease,
    opacity 0.16s ease,
    transform 0.16s ease,
    visibility 0s;
}

.ot[data-ot-zoomed="true"] .ot-window {
  width: 760px;
}

/* ---------- Minimized state ---------- */

.ot-minimized-summary {
  display: none;
}

.ot[data-ot-minimized="true"] .ot-window {
  position: absolute;
  left: -0.65rem;
  bottom: calc(100% + 0.55rem);
  width: var(--sidebar-width);
  max-width: none;
  min-height: 0;
  transform: none;
}

.ot[data-ot-minimized="true"][data-ot-open="true"] .ot-window {
  transform: none;
}

.ot[data-ot-minimized="true"] .ot-body {
  display: none;
}

.ot[data-ot-minimized="true"] .ot-titlebar {
  min-height: 52px;
  padding: 0;
  overflow: hidden;
  border-bottom: 0;
  border-radius: 10px;
}

.ot[data-ot-minimized="true"] .ot-window-controls,
.ot[data-ot-minimized="true"] .ot-title,
.ot[data-ot-minimized="true"] .ot-theme-toggle {
  display: none;
}

.ot[data-ot-minimized="true"] .ot-minimized-summary {
  width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.7rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ot-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ot[data-ot-minimized="true"] .ot-minimized-summary:hover {
  background: var(--ot-hover);
}

.ot-minimized-icon {
  width: 31px;
  height: 31px;
  flex-basis: 31px;
}

.ot-minimized-icon > .bi {
  font-size: 1rem;
}

.ot-minimized-label {
  min-width: 0;
  flex: 1 1 auto;
  color: var(--ot-text);
  font-size: 0.78rem;
  font-weight: 700;
}

.ot-minimized-restore {
  color: var(--ot-meta);
  font-size: 0.9rem;
}

/* ---------- Title bar ---------- */

.ot-titlebar {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--ot-border);
  background: var(--ot-header);
}

.ot-window-controls {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.ot-window-button {
  width: 12px;
  height: 12px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
  cursor: pointer;
}

.ot-window-button:focus-visible,
.ot-theme-toggle:focus-visible,
.ot-show-more:focus-visible,
.ot-review-link:focus-visible,
.ot-minimized-summary:focus-visible {
  outline: 2px solid var(--ot-accent);
  outline-offset: 2px;
}

.ot-window-close {
  background: #ff5f57;
}

.ot-window-minimize {
  background: #febc2e;
}

.ot-window-zoom {
  background: #28c840;
}

.ot-title {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  color: var(--ot-text);
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ot-theme-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.48rem;
  border: 1px solid var(--ot-border);
  border-radius: 999px;
  background: var(--ot-bg);
  color: var(--ot-meta);
  font: inherit;
  font-size: 0.64rem;
  line-height: 1;
  cursor: pointer;
}

.ot-theme-toggle:hover {
  background: var(--ot-hover);
  color: var(--ot-text);
}

/* ---------- Terminal body ---------- */

.ot-body {
  padding: 0.85rem;
  background: var(--ot-bg);
}

.ot-command {
  min-width: 0;
  display: flex;
  align-items: center;
  color: var(--ot-text);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: nowrap;
}

.ot-prompt {
  margin-right: 0.45rem;
  color: var(--ot-accent);
  font-weight: 700;
}

.ot-command-text {
  display: inline-block;
  width: 0;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  animation: ot-type-command 1.4s steps(34, end) forwards;
}

.ot-cursor {
  width: 0.48rem;
  height: 0.92rem;
  margin-left: 0.16rem;
  display: inline-block;
  background: var(--ot-accent);
  animation: ot-cursor-blink 0.85s step-end infinite;
}

.ot-result-summary {
  margin-top: 0.3rem;
  color: var(--ot-meta);
  font-size: 0.68rem;
}

.ot-task-list {
  max-height: min(520px, calc(100vh - 210px));
  margin-top: 0.75rem;
  padding: 0.15rem 0.2rem 0.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--ot-border) transparent;
}

.ot[data-ot-zoomed="true"] .ot-task-list {
  max-height: min(650px, calc(100vh - 180px));
}

.ot-task-list::-webkit-scrollbar {
  width: 8px;
}

.ot-task-list::-webkit-scrollbar-track {
  background: transparent;
}

.ot-task-list::-webkit-scrollbar-thumb {
  border: 2px solid var(--ot-bg);
  border-radius: 999px;
  background: var(--ot-border);
}

/* ---------- Elevated task cards ---------- */

.ot-task-extra {
  display: none;
}

.ot[data-ot-expanded="true"] .ot-task-extra {
  display: grid;
}

.ot-card {
  --ot-card-accent: var(--ot-registration-accent);
  --ot-card-icon-bg: var(--ot-registration-icon-bg);
  --ot-card-icon-text: var(--ot-registration-icon-text);

  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 0.7rem;
  margin: 0 0 0.65rem;
  padding: 0.78rem 0.8rem;
  overflow: hidden;
  border: 1px solid var(--ot-border);
  border-radius: 9px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.035),
    rgba(255, 255, 255, 0.012)
  );
  box-shadow:
    0 5px 15px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.025);
  animation: ot-row-enter 0.3s ease-out both;
  animation-delay: calc(1.05s + (var(--i) * 70ms));
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.ot-card:last-child {
  margin-bottom: 0;
}

.ot-card:hover {
  border-color: var(--ot-card-accent);
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.055),
    rgba(255, 255, 255, 0.02)
  );
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.035);
  transform: translateY(-1px);
}

.ot-card-access {
  --ot-card-accent: var(--ot-access-accent);
  --ot-card-icon-bg: var(--ot-access-icon-bg);
  --ot-card-icon-text: var(--ot-access-icon-text);
}

.ot-card-accent {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--ot-card-accent);
  box-shadow: 0 0 14px rgba(192, 132, 252, 0.28);
}

.ot-card-access .ot-card-accent {
  box-shadow: 0 0 14px rgba(250, 204, 21, 0.26);
}

.ot-card-icon {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: start;
  border: 1px solid var(--ot-card-accent);
  border-radius: 9px;
  background: var(--ot-card-icon-bg);
  color: var(--ot-card-icon-text);
}

.ot-card-icon .bi {
  font-size: 1.15rem;
}

.ot-card-content,
.ot-card-title-wrap {
  min-width: 0;
}

.ot-card-heading {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.ot-card-title-wrap {
  flex: 1 1 auto;
}

.ot-card-status {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
}

.ot-task-title {
  margin: 0;
  color: var(--ot-text);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
}

.ot-task-meta {
  margin-top: 0.18rem;
  color: var(--ot-meta);
  font-size: 0.66rem;
  line-height: 1.4;
}

.ot-relative-time {
  min-width: 0;
  overflow: hidden;
  color: var(--ot-meta);
  font-size: 0.62rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ot-type-pill,
.ot-action-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 700;
  line-height: 1;
}

.ot-type-pill {
  padding: 0.24rem 0.48rem;
  font-size: 0.62rem;
}

.ot-type-registration {
  background: var(--ot-registration-pill-bg);
  color: var(--ot-registration-pill-text);
}

.ot-type-access {
  background: var(--ot-access-pill-bg);
  color: var(--ot-access-pill-text);
}

/* ---------- Normal summary ---------- */

.ot-card-summary {
  margin-top: 0.65rem;
  padding-top: 0.62rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--ot-border);
}

.ot-summary-field {
  min-width: 0;
  padding: 0 0.55rem;
  border-right: 1px solid var(--ot-border);
}

.ot-summary-field:first-child {
  padding-left: 0;
}

.ot-summary-field:last-child {
  padding-right: 0;
  border-right: 0;
}

.ot-summary-field span,
.ot-extended-grid span {
  display: block;
  margin-bottom: 0.14rem;
  color: var(--ot-meta);
  font-size: 0.57rem;
  font-weight: 500;
}

.ot-summary-field strong,
.ot-extended-grid strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--ot-text);
  font-size: 0.64rem;
  font-weight: 500;
  line-height: 1.4;
}

/* ---------- Zoom-only extended details ---------- */

.ot-card-extended {
  display: none;
}

.ot[data-ot-zoomed="true"] .ot-card-summary {
  display: none;
}

.ot[data-ot-zoomed="true"] .ot-card-extended {
  margin-top: 0.7rem;
  padding: 0.72rem;
  display: block;
  border: 1px solid var(--ot-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.08);
}

.ot[data-ot-theme="light"][data-ot-zoomed="true"] .ot-card-extended {
  background: #f8fafc;
}

.ot-extended-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.72rem 1rem;
}

.ot-extended-wide {
  grid-column: 1 / -1;
}

.ot-extended-grid p {
  margin: 0;
  color: var(--ot-text);
  font-size: 0.65rem;
  line-height: 1.55;
}

/* ---------- Card footer ---------- */

.ot-task-footer {
  margin-top: 0.65rem;
  padding-top: 0.62rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  border-top: 1px solid var(--ot-border);
}

.ot-action-pill {
  padding: 0.25rem 0.48rem;
  background: var(--ot-action-bg);
  color: var(--ot-action-text);
  font-size: 0.6rem;
}

.ot-review-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.36rem 0.65rem;
  border: 1px solid var(--ot-card-accent);
  border-radius: 6px;
  color: var(--ot-card-accent);
  font-size: 0.67rem;
  font-weight: 700;
  text-decoration: none;
}

.ot-review-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--ot-card-accent);
  text-decoration: none;
}

/* ---------- Show more ---------- */

.ot-show-more {
  width: 100%;
  margin-top: 0.55rem;
  padding: 0.42rem 0.5rem;
  border: 1px solid var(--ot-border);
  border-radius: 7px;
  background: transparent;
  color: var(--ot-accent);
  font: inherit;
  font-size: 0.67rem;
  text-align: left;
  cursor: pointer;
}

.ot-show-more:hover {
  background: var(--ot-hover);
}

.ot-show-more-open {
  display: none;
}

.ot[data-ot-expanded="true"] .ot-show-more-closed {
  display: none;
}

.ot[data-ot-expanded="true"] .ot-show-more-open {
  display: inline;
}

/* ---------- Light theme card refinements ---------- */

.ot[data-ot-theme="light"] .ot-card {
  background: #fff;
  box-shadow:
    0 4px 14px rgba(16, 24, 40, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.ot[data-ot-theme="light"] .ot-card:hover {
  background: #fff;
  box-shadow:
    0 8px 22px rgba(16, 24, 40, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.ot[data-ot-theme="light"] .ot-review-link:hover {
  background: #eef2f7;
}

/* ---------- Animations ---------- */

@keyframes ot-heartbeat {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.32);
  }
}

@keyframes ot-pulse-ring {
  0% {
    opacity: 0.75;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(2.5);
  }
}

@keyframes ot-type-command {
  from {
    width: 0;
  }

  to {
    width: 34ch;
  }
}

@keyframes ot-cursor-blink {
  0%,
  49% {
    opacity: 1;
  }

  50%,
  100% {
    opacity: 0;
  }
}

@keyframes ot-row-enter {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ---------- Responsive protection ---------- */

@media (max-width: 820px) {
  .ot-window,
  .ot[data-ot-zoomed="true"] .ot-window {
    width: calc(100vw - 1rem);
  }

  .ot-card-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem 0;
  }

  .ot-summary-field:nth-child(2) {
    border-right: 0;
  }

  .ot-summary-field:nth-child(3) {
    padding-left: 0;
  }
}

@media (max-width: 620px) {
  .ot-card {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 0.55rem;
    padding: 0.7rem;
  }

  .ot-card-icon {
    width: 34px;
    height: 34px;
  }

  .ot-card-heading,
  .ot-card-status {
    display: block;
  }

  .ot-card-status {
    margin-top: 0.4rem;
  }

  .ot-type-pill {
    margin-left: 0.4rem;
  }

  .ot-extended-grid {
    grid-template-columns: 1fr;
  }

  .ot-extended-wide {
    grid-column: auto;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .ot-trigger,
  .ot-window,
  .ot-trigger-icon .bi,
  .ot-minimized-icon > .bi,
  .ot-trigger-dot::after,
  .ot-minimized-dot::after,
  .ot-command-text,
  .ot-cursor,
  .ot-card {
    animation: none;
    transition: none;
  }

  .ot-command-text {
    width: auto;
  }

  .ot-cursor {
    opacity: 1;
  }

  .ot-card:hover {
    transform: none;
  }
}
