:root {
  color-scheme: light;
  --font-body: 'Montserrat', 'Segoe UI', -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  --font-heading: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --bg: #ffffff;
  --text: #2a2a2a;
  --muted: #5f6b7a;
  --border: #e8e5dd;
  --panel: #ffffff;
  /* Accent pulled from site palette (lavender leaning red) */
  --accent: #A3809C;
  --accent-contrast: #ffffff;
}

@font-face {
  font-family: 'FKGroteskNeue';
  src: url('/fonts/FKGroteskNeue.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'FK Grotesk Neue';
  src: url('/fonts/FKGroteskNeue.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Subtle floral background pulled from sarahmeden.com and self-hosted */
  background-color: var(--bg);
  background-image:
    radial-gradient(1000px 500px at 10% -10%, rgba(163, 128, 156, 0.06), rgba(255, 255, 255, 0) 60%),
    url('/images/floral-clean.png');
  background-repeat: no-repeat, no-repeat;
  background-position: left -150px top -180px, top center;
  background-size: 1200px 600px, clamp(800px, 88vw, 1640px) auto;
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header,
main {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

header {
  padding: 2rem 1.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

header h1 {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 1.8rem;
  margin: 0 0 0.35rem 0;
}

header p {
  margin: 0;
  color: var(--muted);
}

main {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 2rem;
  padding: 2rem 1.5rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 10px 24px rgba(17, 24, 39, 0.08);
}

.panel:not(.reader-panel) {
  overflow: auto;
}

.panel h2 {
  margin: 0 0 0.75rem 0;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1.15rem;
  color: #1f2937;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-header h2 {
  margin: 0;
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.filter-grid label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: #475569;
}

.filter-grid input,
.filter-grid select {
  margin-top: 0.35rem;
}

.filter-status {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: #5f6b7a;
}

.summary-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.summary-table thead th {
  text-align: left;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--border);
  color: #475569;
}

.summary-table tbody td {
  padding: 0.55rem 0.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  color: #1f2937;
}

.summary-table tbody tr:last-child td {
  border-bottom: none;
}

.status-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge.active {
  background: rgba(0, 150, 136, 0.12);
  color: #00695c;
}

.status-badge.idle {
  background: rgba(255, 193, 7, 0.18);
  color: #8a6d00;
}

.status-badge.ended {
  background: rgba(239, 68, 68, 0.16);
  color: #b91c1c;
}

.section-metrics {
  margin-bottom: 0.85rem;
  font-size: 0.9rem;
  color: #475569;
}

.token-meta {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 0.2rem;
}

label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  color: var(--muted);
}

input,
select {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  margin-bottom: 1rem;
}

input:focus,
select:focus {
  outline: 2px solid rgba(181, 154, 106, 0.25);
  border-color: var(--accent);
}

input[readonly] {
  background: #f7f5f1;
  color: #5f6b7a;
  cursor: not-allowed;
}

select:disabled {
  background: #f7f5f1;
  color: #5f6b7a;
  cursor: not-allowed;
}

button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.75rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-contrast);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

button:disabled { opacity: 0.55; cursor: not-allowed; }

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(163, 128, 156, 0.25);
}

.reader-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#viewer {
  position: relative;
  flex: 1;
  min-height: 600px;
  height: 100%;
  background: linear-gradient(180deg, #ffffff 0%, #f8f3fb 100%);
  border-radius: 18px;
  border: 1px solid rgba(84, 63, 92, 0.16);
  box-shadow: inset 0 0 0 1px rgba(84, 63, 92, 0.06);
  overflow: hidden;
  --page-width: 640px;
  --page-gap: 48px;
  --page-padding-x: 48px;
  --page-padding-y: 56px;
  --watermark-offset: 12px;
  --footer-offset: 12px;
  --overlay-guard-top: 24px;
  --overlay-guard-bottom: 28px;
  --reader-font-scale: 1;
}

#viewer * {
  box-sizing: border-box;
}

#viewer .reader-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#viewer .reader-viewport {
  flex: 1;
  width: 100%;
  height: 100%;
  padding: var(--page-padding-y) var(--page-padding-x);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#viewer .reader-page {
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: #2f2833;
  font-size: calc(1.05rem * var(--reader-font-scale, 1));
  line-height: 1.65;
  word-break: break-word;
  padding-top: var(--overlay-guard-top, 0px);
  padding-bottom: var(--overlay-guard-bottom, 0px);
}

