/* ═══════════════════════════════════════════════════════════════
   CONTEXT PANEL — Narrative context drawer
   100% Cloto design tokens — zero hardcoded colors.
   ═══════════════════════════════════════════════════════════════ */

/* ── Panel override (extends .fbw-drawer) ── */

.ctx-panel {
  width: 380px;
  max-width: 90vw;
  background: var(--cloto-void);
  right: -400px;
}
.ctx-panel.is-open {
  right: 0;
}

/* ── Header ── */

.ctx-header {
  flex-shrink: 0;
  border-bottom: 1px solid var(--cloto-glass-border);
}

.ctx-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-6) var(--space-8);
}

.ctx-title {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--cloto-text-40);
}

.ctx-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--cloto-text-40);
  font-size: var(--cloto-fs-lg);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-spring);
}
.ctx-close:hover {
  color: var(--cloto-text-70);
  background: var(--cloto-teal-a6);
}

/* ── Card banner ── */

.ctx-card-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-8);
  background: var(--cloto-gold-a6);
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-xs);
  color: var(--cloto-text-70);
}

.ctx-banner-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cloto-gold);
  flex-shrink: 0;
}

.ctx-banner-label {
  color: var(--cloto-text-40);
}

.ctx-banner-title {
  color: var(--cloto-gold-light);
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ctx-banner-dismiss {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--cloto-text-40);
  font-size: var(--cloto-fs-sm);
  cursor: pointer;
  flex-shrink: 0;
}
.ctx-banner-dismiss:hover {
  color: var(--cloto-text-70);
  background: var(--cloto-gold-a10);
}

/* ── Search ── */

.ctx-search {
  padding: var(--space-3) var(--space-8);
}

.ctx-search-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--cloto-glass-border);
  border-radius: var(--radius-sm);
  background: var(--cloto-surface);
  color: var(--cloto-text-100);
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  outline: none;
  transition: border-color var(--duration-normal) ease;
}
.ctx-search-input::placeholder {
  color: var(--cloto-text-25);
}
.ctx-search-input:focus {
  border-color: var(--cloto-teal-a25);
}

/* ── Tabs ── */

.ctx-tabs {
  display: flex;
  gap: 0;
  padding: 0 var(--space-8);
  border-bottom: 1px solid var(--cloto-glass-border);
}

.ctx-tab {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--cloto-text-40);
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-xs);
  cursor: pointer;
  transition: all var(--duration-normal) ease;
  text-align: center;
  white-space: nowrap;
}
.ctx-tab:hover {
  color: var(--cloto-text-70);
}
.ctx-tab.is-active {
  color: var(--cloto-teal);
  border-bottom-color: var(--cloto-teal);
}

/* ── Content (scrollable) ── */

.ctx-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-6) var(--space-8);
}

/* Glass scrollbar */
.ctx-content::-webkit-scrollbar {
  width: 4px;
}
.ctx-content::-webkit-scrollbar-track {
  background: transparent;
}
.ctx-content::-webkit-scrollbar-thumb {
  background: var(--cloto-text-15);
  border-radius: 2px;
}

/* ── Empty state ── */

.ctx-empty {
  padding: var(--space-12) var(--space-8);
  text-align: center;
  color: var(--cloto-text-40);
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  line-height: 1.6;
}

/* ── Collapsible sections ── */

.ctx-section {
  margin-bottom: var(--space-6);
}

.ctx-section-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  cursor: pointer;
  user-select: none;
}

.ctx-section-chevron {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  position: relative;
}
.ctx-section-chevron::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 2px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--cloto-text-40);
  border-bottom: 1.5px solid var(--cloto-text-40);
  transform: rotate(45deg);
  transition: transform var(--duration-normal) ease;
}

.ctx-section.is-collapsed .ctx-section-chevron::before {
  transform: rotate(-45deg);
  top: 4px;
  left: 1px;
}

.ctx-section-title {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  font-weight: 600;
  color: var(--cloto-text-70);
}

.ctx-section-count {
  font-weight: 400;
  color: var(--cloto-text-40);
  font-size: var(--cloto-fs-xs);
  margin-left: var(--space-2);
}

.ctx-section.is-collapsed .ctx-section-body {
  display: none;
}

.ctx-section-body {
  padding-top: var(--space-3);
}

/* ── Senso Profondo ── */

.ctx-sense-item {
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--cloto-surface);
}
.ctx-sense-gold {
  border-left: 3px solid var(--cloto-gold);
}
.ctx-sense-teal {
  border-left: 3px solid var(--cloto-teal);
}

