:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --panel: #f0eee8;
  --line: #dedbd4;
  --line-strong: #c9c4ba;
  --muted: #6f746f;
  --text: #1f2522;
  --strong: #101512;
  --brand-warm-charcoal: #1f2522;
  --brand-deep-navy: #101d36;
  --read-message-text: rgba(31, 37, 34, 0.64);
  --read-message-strong: rgba(31, 37, 34, 0.72);
  --read-message-accent: rgba(31, 37, 34, 0.46);
  --message-font: "Circular", "Circular Std", "Avenir Next", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 15%) minmax(0, 20%) minmax(0, 65%);
  height: 100vh;
  overflow: hidden;
}

.timescale-column,
.stream-column,
.thread-column {
  min-width: 0;
  border-right: 1px solid var(--line);
}

.timescale-column {
  padding: 24px 10px;
  background: var(--panel);
}

.time-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.time-scale {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  padding: 0 0 0 4px;
}

.time-marker {
  flex: 0 0 auto;
  display: block;
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 2px 0 4px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
}

.time-marker span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.time-gap {
  flex: 1 1 24px;
  min-height: 20px;
  margin-left: 6px;
  border-left: 1px dotted var(--line-strong);
}

.time-marker:hover {
  background: rgba(255, 255, 255, 0.72);
}

.time-marker.is-active {
  background: var(--surface);
  color: var(--strong);
}

.stream-column {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  background: var(--surface-soft);
}

.channel-filter-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-height: 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.channel-filter {
  display: grid;
  min-width: 0;
  min-height: 28px;
  place-items: center;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.24);
  background-color: rgba(128, 128, 128, 0.5);
  color: #ffffff;
  transition: background-color 180ms ease, box-shadow 180ms ease;
}

.channel-filter:last-child {
  border-right: 0;
}

.channel-filter:hover,
.channel-filter.is-active {
  background-color: var(--channel-color);
  box-shadow: inset 0 -4px 0 rgba(255, 255, 255, 0.72);
}

.channel-filter svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.channel-filter span {
  color: #ffffff;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.channel-filter-facebook span {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 20px;
  font-weight: 800;
}

.channel-filter-email {
  --channel-color: #23615b;
}

.channel-filter-facebook {
  --channel-color: #1877f2;
}

.channel-filter-instagram {
  --channel-color: #e4405f;
}

.message-list {
  position: relative;
  display: grid;
  align-content: start;
  gap: 0;
  overflow-y: auto;
  min-height: 0;
  overscroll-behavior: contain;
  padding: 8px 0 18px;
}

.stream-item {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 104px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px 16px 24px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.stream-item:hover {
  background: var(--surface);
}

.stream-item.is-active {
  background: #f0eee8;
}

.stream-item.is-unread {
  background: transparent;
  color: var(--strong);
}

.stream-item.is-unread:hover {
  background: var(--surface);
}

.stream-item.is-unread.is-active {
  background: #f0eee8;
}

.stream-item.is-unread .stream-name {
  color: var(--strong);
  font-weight: 760;
}

.stream-item.is-unread .stream-preview {
  color: var(--read-message-text);
  font-weight: 400;
}

.stream-item.is-unread .stream-topline time {
  color: var(--brand-deep-navy);
  font-weight: 760;
}

.stream-content {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.stream-topline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stream-topline {
  justify-content: space-between;
}

.stream-topline time {
  flex: 0 0 auto;
  color: var(--read-message-accent);
  font-size: 12px;
}

.stream-name {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  color: var(--read-message-strong);
  font-weight: 700;
}

.stream-name-first,
.stream-name-rest {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-name-first {
  flex: 0 1 auto;
  font-size: 33px;
  line-height: 1;
}

.stream-name-rest {
  flex: 1 1 auto;
  font-size: 16.5px;
  line-height: 1;
}

.stream-preview {
  overflow: hidden;
  font-family: var(--message-font);
  font-size: 17px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-preview {
  color: var(--read-message-text);
}

.thread-column {
  position: relative;
  background: var(--surface);
  border-right: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.thread-column::after {
  content: "";
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: block;
  height: 96px;
  margin-top: -96px;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0),
    rgba(255, 255, 255, 0.82) 62%,
    var(--surface)
  );
}

.conversation-thread {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.thread-contact-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  gap: 16px;
  padding: 24px 56px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.thread-contact-header h2 {
  margin: 0;
  color: var(--strong);
  font-size: 26px;
  line-height: 1.15;
}

.thread-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.thread-composer textarea {
  min-height: 52px;
  max-height: 116px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface-soft);
  color: var(--text);
  font-family: var(--message-font);
  font-size: 16px;
  line-height: 1.35;
}

.thread-composer textarea:focus {
  outline: 2px solid rgba(16, 29, 54, 0.16);
  border-color: rgba(16, 29, 54, 0.36);
}

.thread-composer button {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--brand-warm-charcoal);
  color: #f7f5ef;
  font-weight: 760;
}

.thread-composer button:disabled,
.thread-composer textarea:disabled {
  opacity: 0.56;
  cursor: default;
}

.thread-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px 0 44px;
}

.thread-bubble {
  position: relative;
  width: fit-content;
  max-width: min(calc(100% - 96px), 520px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  background: var(--surface-soft);
  color: var(--text);
}

.thread-delay {
  align-self: center;
  display: block;
  color: #8a8f8a;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.thread-delay span {
  white-space: nowrap;
}

.thread-bubble.is-inbound {
  align-self: flex-start;
  border-left: 0;
  border-radius: 0 8px 8px 0;
  padding-left: 56px;
}

.thread-bubble.is-outbound {
  align-self: flex-end;
  border-right: 0;
  border-radius: 8px 0 0 8px;
  padding-right: 56px;
  background: var(--brand-warm-charcoal);
  border-color: var(--brand-warm-charcoal);
  color: #f7f5ef;
}

.thread-bubble.is-note {
  align-self: center;
  max-width: 82%;
  border: 1px solid #ead8a9;
  border-radius: 8px;
  padding-right: 18px;
  padding-left: 18px;
  background: #fff7e5;
}

.thread-bubble p {
  margin: 0;
  color: inherit;
  font-family: var(--message-font);
  font-size: 17px;
  line-height: 1.48;
  white-space: pre-wrap;
}

.empty-state {
  padding: 30px;
  color: var(--muted);
}

.empty-state.compact {
  padding: 6px 8px;
  font-size: 13px;
}

@media (max-width: 820px) {
  .app-shell {
    display: flex;
    width: 100vw;
    height: 100dvh;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .timescale-column,
  .stream-column,
  .thread-column {
    flex: 0 0 100vw;
    height: 100dvh;
    scroll-snap-align: start;
  }

  .timescale-column {
    border-bottom: 0;
  }

  .thread-column {
    min-height: 100dvh;
  }

  .conversation-thread {
    min-height: 100dvh;
  }

  .thread-contact-header {
    padding: 20px 24px 16px;
  }

  .thread-bubble {
    max-width: calc(100% - 52px);
  }

  .thread-bubble.is-inbound {
    padding-left: 24px;
  }

  .thread-bubble.is-outbound {
    padding-right: 24px;
  }
}
