:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #171a1e;
  --panel-2: #1d2126;
  --panel-3: #22272d;
  --line: #2d333b;
  --line-soft: #242a31;
  --text: #d8dde3;
  --text-soft: #9aa4af;
  --text-muted: #6f7a85;
  --accent: #8fa3b8;
  --blue: #6f91ad;
  --amber: #b39a65;
  --red: #b26d68;
  --green: #7f9d83;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 28%),
    var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: #14171a;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid #3a424b;
  border-radius: 6px;
  background: #1b1f24;
  color: #c4ccd4;
  font-weight: 700;
}

.brand h1,
.case-heading h2,
.review-header h2 {
  margin: 0;
}

.brand h1 {
  font-size: 13px;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.brand p,
.muted-label {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-tools {
  padding: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.search-label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.case-search {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid #323940;
  border-radius: 6px;
  outline: none;
  background: #101316;
  color: var(--text);
}

.case-search:focus {
  border-color: #526170;
  box-shadow: 0 0 0 3px rgba(143, 163, 184, 0.12);
}

.case-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 7px;
  overflow: auto;
  padding: 12px;
}

.case-card {
  width: 100%;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.case-card:hover,
.case-card.active {
  border-color: #343c45;
  background: #1a1e23;
}

.case-card.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.case-card:active {
  transform: translateY(1px);
}

.case-card-top,
.risk-line,
.message-meta,
.topbar-meta,
.stat-row,
.flag-row,
.account-row,
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.case-id {
  color: #c7ced6;
  font-size: 12px;
  font-weight: 700;
}

.case-title-small {
  margin: 6px 0 10px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.35;
}

.risk-line {
  justify-content: flex-start;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.risk-dot,
.system-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--green);
}

.risk-high {
  background: var(--red);
}

.risk-medium {
  background: var(--amber);
}

.risk-low {
  background: var(--green);
}

.sidebar-footer {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 14px 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--text-muted);
  font-size: 12px;
}

.formatter-link {
  margin-left: auto;
  color: #aeb8c2;
  text-decoration: none;
}

.formatter-link:hover {
  color: #d8dde3;
}

.system-dot {
  background: var(--amber);
}

.review-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
}

.chat-panel,
.review-panel {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.chat-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.case-topbar,
.review-header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 76px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(23, 26, 30, 0.96);
}

.case-heading {
  min-width: 0;
  flex: 1;
}

.case-heading h2 {
  overflow: hidden;
  color: #e1e5e9;
  font-size: 18px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-meta {
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--text-muted);
  font-size: 12px;
}

.meta-chip,
.archive-pill {
  border: 1px solid #37404a;
  border-radius: 999px;
  padding: 5px 8px;
  background: #1b2025;
  color: var(--text-soft);
  white-space: nowrap;
}

.panel-toggle,
.review-toggle,
.review-close {
  border: 1px solid #38414a;
  border-radius: 6px;
  background: #20262c;
  color: #cbd2d9;
  cursor: pointer;
  min-height: 36px;
}

.panel-toggle {
  display: none;
  padding: 0 10px;
}

.review-toggle,
.review-close {
  padding: 0 12px;
}

.panel-toggle:hover,
.review-toggle:hover,
.review-close:hover {
  background: #252c33;
}

.review-toggle,
.review-close {
  display: none;
}

.mobile-archive-panel {
  display: none;
}

.chat-scroll {
  min-height: 0;
  overflow-y: auto;
  padding: 24px clamp(18px, 4vw, 56px) 34px;
  scroll-behavior: smooth;
}

.date-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 22px;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.date-divider::before,
.date-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line-soft);
}

.message-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 680px);
  gap: 11px;
  margin: 14px 0;
}

.message-row.from-peer {
  grid-template-columns: minmax(0, 680px) 34px;
  justify-content: end;
}

.message-row.from-peer .avatar {
  grid-column: 2;
}

.message-row.from-peer .message-stack {
  grid-column: 1;
  grid-row: 1;
  align-items: flex-end;
}

.avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #38404a;
  border-radius: 50%;
  background: #20252b;
  color: #aeb7c1;
  font-size: 12px;
  font-weight: 700;
}

