:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #eef4f1;
  --file-bg: #fbfbf8;
  --input-bg: #fbfbf8;
  --ink: #1f2933;
  --muted: #657381;
  --line: #d6ddd8;
  --navy: #173b66;
  --green: #0f7b65;
  --amber: #b67818;
  --red: #b23a3a;
  --success-surface: #e9f6f0;
  --warning-surface: #fff5dc;
  --danger-surface: #fff0ee;
  --accent-surface: #fdf4df;
  --drop-border: #9baaa5;
  --drop-hover: #e7f0ec;
  --plan-bg: #fff8e8;
  --plan-line: #dfd2b6;
  --plan-text: #624615;
  --plan-strong: #3f2c0c;
  --secondary-bg: #ece8dc;
  --progress-bg: #e8ece8;
  --log-border: #ecefe9;
  --chip-bg: #ffffff;
  --chip-border: #e2e8e3;
  --iframe-bg: #ffffff;
  --toggle-bg: #ffffff;
  --toggle-hover: #eef4f1;
  --toggle-icon: #173b66;
  --shadow: 0 14px 36px rgba(31, 41, 51, 0.09);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101316;
  --surface: #191f24;
  --surface-2: #202a2b;
  --file-bg: #151a1e;
  --input-bg: #12171b;
  --ink: #edf2f1;
  --muted: #a7b3bd;
  --line: #344049;
  --navy: #b6cdf4;
  --green: #3cc69f;
  --amber: #e4b34d;
  --red: #ff7a73;
  --success-surface: #12352e;
  --warning-surface: #382b12;
  --danger-surface: #3a1d20;
  --accent-surface: #2c281a;
  --drop-border: #52645e;
  --drop-hover: #263432;
  --plan-bg: #211e15;
  --plan-line: #665331;
  --plan-text: #e7cf96;
  --plan-strong: #ffe4a6;
  --secondary-bg: #2c3338;
  --progress-bg: #2a3438;
  --log-border: #2d373d;
  --chip-bg: #12171b;
  --chip-border: #334148;
  --iframe-bg: #ffffff;
  --toggle-bg: #20272d;
  --toggle-hover: #26323a;
  --toggle-icon: #f3cc66;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
}

* {
  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 {
  font: inherit;
}

body,
.panel,
.metric,
.file-card,
.drop-zone,
.connection,
.job-pill,
.logs,
.plan-box,
.control-grid input,
button {
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.app-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.topbar,
.panel-heading,
.actions,
.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  color: var(--navy);
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1;
}

h2 {
  font-size: 21px;
  line-height: 1.15;
}

.connection,
.job-pill {
  min-width: 120px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.connection.ready,
.job-pill.completed {
  border-color: rgba(15, 123, 101, 0.24);
  background: var(--success-surface);
  color: var(--green);
}

.connection.warn,
.job-pill.stopping,
.job-pill.running {
  border-color: rgba(182, 120, 24, 0.28);
  background: var(--warning-surface);
  color: var(--amber);
}

.job-pill.failed,
.job-pill.stopped {
  border-color: rgba(178, 58, 58, 0.24);
  background: var(--danger-surface);
  color: var(--red);
}

.theme-toggle {
  display: inline-grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--toggle-bg);
  color: var(--toggle-icon);
  padding: 0;
  box-shadow: var(--shadow);
}

.theme-toggle:hover {
  background: var(--toggle-hover);
}

.theme-icon {
  grid-area: 1 / 1;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

:root[data-theme="light"] .moon-icon,
:root[data-theme="dark"] .sun-icon {
  opacity: 0;
  transform: scale(0.72) rotate(-20deg);
}

:root[data-theme="light"] .sun-icon,
:root[data-theme="dark"] .moon-icon {
  opacity: 1;
  transform: scale(1) rotate(0);
}

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

.metric {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric.accent {
  background: var(--accent-surface);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}

.metric strong {
  display: block;
  overflow: hidden;
  color: var(--navy);
  font-size: 25px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 16px;
  align-items: stretch;
}

.workspace.lower {
  margin-top: 16px;
}

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

.upload-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px;
  margin-top: 16px;
}

.drop-zone {
  position: relative;
  display: grid;
  min-height: 120px;
  align-content: center;
  border: 1px dashed var(--drop-border);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.drop-zone:hover {
  border-color: var(--green);
  background: var(--drop-hover);
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-title {
  color: var(--navy);
  font-size: 18px;
  font-weight: 800;
}

.drop-meta {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.file-card {
  min-width: 0;
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 54px 16px 16px;
  background: var(--file-bg);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.file-card strong {
  color: var(--ink);
}

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

.open-list-link {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--green);
  padding: 0 12px;
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.16s ease;
}

.open-list-link:hover {
  border-color: rgba(15, 123, 101, 0.36);
  background: var(--success-surface);
  transform: translateY(-1px);
}

.file-card-shell {
  position: relative;
  min-width: 0;
}

.delete-file {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  display: inline-grid;
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--red);
  padding: 0;
  box-shadow: none;
}

.delete-file:hover:not(:disabled) {
  background: var(--danger-surface);
  border-color: rgba(178, 58, 58, 0.32);
}

.delete-file svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.switch input {
  width: 44px;
  height: 24px;
  accent-color: var(--green);
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 18px;
}

.control-grid label:last-child,
.control-grid .wide-control {
  grid-column: 1 / -1;
}

label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.control-grid input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 0 13px;
  outline: none;
}

.control-grid input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 123, 101, 0.12);
}

.plan-box {
  min-width: 0;
  min-height: 116px;
  margin-top: 16px;
  border: 1px solid var(--plan-line);
  border-radius: 8px;
  background: var(--plan-bg);
  padding: 16px;
  color: var(--plan-text);
  font-size: 14px;
  line-height: 1.55;
}

.plan-box strong {
  color: var(--plan-strong);
}

.actions {
  margin-top: 16px;
}

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

.tab-view {
  display: none;
}

.tab-view.active {
  display: block;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 900;
  transition: transform 0.16s ease, opacity 0.16s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.view-tab {
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--secondary-bg);
  color: var(--muted);
  padding: 0 10px;
}

.view-tab.active {
  border-color: rgba(15, 123, 101, 0.34);
  background: var(--success-surface);
  color: var(--green);
}

.open-list-link {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--green);
  padding: 0 12px;
}

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

