:root {
  color-scheme: light;
  --bg: #ededed;
  --paper: rgba(255, 255, 255, 0.92);
  --paper-strong: #ffffff;
  --ink: #2d241f;
  --ink-soft: #6e6259;
  --line: rgba(88, 66, 50, 0.14);
  --accent: #c95f37;
  --accent-soft: rgba(201, 95, 55, 0.12);
  --me: #95ec69;
  --other: #ffffff;
  --system: #ece4db;
  --shadow: 0 8px 18px rgba(0, 0, 0, 0.06);
  --radius: 22px;
  --sidebar-width: 360px;
  font-family: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-height: 100vh;
  overflow: hidden;
}

.app-shell {
  display: block;
  height: 100dvh;
  min-height: 100dvh;
}

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

h1 {
  margin: 0 0 10px;
  font-size: 28px;
  line-height: 1.15;
}

.muted {
  color: var(--ink-soft);
}

.small {
  font-size: 13px;
}

.field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

input[type="search"],
input[type="date"],
select,
button {
  font: inherit;
}

input[type="search"],
input[type="date"],
select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
}

.button-row {
  display: flex;
  gap: 10px;
}

.button-row {
  margin-top: 10px;
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button.ghost {
  background: rgba(93, 71, 54, 0.12);
  color: var(--ink);
}

.main-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100dvh;
  min-height: 100dvh;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-spacer {
  grid-column: 1;
  justify-self: start;
  width: 44px;
  height: 44px;
}

.topbar-title {
  justify-self: center;
  grid-column: 2;
  font-size: 24px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
}

.timeline-wrapper {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 28px 24px 48px;
}

.timeline {
  display: grid;
  gap: 14px;
  align-content: start;
}

.empty-state {
  justify-self: center;
  padding: 18px 22px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink-soft);
  box-shadow: var(--shadow);
}

.inline-loader {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  margin: 10px 0 6px;
}

.inline-loader-line {
  height: 1px;
  background: rgba(66, 111, 184, 0.18);
}

.inline-loader-label {
  appearance: none;
  border: 0;
  background: transparent;
  color: #3f74c8;
  font-size: 13px;
  line-height: 1;
  padding: 10px 18px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.inline-loader.is-end .inline-loader-label {
  color: #6f8fc3;
  cursor: default;
}

.control-toggle {
  grid-column: 3;
  justify-self: end;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  font-size: 38px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  z-index: 25;
}

.control-toggle:hover {
  transform: none;
  opacity: 0.72;
}

.control-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - 88px);
  overflow-y: auto;
  z-index: 24;
  padding: 18px;
  border-radius: 26px;
  background: rgba(255, 250, 244, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.control-panel.hidden,
.panel-backdrop.hidden {
  display: none;
}

.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 18, 11, 0.18);
  z-index: 23;
}

.control-hero {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.control-section + .control-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.search-results {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  max-height: 34vh;
  overflow-y: auto;
}

.search-item {
  width: 100%;
  text-align: left;
  color: var(--ink);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  border-radius: 16px;
  padding: 12px;
  cursor: pointer;
}

.search-item:hover {
  border-color: rgba(201, 95, 55, 0.34);
  background: rgba(255, 249, 244, 0.92);
}

.search-item .meta {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.search-item .body {
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  color: var(--ink);
}

.search-empty {
  padding: 10px 2px;
  font-size: 13px;
  color: var(--ink-soft);
}

.day-separator {
  justify-self: center;
  background: rgba(0, 0, 0, 0.08);
  color: rgba(0, 0, 0, 0.58);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.message-row {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 780px);
  animation: rise-in 180ms ease;
}

.message-row.other {
  justify-self: start;
}

.message-row.me {
  justify-self: end;
  align-items: flex-end;
}

.message-row.system {
  justify-self: center;
  align-items: center;
  max-width: 80%;
}

.message-meta {
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--ink-soft);
}

.bubble {
  background: var(--other);
  border-radius: 24px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 0;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}

.message-row.me .bubble {
  background: var(--me);
}

.message-row.other .bubble::before {
  content: "";
  position: absolute;
  top: 14px;
  left: -6px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 8px solid var(--other);
}

.message-row.me .bubble::after {
  content: "";
  position: absolute;
  top: 14px;
  right: -6px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid var(--me);
}

.message-row.system .bubble {
  background: var(--system);
  color: var(--ink-soft);
}

.quote-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 16px;
  border: 1px solid rgba(201, 95, 55, 0.18);
  background: var(--accent-soft);
  color: var(--ink);
}

.quote-card .quote-sender {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 3px;
}

.quote-card .quote-preview {
  font-size: 13px;
  line-height: 1.4;
}

.message-text {
  white-space: pre-wrap;
}

.media-stack {
  display: grid;
  gap: 8px;
}

.media-image {
  max-width: min(360px, 100%);
  border-radius: 18px;
  cursor: zoom-in;
  display: block;
  box-shadow: 0 10px 20px rgba(61, 43, 29, 0.09);
}

.media-link {
  display: inline-flex;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}

.media-audio,
.media-video {
  width: min(360px, 100%);
}

.media-audio {
  display: none;
}

.voice-player {
  display: grid;
  gap: 6px;
  min-width: 170px;
  max-width: min(280px, 100%);
}

.voice-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  box-shadow: none;
}

.voice-button:hover {
  transform: none;
}

.voice-icon {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.72);
  flex: none;
  font-size: 16px;
  line-height: 1;
}

.message-row.me .voice-icon {
  background: rgba(255, 255, 255, 0.5);
}

.voice-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
  text-align: left;
}

.voice-label {
  font-size: 15px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.78);
}

.voice-duration {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.52);
}

.voice-player[data-state="playing"] .voice-icon {
  background: rgba(52, 123, 246, 0.16);
  color: #2f67d8;
}

.voice-player[data-state="playing"] .voice-label {
  color: #2f67d8;
}

.voice-player[data-state="error"] .voice-icon {
  background: rgba(201, 95, 55, 0.14);
  color: #b24d2d;
}

.voice-player[data-state="error"] .voice-label {
  color: #b24d2d;
}

.status-chip {
  display: inline-flex;
  align-self: flex-start;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(93, 71, 54, 0.09);
  color: var(--ink-soft);
  font-size: 12px;
}

.highlight .bubble {
  box-shadow: 0 0 0 3px rgba(201, 95, 55, 0.22), var(--shadow);
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(26, 18, 12, 0.74);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 30;
}

.lightbox.hidden {
  display: none;
}

.lightbox-body {
  max-width: min(1000px, 96vw);
  max-height: 88vh;
}

.lightbox-body img,
.lightbox-body video {
  max-width: 100%;
  max-height: 88vh;
  border-radius: 22px;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .message-row {
    max-width: 100%;
  }

  .topbar {
    min-height: 64px;
    padding: 8px 12px;
  }

  .topbar-title {
    font-size: 21px;
  }

  .timeline-wrapper {
    padding: 18px 12px 36px;
  }

  .inline-loader-label {
    padding: 12px 20px;
    min-height: 42px;
    font-size: 14px;
  }

  .control-toggle {
    font-size: 34px;
    min-width: 40px;
    min-height: 40px;
  }

  .control-panel {
    top: 60px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: calc(100vh - 76px);
  }
}
