:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f4;
  --ink: #182224;
  --muted: #657174;
  --line: #d9e1e3;
  --accent: #0f766e;
  --accent-2: #134e4a;
  --warn: #a16207;
  --danger: #b42318;
  --ok: #157347;
  --shadow: 0 12px 32px rgba(24, 34, 36, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

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

.sidebar {
  background: #162326;
  color: #f3fbfb;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: #20363a;
  border-radius: 8px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-footer span {
  color: #a8bbbf;
  font-size: 13px;
}

nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: #d8e6e8;
  text-align: left;
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
}

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

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 4px;
  padding: 14px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

.topbar p {
  color: var(--muted);
  margin-top: 5px;
}

.topbar-actions,
.approval-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 13px;
  font-weight: 700;
  cursor: pointer;
}

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

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

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

.button.danger {
  background: #fff4f2;
  color: var(--danger);
  border-color: #ffd7d2;
}

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

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}

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

.metric strong {
  display: block;
  font-size: 28px;
  margin-top: 4px;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(340px, 0.38fr) minmax(0, 0.62fr);
  gap: 16px;
  align-items: start;
}

.queue-panel,
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-heading,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2,
.detail-header h2 {
  font-size: 18px;
}

.search-wrap {
  display: grid;
  gap: 4px;
}

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

.search-wrap input {
  width: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

.email-list {
  max-height: calc(100vh - 235px);
  overflow: auto;
}

.email-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 14px 16px;
  cursor: pointer;
}

.email-item:hover,
.email-item.active {
  background: var(--surface-2);
}

.email-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.email-meta,
.email-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 7px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #edf3f3;
  color: #304245;
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
}

.badge.high {
  background: #fff1f0;
  color: var(--danger);
}

.badge.medium {
  background: #fff7e6;
  color: var(--warn);
}

.badge.low {
  background: #eaf7ef;
  color: var(--ok);
}

.detail-panel {
  min-height: calc(100vh - 161px);
}

.empty-state {
  padding: 42px;
  display: grid;
  gap: 10px;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--ink);
}

.hidden {
  display: none;
}

.detail-view {
  padding: 18px;
}

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

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.detail-header p {
  color: var(--muted);
  margin-top: 5px;
}

.confidence {
  min-width: 92px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  color: var(--muted);
}

.confidence strong {
  display: block;
  color: var(--ink);
  font-size: 24px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.45fr);
  gap: 14px;
  margin-top: 16px;
}

.section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-top: 14px;
}

.detail-grid .section {
  margin-top: 0;
}

.section-title h3 {
  font-size: 15px;
}

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

.field-list {
  display: grid;
  grid-template-columns: minmax(150px, 0.35fr) minmax(0, 0.65fr);
  gap: 8px 12px;
  margin: 14px 0 0;
}

.field-list dt {
  color: var(--muted);
}

.field-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.missing-list {
  margin: 12px 0 0;
  padding-left: 19px;
  color: var(--danger);
}

.missing-list.ok {
  color: var(--ok);
  padding-left: 0;
  list-style: none;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.action-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.action-summary div {
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-width: 0;
}

.action-summary span,
.action-summary strong {
  display: block;
}

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

.action-summary strong {
  margin-top: 4px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.tab {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.tab.active {
  border-color: var(--accent);
  color: var(--accent-2);
  background: #e8f6f4;
  font-weight: 800;
}

.draft-output,
.original-email {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 12px 0 0;
  max-height: 330px;
  overflow: auto;
  line-height: 1.45;
}

.approval-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfb;
  margin-top: 14px;
}

.approval-bar span {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 27, 30, 0.36);
}

form {
  padding: 18px;
  display: grid;
  gap: 14px;
}

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

.icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

label input,
label textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

@media (max-width: 1100px) {
  .workbench,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .email-list {
    max-height: 410px;
  }
}

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

  .sidebar {
    position: static;
  }

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

  main {
    padding: 16px;
  }

  .topbar,
  .approval-bar {
    flex-direction: column;
    align-items: stretch;
  }

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

  .action-summary {
    grid-template-columns: 1fr;
  }

  .field-list {
    grid-template-columns: 1fr;
  }

  .search-wrap input {
    width: 100%;
  }
}

/* --- Integration status chips --- */
.integration-status {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-right: 4px;
}

.chip {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.chip.live {
  background: rgba(21, 115, 71, 0.12);
  color: var(--ok);
  border-color: rgba(21, 115, 71, 0.3);
}

.chip.demo {
  background: var(--surface-2);
  color: var(--muted);
}

/* --- Execution result panel --- */
.execution-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  background: #f8fafb;
}

.exec-badge {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.exec-badge.success { color: var(--ok); }
.exec-badge.error { color: var(--danger); }
.exec-badge.skipped { color: var(--muted); }

.exec-summary {
  margin: 4px 0 12px;
  font-size: 14px;
  font-weight: 600;
}

.exec-detail {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.exec-detail div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-width: 0;
}

.exec-detail span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.exec-detail strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.exec-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 720px) {
  .exec-detail {
    grid-template-columns: 1fr;
  }
}