#viewer .reader-page > * {
  margin: 0 0 1.1rem;
}

#viewer .reader-page > *:last-child {
  margin-bottom: 0;
}

#viewer .reader-page h1,
#viewer .reader-page h2,
#viewer .reader-page h3,
#viewer .reader-page h4,
#viewer .reader-page h5,
#viewer .reader-page h6 {
  margin: 1.5rem 0 1rem;
  font-family: 'Libre Baskerville', Georgia, serif;
  color: #3c3143;
}

#viewer .reader-page ul,
#viewer .reader-page ol {
  margin: 0 0 1.1rem 1.4rem;
  padding: 0;
}

#viewer .reader-page figure {
  margin: 1.4rem 0;
  break-inside: avoid;
  text-align: center;
}

#viewer .reader-page img,
#viewer .reader-page svg,
#viewer .reader-page video,
#viewer .reader-page canvas {
  max-width: 100%;
  height: auto;
}

#viewer .reader-measure {
  position: absolute;
  top: -9999px;
  left: -9999px;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
}

#viewer .section-marker {
  break-after: avoid-column;
  height: 0;
}

#watermark-overlay {
  position: absolute;
  top: var(--watermark-offset, 12px);
  right: 12px;
  background: rgba(163, 128, 156, 0.06);
  border: 1px solid rgba(163, 128, 156, 0.2);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: #75546E;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  pointer-events: none;
  z-index: 10;
}

#forensic-footer {
  position: absolute;
  bottom: var(--footer-offset, 12px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.78rem;
  color: var(--muted);
  pointer-events: auto;
  z-index: 10;
}

#forensic-footer .footer-link {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  font: inherit;
}

#feedback-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

#feedback-modal {
  background: #fff;
  border-radius: 12px;
  width: min(560px, 92vw);
  max-height: 80vh;
  overflow: auto;
  border: 1px solid var(--border);
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
  padding: 1rem;
}

#feedback-modal h3 {
  margin: 0 0 0.5rem 0;
  font-family: var(--font-heading);
}

#feedback-modal .field {
  margin: 0.5rem 0;
}

#feedback-modal textarea {
  width: 100%;
  min-height: 120px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  resize: vertical;
}

#feedback-modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

#feedback-modal .secondary {
  background: #f3f0f5;
  color: #4b3f48;
}