.ctx-sense-label {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-2xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--cloto-text-40);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
}

.ctx-sense-text {
  font-family: var(--cloto-font-brand);
  font-style: italic;
  font-size: var(--cloto-fs-md);
  color: var(--cloto-text-100);
  line-height: 1.5;
}

/* ── Character arcs ── */

.ctx-arc-item {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--cloto-glass-border);
}
.ctx-arc-item:last-child {
  border-bottom: none;
}

.ctx-arc-name {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  font-weight: 600;
  color: var(--cloto-text-100);
}

/* ── Badges ── */

.ctx-badge {
  display: inline-block;
  padding: 1px var(--space-3);
  border-radius: var(--radius-full);
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-2xs);
  font-weight: 500;
  vertical-align: middle;
}

.ctx-badge-purple {
  color: var(--cloto-purple);
  background: var(--cloto-purple-a12);
}

.ctx-badge-teal {
  color: var(--cloto-teal);
  background: var(--cloto-teal-a12);
}

/* ── Segments (da → a) ── */

.ctx-segment,
.ctx-char-segments .ctx-segment {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-xs);
  color: var(--cloto-text-70);
}

.ctx-segment-arrow {
  color: var(--cloto-text-25);
  flex-shrink: 0;
}

.ctx-segment-da,
.ctx-segment-a {
  min-width: 0;
}

/* ── Narrative promises ── */

.ctx-promise-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  color: var(--cloto-text-100);
}

.ctx-promise-icon {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  font-size: var(--cloto-fs-sm);
}

/* Open promise: gold icon */
.ctx-promise-item:not(.is-resolved) .ctx-promise-icon {
  color: var(--cloto-gold);
}

/* Resolved promise: green, line-through, dimmed */
.ctx-promise-item.is-resolved {
  opacity: 0.5;
}
.ctx-promise-item.is-resolved .ctx-promise-icon {
  color: var(--cloto-success);
}
.ctx-promise-item.is-resolved .ctx-promise-text {
  text-decoration: line-through;
}

/* ── from-card highlight ── */

.from-card {
  border-left: 3px solid var(--cloto-gold);
  padding-left: var(--space-3);
  margin-left: calc(-1 * var(--space-3));
}

.ctx-from-badge {
  display: inline-block;
  padding: 0 var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--cloto-gold-a12);
  color: var(--cloto-gold-light);
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-2xs);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Obligations ── */

.ctx-obligation-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  color: var(--cloto-text-100);
}

.ctx-obligation-check {
  flex-shrink: 0;
  color: var(--cloto-text-40);
  font-size: var(--cloto-fs-md);
}

/* ── Dramatic irony ── */

.ctx-irony-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  color: var(--cloto-text-100);
}

.ctx-irony-icon {
  flex-shrink: 0;
  color: var(--cloto-info);
  font-size: var(--cloto-fs-sm);
}

/* ── Timeline ── */

.ctx-timeline-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  color: var(--cloto-text-100);
}

.ctx-timeline-idx {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--cloto-teal-a10);
  color: var(--cloto-teal);
  font-size: var(--cloto-fs-2xs);
  font-weight: 600;
}

.ctx-timeline-when {
  display: block;
  font-size: var(--cloto-fs-2xs);
  color: var(--cloto-text-40);
  margin-top: var(--space-1);
}

/* ── Search highlight ── */

.ctx-highlight {
  background: var(--cloto-gold-a20);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Characters tab ── */

.ctx-character-card {
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--cloto-surface);
  border: 1px solid var(--cloto-glass-border);
}

.ctx-char-name {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-md);
  font-weight: 600;
  color: var(--cloto-text-100);
  margin-bottom: var(--space-2);
}

.ctx-char-field {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-xs);
  color: var(--cloto-text-70);
  margin-top: var(--space-2);
  line-height: 1.5;
}

.ctx-char-backstory {
  font-style: italic;
  color: var(--cloto-text-40);
}

.ctx-char-arc-label {
  font-weight: 600;
  color: var(--cloto-text-40);
}

.ctx-char-segments {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--cloto-glass-border);
}

/* ── Light theme overrides ── */

body.fd-light .ctx-panel {
  background: var(--cloto-void);
  box-shadow: -8px 0 32px var(--cloto-black-a8);
}

body.fd-light .ctx-search-input {
  background: var(--cloto-surface);
}

body.fd-light .ctx-sense-item,
body.fd-light .ctx-character-card {
  background: var(--cloto-surface);
}
