:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #18202b;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #146c63;
  --accent-strong: #0f4f49;
  --warning: #a15c00;
  --danger: #b42318;
  --safe: #067647;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 24px;
  color: #f8fafc;
  background: #15232f;
  min-height: 0;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: white;
  background: var(--accent);
  font-weight: 800;
}

.brand h1,
.brand p,
.section-header h2,
.detail-toolbar h2,
.message-header h3,
.security-panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  color: #b9c2cf;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: #d7dee8;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  color: #ffffff;
  background: #223545;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.conversation-workspace {
  grid-template-columns: unset;
  grid-template-rows: 44px minmax(0, 1fr);
}

.app-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
}

.app-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg);
  color: var(--ink);
}

.icon-btn-danger:hover {
  background: #fee4e2;
  color: var(--danger);
}

.app-toolbar-search {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  max-width: 280px;
  padding: 0 8px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
}

.app-toolbar-search .search-icon {
  color: var(--muted);
  flex-shrink: 0;
}

.app-toolbar-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
}

.app-toolbar-search input::placeholder {
  color: var(--muted);
}

.workspace-body {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}

.section-header,
.detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

.section-header h2,
.detail-toolbar h2 {
  font-size: 22px;
}

.counter,
.detail-toolbar p,
.label {
  color: var(--muted);
  font-size: 13px;
}

