:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --text: #171717;
  --muted: #666f7a;
  --line: #d9dee5;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #be123c;
  --danger-bg: #fff1f2;
  --focus: #f59e0b;
  --shadow: 0 16px 40px rgba(18, 24, 38, 0.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 36px);
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1;
  letter-spacing: 0;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbarActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(280px, 420px) minmax(320px, 1fr);
  gap: 16px;
  padding: 16px clamp(16px, 3vw, 36px) 28px;
  min-height: 0;
}

.sidePanel,
.messagePanel,
.readerPanel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  min-height: 0;
  box-shadow: var(--shadow);
}

.sidePanel {
  padding: 16px;
  overflow: auto;
}

.messagePanel,
.readerPanel {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

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

label,
.metricLabel {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 130px;
}

input:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22);
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

.metrics > div {
  min-height: 72px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics strong {
  display: block;
  margin-top: 6px;
  font-size: 25px;
  line-height: 1;
  letter-spacing: 0;
}

.actionsGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actionsGrid .danger {
  grid-column: 1 / -1;
}

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary {
  background: #ffffff;
  border-color: var(--line);
  color: var(--text);
}

.button.secondary:hover {
  background: var(--panel-2);
}

.button.danger {
  background: var(--danger-bg);
  border-color: #fecdd3;
  color: var(--danger);
}

.button.danger:hover {
  background: #ffe4e6;
}

.button.full {
  width: 100%;
}

.sendPanel {
  margin-top: 18px;
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.sendPanel h2,
.messageListHeader h2,
.readerHeader h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.sendPanel label {
  display: grid;
  gap: 6px;
}

.messageListHeader {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

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

.messageList {
  overflow: auto;
  min-height: 0;
}

.messageItem {
  width: 100%;
  min-height: 86px;
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.messageItem:hover,
.messageItem.active {
  background: #f0fdfa;
}

.messageItem .readMarker {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--accent);
}

.messageItem.read .readMarker {
  background: #c7ced8;
}

.messageItem strong,
.messageItem span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messageItem strong {
  font-size: 14px;
}

.messageItem span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.emptyState {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  background: #ffffff;
}

.reader {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.reader.hidden,
.hidden {
  display: none !important;
}

.readerHeader {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.readerActions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  min-height: 40px;
  background: #ffffff;
}

.segmented button {
  min-width: 72px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 8px 10px;
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: #ccfbf1;
  color: #134e4a;
}

.readerHeader p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

#readerSubject {
  overflow-wrap: anywhere;
}

.readerContent {
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
}

#readerBody {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.6;
  background: #ffffff;
}

#readerHtml {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

#readerHtml.hidden {
  display: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #171717;
  color: #ffffff;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .readerPanel {
    grid-column: 1 / -1;
    min-height: 360px;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbarActions {
    width: 100%;
  }

  .topbarActions .button {
    flex: 1;
  }

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

  .sidePanel,
  .messagePanel,
  .readerPanel {
    box-shadow: none;
  }

  .messagePanel,
  .readerPanel {
    min-height: 360px;
  }

  .readerHeader {
    flex-direction: column;
  }

  .readerActions {
    width: 100%;
    justify-content: space-between;
  }

  .segmented {
    flex: 1;
  }
}