.secondary {
  background: var(--secondary-bg);
  color: var(--ink);
}

.preview-panel,
.log-panel {
  min-height: 500px;
}

iframe {
  width: 100%;
  height: 428px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--iframe-bg);
}

.progress {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--progress-bg);
  margin-top: 18px;
}

.progress div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.2s ease;
}

.progress-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.logs {
  height: 342px;
  overflow: auto;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--file-bg);
  padding: 10px;
}

.log-line {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid var(--log-border);
  padding: 9px 2px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.log-line:last-child {
  border-bottom: 0;
}

.log-time {
  color: #7b878f;
  font-weight: 800;
}

.log-message {
  overflow-wrap: anywhere;
}

.recipient-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.recipient-preview span {
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--chip-border);
  border-radius: 6px;
  background: var(--chip-bg);
  padding: 4px 7px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.log-line.success .log-message {
  color: var(--green);
}

.log-line.error .log-message {
  color: var(--red);
}

.log-line.warning .log-message {
  color: var(--amber);
}

.empty-state {
  color: var(--muted);
  padding: 12px;
}

.recipient-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  max-height: 342px;
  overflow: auto;
  padding-right: 4px;
}

.recipient-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--file-bg);
  padding: 10px 12px;
}

.recipient-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.recipient-row strong {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.delivery-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
  padding-right: 4px;
  margin-top: 16px;
}

.delivery-summary {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--file-bg);
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
}

.delivery-summary strong {
  color: var(--ink);
}

.delivery-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 94px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--file-bg);
  padding: 10px 12px;
}

.delivery-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.delivery-row strong {
  min-width: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.delivery-row em {
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--secondary-bg);
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
  text-align: center;
}

.delivery-row small {
  grid-column: 2 / -1;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.delivery-row.sent em,
.delivery-row.test em {
  background: var(--success-surface);
  color: var(--green);
}

.delivery-row.failed em {
  background: var(--danger-surface);
  color: var(--red);
}

.delivery-row.sending em {
  background: var(--warning-surface);
  color: var(--amber);
}

@media (max-width: 980px) {
  .summary-grid,
  .workspace {
    grid-template-columns: 1fr 1fr;
  }

  .workspace {
    display: block;
  }

  .panel + .panel {
    margin-top: 16px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 20px, 1280px);
    padding-top: 18px;
  }

  .topbar,
  .panel-heading,
  .actions,
  .progress-meta {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .connection {
    flex: 1;
  }

  .summary-grid,
  .upload-row,
  .control-grid {
    grid-template-columns: 1fr;
  }

  .control-grid label:last-child,
  .control-grid .wide-control {
    grid-column: auto;
  }

  h1 {
    font-size: 32px;
  }

  .metric strong {
    font-size: 21px;
  }
}
