:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #687386;
  --line: #dce2ea;
  --accent: #176b5b;
  --accent-hover: #0f594b;
  --danger: #a64242;
  --danger-bg: #fff0f0;
  --ok-bg: #eaf7f3;
  --shadow: 0 16px 36px rgba(28, 36, 48, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 32px auto;
}

.tool-panel,
.results-section,
.errors-section,
.email-section,
.summary-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tool-panel {
  padding: 24px;
}

.topbar,
.section-heading,
.actions,
.summary-bar {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 24px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 2vw, 2rem);
  line-height: 1.1;
}

h2 {
  font-size: 1rem;
}

.subtle {
  color: var(--muted);
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid #b9dfd5;
  border-radius: 999px;
  background: var(--ok-bg);
  color: #0f594b;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 700;
}

.controls-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
  gap: 16px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-weight: 700;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  font-weight: 500;
}

.field input {
  min-height: 42px;
  padding: 8px 12px;
}

.field textarea {
  min-height: 220px;
  resize: vertical;
  padding: 12px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.92rem;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.14);
}

.file-field input {
  padding-top: 8px;
}

.actions {
  flex-wrap: wrap;
  margin-top: 18px;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

button.secondary:hover:not(:disabled) {
  background: #eef2f6;
}

button.compact {
  min-height: 34px;
  padding: 6px 12px;
}

.summary-bar {
  justify-content: flex-start;
  margin: 18px 0;
  padding: 14px 18px;
}

.summary-bar div {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 96px;
}

.summary-bar strong {
  font-size: 1.35rem;
}

.results-section,
.email-section,
.errors-section {
  margin-top: 18px;
  overflow: hidden;
}

.section-heading {
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.email-actions {
  display: flex;
  gap: 8px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f0f3f7;
  color: #405064;
  font-size: 0.83rem;
  text-transform: uppercase;
}

td {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.86rem;
}

td.masked {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.fields-cell {
  max-width: 320px;
  white-space: pre-wrap;
  word-break: break-word;
}

.email-section textarea {
  display: block;
  width: 100%;
  min-height: 132px;
  border: 0;
  border-top: 1px solid var(--line);
  resize: vertical;
  padding: 12px 18px;
  color: var(--text);
  background: #fff;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9rem;
  outline: none;
}

.email-section textarea:focus {
  box-shadow: inset 0 0 0 3px rgba(23, 107, 91, 0.14);
}

.empty-row td {
  color: var(--muted);
  font-family: inherit;
  text-align: center;
}

.error-list {
  list-style: none;
  margin: 0;
  padding: 12px 18px 18px;
}

.error-list li {
  border: 1px solid #f0cccc;
  border-radius: 6px;
  background: var(--danger-bg);
  color: var(--danger);
  margin-top: 8px;
  padding: 10px 12px;
}

.error-list li.empty {
  border-color: var(--line);
  background: #fff;
  color: var(--muted);
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    margin: 10px auto 24px;
  }

  .tool-panel {
    padding: 16px;
  }

  .topbar,
  .summary-bar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .status-pill {
    align-self: flex-start;
  }
}