.list {
  display: grid;
  align-content: start;
  gap: 1px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.conversation {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.conversation:hover {
  background: var(--panel);
}

.conversation.active {
  background: #2563eb;
}

.conversation.active .conv-sender,
.conversation.active .conv-subject,
.conversation.active .conv-preview,
.conversation.active .conv-time,
.conversation.active .conv-name-wrap span {
  color: #ffffff;
}

.conversation.active .conv-unread-dot {
  background: #ffffff;
}

.conv-row {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.conv-sender {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.conv-name-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  min-width: 0;
}

.conv-name-wrap span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2563eb;
  flex-shrink: 0;
}

.conv-time {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  flex-shrink: 0;
}

.conv-subject {
  font-size: 13px;
  color: var(--ink);
}

.conv-preview {
  font-size: 12px;
  color: var(--muted);
}

.pill,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.safe {
  color: var(--safe);
  background: #dcfae6;
}

.review {
  color: var(--warning);
  background: #fff1d6;
}

.blocked {
  color: var(--danger);
  background: #fee4e2;
}

.count {
  color: var(--accent-strong);
  background: #d9f0ed;
}

.conversation-detail,
.thread-panel {
  min-width: 0;
}

.thread-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #f8fafb;
}

.trust-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.trust-grid > div {
  display: grid;
  gap: 6px;
  min-height: 84px;
  padding: 18px 24px;
  background: var(--panel);
}

.message-panel,
.security-panel {
  margin: 24px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.message-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  padding: 24px;
  overflow: auto;
}

.bubble {
  max-width: min(720px, 86%);
  border-radius: 8px;
  line-height: 1.55;
}

.bubble.inbound {
  align-self: flex-start;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.bubble.outbound {
  align-self: flex-end;
  padding: 16px;
  border: 1px solid #b9d8d4;
  background: #e8f5f3;
}

.bubble.system {
  align-self: center;
  max-width: 92%;
  padding: 9px 12px;
  color: var(--muted);
  background: #eef2f6;
  font-size: 13px;
}

.bubble-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.bubble-header span {
  color: var(--muted);
  font-size: 12px;
}

.bubble-sender {
  display: grid;
  min-width: 0;
}

.bubble-sender span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.bubble-header > span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.bubble p {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bubble-actions {
  display: none;
  align-items: center;
  gap: 1px;
  width: fit-content;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  margin-top: 4px;
}

.bubble-wrap[data-direction="outbound"] .bubble-actions {
  align-self: flex-end;
}

.bubble-wrap[data-direction="inbound"] .bubble-actions {
  align-self: flex-start;
}

.bubble-wrap.selected .bubble-actions {
  display: flex;
}

.baction {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.baction:hover {
  background: var(--bg);
  color: var(--ink);
}

.trash-bubble {
  opacity: 0.7;
}

/* ── Quarantine ── */

.quar-dot-review  { background: var(--warning); }
.quar-dot-blocked { background: var(--danger); }

.quar-card {
  border-radius: 8px;
  border: 1px solid;
  padding: 14px 18px;
  margin-bottom: 4px;
}

.quar-card-review {
  border-color: #f79009;
  background: #fffaeb;
}

.quar-card-blocked {
  border-color: var(--danger);
  background: #fff1f0;
}

.quar-card-header {
  font-size: 13px;
  margin-bottom: 10px;
}

.quar-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 0;
  font-size: 12px;
}

.quar-dl dt {
  color: var(--muted);
  white-space: nowrap;
}

.quar-dl dd {
  margin: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.trash-section-header {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.baction-sep {
  width: 1px;
  height: 16px;
  background: var(--line);
  flex-shrink: 0;
}

.baction-danger:hover {
  background: #fee4e2;
  color: var(--danger);
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reply-composer {
  align-self: flex-start;
  width: min(640px, 92%);
  padding: 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
  display: grid;
  gap: 10px;
}

.reply-fields {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.reply-field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.reply-field-row:last-child {
  border-bottom: 0;
}

.reply-label {
  color: var(--muted);
  min-width: 70px;
  font-size: 12px;
}

.reply-field-value {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-from-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  min-width: 0;
}

.reply-from-name,
.reply-from-email {
  border: 0;
  outline: 0;
  font: inherit;
  font-size: 13px;
  background: transparent;
  min-width: 0;
}

.reply-from-name {
  flex: 1;
  border-right: 1px solid var(--line);
  padding-right: 10px;
  margin-right: 10px;
}

.reply-from-email {
  flex: 2;
  color: var(--muted);
}

.reply-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  resize: vertical;
  background: var(--bg);
  outline: none;
}

.reply-textarea:focus {
  border-color: var(--accent);
}

.reply-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.composer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.context-panel {
  min-width: 0;
  height: 100vh;
  border-left: 1px solid var(--line);
  background: #fbfcfd;
  overflow: auto;
}

.context-panel.collapsed {
  display: none;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.context-section {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.context-section h3 {
  margin: 0;
}

.context-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.context-grid > div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.message-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: white;
  background: var(--accent);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.toolbar-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
}

.toolbar-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.message-panel p {
  margin: 18px 0 0;
  color: #344054;
  line-height: 1.65;
}

.resource-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.resource-grid .security-panel {
  margin-top: 0;
}

.compact-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.compact-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.compact-item strong {
  overflow-wrap: anywhere;
}

.compact-item span {
  color: var(--muted);
  font-size: 13px;
}

.event-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.event {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.event:first-child {
  border-top: 0;
}

.event span {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 920px) {
  .app-shell,
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace-body {
    grid-template-columns: 1fr;
  }

  .thread-panel {
    min-height: 70vh;
  }

  .context-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .context-panel.collapsed {
    display: none;
  }

  .sidebar {
    padding: 16px;
  }

  .nav {
    grid-template-columns: repeat(4, 1fr);
  }

  .conversation-list {
    border-right: 0;
  }

  .trust-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .resource-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Login ── */

.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  display: grid;
  gap: 28px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.field input {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  background: var(--bg);
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
}

.login-submit {
  width: 100%;
  justify-content: center;
  padding: 10px;
}

.login-error {
  color: #e53e3e;
  font-size: 13px;
  min-height: 18px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid #2e4256;
  display: grid;
  gap: 8px;
}

.sidebar-user-btn {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #2e4256;
  border-radius: 6px;
  color: #d7dee8;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  font: inherit;
}

.sidebar-user-btn small {
  color: #89a0b5;
  font-size: 11px;
  text-transform: capitalize;
}

.sidebar-user-btn:hover,
.sidebar-user-btn.active {
  background: #223545;
  color: #ffffff;
}

.sidebar-logout {
  width: 100%;
  color: #d7dee8;
  background: transparent;
  border-color: #2e4256;
}

.sidebar-logout:hover {
  color: #ffffff;
  border-color: #89a0b5;
  background: transparent;
}

/* ── Profile panel ── */

.profile-panel {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

.profile-content {
  display: grid;
  align-content: start;
  gap: 24px;
  max-width: 560px;
  padding: 28px 32px;
}

.profile-card {
  display: grid;
  gap: 20px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.profile-card h3 {
  margin: 0;
  font-size: 16px;
}

.tfa-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tfa-setup-area {
  display: grid;
  gap: 16px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.tfa-qr {
  display: block;
  margin: 12px auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.tfa-secret {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  word-break: break-all;
  color: var(--muted);
  margin: 0 0 16px;
}

.compose-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.compose-card {
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--line);
  width: 560px;
  max-width: calc(100vw - 32px);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.compose-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

@media (max-width: 560px) {
  .nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .section-header,
  .detail-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .trust-grid {
    grid-template-columns: 1fr;
  }

  .message-panel,
  .security-panel {
    margin: 16px;
  }
}
