:root {
  --bg: #f7f8f5;
  --surface: #fff;
  --surface-strong: #f0f4f2;
  --text: #1c2420;
  --muted: #69746e;
  --border: #dbe2dd;
  --primary: #0f6b57;
  --primary-strong: #0a5142;
  --primary-soft: #e4f3ee;
  --amber: #9a6200;
  --amber-soft: #fff3d8;
  --red: #a33a32;
  --red-soft: #ffe8e5;
  --blue: #225ea8;
  --blue-soft: #e6f0ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Yu Gothic", Meiryo, sans-serif;
}

button,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.appShell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topBar,
.topActions,
.cardActions,
.mailMeta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topBar {
  justify-content: space-between;
  margin-bottom: 18px;
}

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

.brandIcon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
}

.brandIcon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
}

.brand p,
.mailCard p,
.metricLabel {
  color: var(--muted);
}

.button,
.iconButton {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.iconButton {
  width: 40px;
  padding: 0;
  background: var(--surface);
  border-color: var(--border);
}

.primary {
  background: var(--primary);
  color: white;
}

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

.secondary {
  background: var(--surface);
  border-color: var(--border);
}

.disabled,
button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.summaryBand {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--border);
  margin-bottom: 18px;
}

.summaryBand > div {
  background: var(--surface);
  padding: 16px;
}

.metricValue {
  display: block;
  font-size: 28px;
  font-weight: 800;
}

.mailList {
  display: grid;
  gap: 14px;
}

.mailCard,
.connectPanel,
.emptyState,
.errorBanner {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.mailCard {
  padding: 18px;
}

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

.mailMain {
  flex: 1;
  min-width: 0;
}

.mailMeta {
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.mailCard h2 {
  margin: 9px 0 4px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.priority,
.status,
.riskFlags span {
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}

.priority-high {
  background: var(--red-soft);
  color: var(--red);
}

.priority-medium {
  background: var(--amber-soft);
  color: var(--amber);
}

.priority-low {
  background: var(--blue-soft);
  color: var(--blue);
}

.priority-loading {
  background: #edf0ec;
  color: var(--muted);
}

.status {
  background: #edf0ec;
}

.riskMark,
.riskFlags span {
  background: var(--amber-soft);
  color: var(--amber);
}

.riskMark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-weight: 800;
}

.analysisGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0 0;
}

.messageBody {
  margin-top: 14px;
}

.messageBodyTitle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}

.messageBodyBox {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 12px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.analysisGrid > div {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-strong);
}

.analysisGrid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.analysisGrid dd {
  margin: 6px 0 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.riskFlags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.replyCandidates {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.replyChoice {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 118px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.replyChoice:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.replyChoice span {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.replyChoice strong {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-height: 1.55;
  font-size: 13px;
}

.replyEditor {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.replyEditor textarea {
  width: 100%;
  min-height: 148px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  line-height: 1.65;
}

.cardActions {
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 14px;
}

.connectPanel,
.emptyState {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 260px;
  padding: 26px;
  color: var(--muted);
}

.errorBanner {
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 700;
}

.hidden {
  display: none;
}

@media (max-width: 760px) {
  .appShell {
    width: min(100% - 20px, 1180px);
  }

  .topBar {
    align-items: flex-start;
    flex-direction: column;
  }

  .summaryBand,
  .analysisGrid,
  .replyCandidates {
    grid-template-columns: 1fr;
  }

  .cardActions {
    align-items: stretch;
    flex-direction: column;
  }
}