.message-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.message-meta {
  justify-content: flex-start;
  margin-bottom: 5px;
  color: var(--text-muted);
  font-size: 12px;
}

.sender-name {
  color: #b8c0c8;
  font-weight: 650;
}

.hover-time {
  opacity: 0;
  transition: opacity 160ms ease;
}

.message-row:hover .hover-time {
  opacity: 1;
}

.bubble {
  max-width: 100%;
  padding: 11px 13px;
  border: 1px solid #303842;
  border-radius: 8px;
  background: var(--panel-2);
  color: #d7dce1;
  line-height: 1.48;
  white-space: pre-wrap;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
}

.from-peer .bubble {
  border-color: #35404b;
  background: #20262c;
}

.message-system,
.message-moderator,
.message-flagged,
.message-deleted,
.message-unavailable {
  display: flex;
  justify-content: center;
  margin: 18px 0;
}

.notice {
  max-width: 720px;
  border: 1px solid #333b44;
  border-radius: var(--radius);
  padding: 10px 12px;
  background: #181d22;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

.message-moderator .notice {
  border-color: rgba(111, 145, 173, 0.46);
  background: rgba(111, 145, 173, 0.08);
}

.message-flagged .notice {
  border-color: rgba(179, 154, 101, 0.46);
  background: rgba(179, 154, 101, 0.08);
  color: #c4b58e;
}

.message-deleted .notice,
.message-unavailable .notice {
  border-style: dashed;
  color: #87919c;
}

.inactive-banner {
  margin: 18px auto;
  max-width: 620px;
  border: 1px solid #343b43;
  border-radius: var(--radius);
  padding: 12px;
  background: #15191d;
  color: #87919b;
  font-size: 12px;
  text-align: center;
}

.case-skeleton {
  position: absolute;
  inset: 76px 0 0;
  z-index: 3;
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 28px clamp(18px, 4vw, 56px);
  background: var(--panel);
}

@media (max-width: 900px) {
  .case-skeleton {
    inset: 72px 0 0;
  }
}

@media (max-width: 620px) {
  .case-skeleton {
    inset: 58px 0 0;
  }
}

.case-skeleton.hidden {
  display: none;
}

.case-skeleton div {
  height: 58px;
  max-width: 680px;
  border-radius: 8px;
  background: linear-gradient(90deg, #1c2025 0%, #252b31 45%, #1c2025 90%);
  background-size: 220% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
}

.case-skeleton div:nth-child(even) {
  justify-self: end;
  width: 58%;
}

.case-skeleton div:nth-child(odd) {
  width: 68%;
}

.review-panel {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: #15181c;
}

.review-header {
  justify-content: space-between;
}

.review-header h2 {
  font-size: 16px;
}

.review-sections {
  overflow: auto;
  padding: 14px;
}

.review-section {
  border-bottom: 1px solid var(--line-soft);
  padding: 15px 0;
}

.review-section:first-child {
  padding-top: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  color: #c7ced6;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.flag-row,
.account-row,
.history-row,
.stat-row {
  padding: 8px 0;
  color: var(--text-soft);
  font-size: 13px;
}

.flag-row span:last-child,
.account-row span:last-child,
.history-row span:last-child,
.stat-row span:last-child {
  color: #c7ced6;
  text-align: right;
}

.analysis-item {
  margin: 8px 0;
  border: 1px solid #303842;
  border-radius: 7px;
  padding: 10px;
  background: #1a1e23;
}

.analysis-item strong {
  display: block;
  margin-bottom: 4px;
  color: #d0d6dc;
  font-size: 13px;
}

.analysis-item p,
.note-body {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.45;
}

.note {
  margin: 8px 0;
  border: 1px solid #303842;
  border-radius: 7px;
  background: #191d22;
}

.note summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  color: #c9d0d7;
  cursor: pointer;
}

.note summary::-webkit-details-marker {
  display: none;
}

.note summary span {
  color: var(--text-muted);
  font-size: 12px;
}

.note-body {
  padding: 0 10px 10px;
}

.empty-state,
.error-state {
  margin: 28px auto;
  max-width: 520px;
  color: var(--text-muted);
  text-align: center;
}

@keyframes skeleton {
  to {
    background-position: -220% 0;
  }
}

@media (max-width: 1120px) {
  .review-workspace {
    grid-template-columns: minmax(0, 1fr) 318px;
  }

  .topbar-meta {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    display: none;
  }

  .mobile-archive-panel {
    display: grid;
    gap: 8px;
    padding: 8px 10px 10px;
    border-bottom: 1px solid var(--line);
    background: #15191d;
  }

  .mobile-archive-panel[hidden] {
    display: none;
  }

  .mobile-archive-panel label {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  .mobile-archive-panel select {
    width: 100%;
    height: 36px;
    border: 1px solid #323940;
    border-radius: 6px;
    background: #101316;
    color: var(--text);
    padding: 0 10px;
  }

  .panel-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    border-color: #4a5662;
    background: #28313a;
    font-weight: 700;
  }

  .panel-toggle::after {
    content: "v";
    margin-left: 6px;
    color: var(--text-muted);
    font-size: 10px;
  }

  .review-toggle {
    display: inline-flex;
    align-items: center;
    border-color: #4a5662;
    background: #28313a;
    font-weight: 700;
    min-height: 34px;
  }

  .review-workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .chat-panel {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .review-panel {
    position: fixed;
    inset: 76px 0 0;
    z-index: 12;
    display: none;
    border-left: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.32);
  }

  body.review-open {
    overflow: hidden;
  }

  body.review-open .review-panel {
    display: flex;
  }

  .review-close {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    margin-left: auto;
  }

  .chat-scroll {
    min-height: calc(100vh - 72px);
    min-height: calc(100dvh - 72px);
    max-height: none;
  }
}

@media (max-width: 620px) {
  body {
    font-size: 13px;
  }

  .case-topbar {
    align-items: center;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 58px;
    padding: 8px 10px;
    position: sticky;
    top: 0;
    z-index: 5;
  }

  .case-heading h2 {
    font-size: 14px;
  }

  .muted-label {
    font-size: 10px;
  }

  .message-row,
  .message-row.from-peer {
    grid-template-columns: 28px minmax(0, 1fr);
    justify-content: start;
    gap: 8px;
    margin: 12px 0;
  }

  .message-row.from-peer .avatar {
    grid-column: 1;
  }

  .message-row.from-peer .message-stack {
    grid-column: 2;
    align-items: flex-start;
  }

  .avatar {
    width: 28px;
    height: 28px;
    font-size: 10px;
  }

  .chat-scroll {
    min-height: calc(100vh - 58px);
    min-height: calc(100dvh - 58px);
    padding: 12px 10px 20px;
  }

  .bubble {
    padding: 10px 11px;
    font-size: 13px;
    line-height: 1.45;
  }

  .notice,
  .inactive-banner {
    width: 100%;
    text-align: left;
  }

  .review-header {
    min-height: 64px;
    padding: 12px;
    gap: 8px;
  }

  .review-panel {
    inset: 58px 0 0;
  }

  .review-sections {
    padding: 12px;
  }

  .case-list {
    padding-bottom: 22px;
  }
}

@media (max-width: 420px) {
  .panel-toggle {
    min-width: 34px;
    padding: 0 9px;
    font-size: 12px;
  }

  .review-toggle {
    min-width: 34px;
    padding: 0 9px;
    font-size: 12px;
  }

  .case-heading h2 {
    font-size: 14px;
  }

  .message-meta {
    flex-wrap: wrap;
    gap: 5px;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  .sidebar {
    display: none;
  }

  .panel-toggle {
    display: inline-flex;
    align-items: center;
  }
}

@media print {
  body {
    overflow: visible;
    background: #fff;
    color: #111;
  }

  .sidebar,
  .review-panel,
  .review-toggle,
  .review-close,
  .panel-toggle {
    display: none;
  }

  .app-shell,
  .review-workspace,
  .chat-panel {
    display: block;
    height: auto;
    min-height: 0;
    background: #fff;
  }

  .case-topbar,
  .chat-scroll {
    background: #fff;
    color: #111;
  }

  .chat-scroll {
    overflow: visible;
  }
}