/* Feedback page tweaks */
#feedback-root .field label {
  font-size: 0.95rem;
}
#feedback-root textarea {
  width: 100%;
  min-height: 240px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  resize: vertical;
  font-size: 0.95rem;
}
#feedback-root input[type="text"],
#feedback-root input[type="email"] {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}
#feedback-root .actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.attachment-actions {
  margin-top: 0.3rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.attachment-actions button {
  border: none;
  background: none;
  color: #2563eb;
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

.attachment-actions button:disabled {
  color: #94a3b8;
  cursor: wait;
  text-decoration: none;
}

.controls {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.9rem;
  padding: 0.65rem 1rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(163, 128, 156, 0.3);
  border-radius: 999px;
  box-shadow: 0 16px 32px rgba(123, 92, 116, 0.18);
}

.controls .font-size-control {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: #53354f;
  white-space: nowrap;
}

.controls .font-size-control span {
  font-weight: 500;
}

.controls .font-size-control select {
  appearance: none;
  -webkit-appearance: none;
  padding: 0.35rem 1.8rem 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(163, 128, 156, 0.55);
  background:
    linear-gradient(155deg, rgba(163, 128, 156, 0.16), rgba(255, 255, 255, 0.85) 58%, rgba(163, 128, 156, 0.08)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2353354f' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E") no-repeat right 0.8rem center / 10px 6px;
  color: #53354f;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

.controls .font-size-control select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(163, 128, 156, 0.35);
}

.controls #page-indicator {
  font-size: 0.85rem;
  color: #53354f;
  padding: 0 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls button.secondary {
  min-width: 132px;
  background: rgba(163, 128, 156, 0.16);
  color: #53354f;
  border: 1px solid rgba(163, 128, 156, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.controls button.secondary:not(:disabled):hover {
  background: rgba(163, 128, 156, 0.28);
}

.controls button.secondary:disabled {
  opacity: 1;
  background: rgba(163, 128, 156, 0.12);
  color: rgba(83, 53, 79, 0.7);
  border-color: rgba(163, 128, 156, 0.35);
  cursor: not-allowed;
}

.status-line {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.85rem;
}

.reader-panel ::selection {
  background: rgba(163, 128, 156, 0.18);
  color: #1a1a1a;
}

.reading-pane { user-select: none; }

@media (max-width: 960px) {
  main {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    padding: 1.5rem 1.25rem 2.25rem;
  }
  body {
    background-position: left -220px top -220px, top center;
    background-size: 1000px 500px, 100vw auto;
  }
  .panel {
    padding: 1rem;
  }
  .reader-panel {
    min-height: auto;
  }
  #viewer {
    flex: none;
    /* Allow the reader to scale to phone heights without dropping below a readable minimum. */
    min-height: clamp(420px, calc(100vh - 180px), 600px);
    height: auto;
    --page-padding-x: clamp(20px, 7vw, 32px);
    --page-padding-y: clamp(56px, 14vw, 80px);
    --watermark-offset: clamp(4px, 2vw, 10px);
    --footer-offset: clamp(32px, 11vw, 52px);
    --overlay-guard-top: clamp(44px, 12vw, 64px);
    --overlay-guard-bottom: clamp(36px, 11vw, 52px);
  }
  @supports (height: 100svh) {
    #viewer {
      min-height: clamp(420px, calc(100svh - 180px), 600px);
    }
  }
  .controls {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .controls .font-size-control {
    flex-basis: 100%;
    justify-content: center;
    order: 1;
  }
  .controls button.secondary {
    flex: 1 0 auto;
    order: 2;
  }
  .controls #page-indicator {
    flex-basis: 100%;
    order: 3;
    text-align: center;
    margin-top: 0.15rem;
  }
}

@media (max-width: 540px) {
  main {
    padding: 0.75rem clamp(0.85rem, 4vw, 1.2rem) 1.25rem;
  }
  .panel {
    padding: clamp(0.75rem, 4vw, 1rem);
  }
  #viewer {
    width: 100%;
    max-width: none;
    margin: 0 auto;
    min-height: clamp(360px, calc(100vh - 140px), 520px);
    --page-padding-x: clamp(8px, 4vw, 16px);
    --page-padding-y: clamp(8px, 3vh, 14px);
    --watermark-offset: clamp(12px, 4.5vw, 20px);
    --footer-offset: clamp(16px, 6vw, 30px);
    --overlay-guard-top: clamp(26px, 4.5vh, 36px);
    --overlay-guard-bottom: clamp(16px, 3vh, 24px);
  }
  @supports (height: 100svh) {
    #viewer {
      min-height: clamp(360px, calc(100svh - 140px), 520px);
    }
  }
  #viewer .reader-page > * {
    margin: 0 0 clamp(0.75rem, 2.5vh, 1rem);
  }
}

@media print { body { display: none; } }

.session-log {
  margin-top: 0.75rem;
  max-height: 260px;
  overflow-y: auto;
  font-size: 0.85rem;
  background: #faf9f7;
  border-radius: 10px;
  padding: 0.75rem;
  border: 1px solid var(--border);
}

.session-log ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.session-log li {
  margin: 0 0 0.65rem 0;
  color: #374151;
}

.session-log li:last-child {
  margin-bottom: 0;
}

.session-log .log-entry {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.4rem 0;
}

.session-log .log-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.83rem;
  color: #1f2937;
}

.session-log .log-heading strong {
  font-size: 0.9rem;
  font-weight: 600;
}

.session-log .log-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: #5f6b7a;
}

.session-log .log-meta span {
  background: rgba(163, 128, 156, 0.15);
  color: #654e6b;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}

.session-log .log-details {
  font-size: 0.78rem;
  color: #374151;
  line-height: 1.35;
}

.session-log time {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.1rem;
}

.session-timeline {
  display: grid;
  gap: 1rem;
}

.session-timeline .timeline-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  background: #fbf8f5;
}

.session-timeline .timeline-card h3 {
  margin: 0 0 0.35rem 0;
  font-family: var(--font-heading);
  font-size: 1rem;
  color: #2a2a2a;
}

.session-timeline .timeline-card p {
  margin: 0;
  color: #5f6b7a;
  font-size: 0.85rem;
}

.session-timeline .timeline-events {
  margin: 0.6rem 0 0 0;
  padding: 0;
  list-style: none;
}

.session-timeline .timeline-events li {
  padding: 0.45rem 0;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.1);
  font-size: 0.85rem;
  color: #374151;
}

.session-timeline .timeline-events li:last-child {
  border-bottom: none;
}

.session-timeline time {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
