:root {
  color-scheme: light;
  --bg: #ece9e3;
  --surface: #f7f5ef;
  --panel: #fffdf7;
  --panel-2: #f1eee6;
  --border: #d8d1c4;
  --muted-border: #e8e1d6;
  --text: #211f1a;
  --muted: #716b62;
  --accent: #245c73;
  --accent-soft: #e4f0f3;
  --success: #1f7a4d;
  --warning: #a45f12;
  --danger: #bd2f2f;
  --shadow: 0 12px 30px rgba(54, 48, 39, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  font-size: 13px;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.title {
  font-size: 18px;
  font-weight: 750;
}

.subtitle,
.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 18px 22px 28px;
}

.tab-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tabs {
  display: inline-flex;
  align-self: flex-start;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
}

.tab {
  min-width: 120px;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.tab:hover,
.tab.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 4px 12px rgba(54, 48, 39, 0.08);
}

.error-banner {
  width: min(1236px, calc(100% - 44px));
  margin: 14px auto 0;
  padding: 10px 12px;
  border: 1px solid #e6aaa5;
  border-radius: 8px;
  background: #fff0ed;
  color: var(--danger);
  font-size: 13px;
}

.card,
.preview-panel,
.label-panel,
.headers-panel,
.context-sections details {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.card {
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.email-list-panel {
  min-height: 0;
}

.list {
  height: calc(100vh - 290px);
  min-height: 420px;
  overflow: auto;
}

.row {
  padding: 13px 16px;
  border-bottom: 1px solid var(--muted-border);
  cursor: pointer;
  border-left: 4px solid transparent;
  background: var(--panel);
}

.row:hover,
.row.active {
  background: #f7f1e8;
}

.row.active {
  border-left-color: var(--accent);
}

.row-meta,
.row-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.row-meta span,
.row-footer span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-subject {
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-dot {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 2px 8px;
  border: 1px solid #abd7b8;
  border-radius: 999px;
  background: #edf8ef;
  color: var(--success);
  font-size: 11px;
  font-weight: 700;
}

.preview-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-nav-center {
  display: flex;
  align-items: center;
  gap: 10px;
}

.annotation-status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
}

.annotation-status.saved {
  border-color: #abd7b8;
  background: #edf8ef;
  color: var(--success);
}

.annotation-status.unsaved {
  border-color: #ebc28c;
  background: #fff4df;
  color: var(--warning);
}

.preview-panel {
  min-height: 520px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mail {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fffdf8;
}

.mail-frame,
.mail-text {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #fffdf8;
  color: #15130f;
  border: 0;
  width: 100%;
}

.mail-text {
  margin: 0;
  padding: 20px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}

.label-panel {
  padding: 18px;
}

.headers-panel {
  padding: 16px;
}

.section-title {
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 750;
}

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

.headers-grid div {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--muted-border);
  border-radius: 8px;
  background: var(--panel-2);
}

.headers-grid span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.headers-grid strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.45;
}

.label-panel.empty {
  min-height: 180px;
}

.review-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.review-title h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.review-title p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.message-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--muted-border);
  border-radius: 8px;
  background: var(--panel-2);
}

.message-row > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.message-row code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.review-actions .btn {
  min-height: 44px;
  padding: 10px 12px;
  font-weight: 700;
}

.field-label {
  margin-bottom: 6px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 10px;
  font-weight: 750;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}

.pill.ok {
  color: var(--success);
  border-color: #abd7b8;
  background: #edf8ef;
}

.pill.warn {
  color: var(--warning);
  border-color: #ebc28c;
  background: #fff4df;
}

.pill.err {
  color: var(--danger);
  border-color: #e6aaa5;
  background: #fff0ed;
}

.btn,
.input,
.select,
.textarea {
  border: 1px solid var(--border);
  background: #fffdf8;
  color: var(--text);
  border-radius: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 7px 11px;
  cursor: pointer;
}

.btn:hover:not(:disabled),
.btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  min-height: 42px;
  font-weight: 700;
}

.btn.primary:hover:not(:disabled) {
  background: #1b495b;
  color: #fff;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  font-size: 13px;
}

.comment-field {
  display: block;
  margin-bottom: 16px;
}

.comment-input {
  min-height: 92px;
  resize: vertical;
  line-height: 1.45;
}

.select:disabled {
  background: #eee9df;
  color: var(--muted);
}

.toolbar,
.btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar {
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

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

.json-preview {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #eee9df;
  color: #39342c;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
}

.context-sections {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.context-sections details {
  overflow: hidden;
  box-shadow: none;
}

.context-sections summary {
  cursor: pointer;
  padding: 13px 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--muted-border);
}

.context-body {
  padding: 12px 16px;
  color: #3f3a32;
  font-size: 13px;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(520px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(54, 48, 39, 0.18);
  z-index: 10;
}

.toast.error {
  border-color: #e6aaa5;
  color: var(--danger);
}

.toast.success {
  border-color: #abd7b8;
  color: var(--success);
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  padding: 22px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
}

.empty {
  min-height: 160px;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

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

  .main,
  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .tabs {
    width: 100%;
  }

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

  .list {
    height: 560px;
    min-height: 360px;
  }

  .preview-panel {
    min-height: 480px;
  }

  .preview-nav,
  .preview-nav-center {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .review-actions,
  .headers-grid {
    grid-template-columns: 1fr;
  }

  .btn-row,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar .select,
  .toolbar .input,
  .toolbar .btn {
    max-width: none !important;
  }
}
