/* BSR Mail-Header-Tool – App Mode nach BSR Design Guide */

:root {
  /* Brand Override */
  --brand-primary: #575e66;
  --brand-accent: #f7a723;
  --brand-accent-hover: #d89216;
  --brand-accent-soft: #fff8ec;
  --brand-focus: rgba(247, 167, 35, 0.22);
  --brand-sidebar-hover: rgba(247, 167, 35, 0.18);

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e0e3e8;
  --border-strong: #c9ced6;

  --text: #171c26;
  --muted: #667085;
  --muted-strong: #475569;

  --accent: var(--brand-accent);
  --accent-hover: var(--brand-accent-hover);
  --accent-soft: var(--brand-accent-soft);

  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: var(--brand-accent);
  --warning-soft: #fff8ec;

  --slate: var(--brand-primary);

  --radius-sm: 3px;
  --radius: 4px;
  --radius-pill: 999px;

  --shadow: 0 2px 10px rgba(15, 23, 42, 0.045);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.075);

  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --focus-ring: 0 0 0 3px var(--brand-focus);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

[hidden] { display: none !important; }

.muted { color: var(--muted); font-weight: 400; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--slate);
  color: #fff;
  box-shadow: 0 6px 20px rgba(87, 94, 102, 0.18);
}

.topbar-inner {
  max-width: 1280px;
  min-height: 58px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 15px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.brand-text { font-weight: 500; }
.brand-text strong { font-weight: 800; }

.tabs {
  display: flex;
  align-self: stretch;
  gap: 4px;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.tab:hover { color: #fff; background: var(--brand-sidebar-hover); }

.tab.active { color: #fff; }
.tab.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 3px;
  background: var(--accent);
}

.tab:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }

.topbar-badge {
  margin-left: auto;
  padding: 4px 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
/* ---------- Layout ---------- */

.content {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 28px 28px;
}

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

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

.page-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.4px;
}

.page-subtitle {
  margin-top: 2px;
  color: var(--muted);
}

.page-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font: 500 12px/1.2 var(--font);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn-sm { min-height: 28px; padding: 5px 10px; }
.btn-icon { min-height: 28px; width: 28px; padding: 0; font-size: 16px; line-height: 1; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--muted-strong);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--surface);
  border-color: #f3c4c4;
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }

.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn .spinner { width: 12px; height: 12px; }

/* ---------- Panel ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted-strong);
}

.panel-body { padding: 16px; }

.panel-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}

/* ---------- Forms ---------- */

.form-grid { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.field-row { display: flex; align-items: center; gap: 12px; }
.field-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.field-row .input { flex: 1; }

.field-label { color: var(--muted-strong); font-size: 12px; font-weight: 600; }

.suffix { color: var(--muted); font-weight: 600; }

.input, .select {
  width: 100%;
  min-height: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: 600 13px/1.2 var(--font);
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .select:focus { border-color: var(--accent); box-shadow: var(--focus-ring); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.check input, input[type="range"] { accent-color: var(--accent); }
.check input { width: 15px; height: 15px; margin: 0; flex-shrink: 0; }
.panel-footer .check { white-space: normal; }

input[type="range"] { width: 100%; margin: 6px 0 0; }

/* ---------- Table ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.table { width: 100%; border-collapse: collapse; font-size: 13px; }

.table th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}

.table td {
  white-space: nowrap;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; width: 1%; }
.table td.name { max-width: 420px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }

.table tfoot td {
  background: var(--surface-2);
  font-weight: 600;
  border-top: 1px solid var(--border-strong);
  border-bottom: 0;
}

.saving-good { color: var(--success); font-weight: 700; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 20px;
  border-radius: var(--radius);
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: #92400e; }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.spinner {
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Notice ---------- */

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border: 1px solid #f5d9a8;
  border-radius: var(--radius);
  color: #7c4a03;
  font-weight: 500;
}

.notice-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
}

/* ---------- Footer & Toasts ---------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 24px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 28px 22px;
  color: var(--muted);
  font-size: 12px;
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 40px));
}

.toast {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-weight: 500;
  animation: toast-in 0.18s ease-out;
}
.toast.error { border-left-color: var(--danger); }

@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }


/* ---------- Mail-Header-Tool ---------- */

:root {
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

.mono { font-family: var(--mono); font-size: 12px; }

.brand-mark { font-size: 17px; line-height: 1; padding-bottom: 2px; }

.select-sm { width: auto; min-height: 32px; padding: 6px 28px 6px 10px; font-size: 12px; font-weight: 500; color: var(--muted-strong); }

.panel-header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.panel-header-actions label.btn { cursor: pointer; }

.help { padding: 12px 16px; background: var(--accent-soft); border-bottom: 1px solid #f5d9a8; }
.help-list { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 6px 16px; margin: 0; }
.help-list dt { font-weight: 700; }
.help-list dd { margin: 0; color: var(--muted-strong); }

.input-wrap { position: relative; }

.header-input {
  display: block;
  width: 100%;
  min-height: 170px;
  height: 170px;
  resize: vertical;
  padding: 12px 16px;
  border: 0;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font: 12px/1.55 var(--mono);
  white-space: pre;
  overflow: auto;
}
.header-input::placeholder { color: var(--muted); font-family: var(--font); font-size: 13px; }
.header-input:focus { box-shadow: inset var(--focus-ring); }

.drop-overlay {
  position: absolute;
  inset: 6px;
  display: none;
  place-items: center;
  border: 1.5px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(255, 248, 236, 0.94);
  color: var(--accent-hover);
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
}
.input-wrap.dragover .drop-overlay { display: grid; }

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

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }

.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi.success { border-top-color: var(--success); }
.kpi.warning { border-top-color: var(--warning); }
.kpi.danger { border-top-color: var(--danger); }

.kpi-label { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; }
.kpi-value { font-size: 22px; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.kpi-value.small { font-size: 15px; font-weight: 700; }
.kpi-sub { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.kpi-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }

/* Auffälligkeiten */
.findings { list-style: none; margin: 0; padding: 0; }
.finding {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
}
.finding:last-child { border-bottom: 0; }
.finding-dot {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}
.finding.danger .finding-dot { background: var(--danger); }
.finding.warning .finding-dot { background: var(--warning); }
.finding.info .finding-dot { background: var(--muted); }
.finding.success .finding-dot { background: var(--success); }
.findings-empty { padding: 14px 16px; color: var(--muted); }

/* Zwei Spalten */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }

/* Schlüssel-Wert-Liste */
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); margin: 0; }
.kv dt, .kv dd { padding: 7px 16px; border-bottom: 1px solid var(--border); }
.kv dt { color: var(--muted-strong); font-size: 12px; font-weight: 600; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv dt:nth-last-of-type(1), .kv dd:last-of-type { border-bottom: 0; }
.kv .sub { display: block; color: var(--muted); font-size: 12px; }
.kv-links { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; font-size: 12px; }

.copy-inline {
  margin-left: 6px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  cursor: pointer;
  vertical-align: 1px;
}
.copy-inline:hover { border-color: var(--accent); color: var(--accent-hover); background: var(--accent-soft); }

/* Tabellen in diesem Tool */
.table td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 180px; }
.table td.top { vertical-align: top; }
.table .cell-sub { display: block; color: var(--muted); font-size: 12px; }
.panel > .table-scroll { overflow-x: auto; }

/* Zustellweg */
.hop-row { cursor: pointer; }
.hop-row td { vertical-align: top; }
.hop-num { color: var(--muted); font-weight: 700; }
.hop-raw td { background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.5 var(--mono); color: var(--muted-strong); }
.table tbody tr.hop-raw:hover td { background: var(--surface-2); }

.delay { display: flex; flex-direction: column; gap: 4px; min-width: 110px; }
.delay-bar { height: 5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 2px; overflow: hidden; }
.delay-bar span { display: block; height: 100%; background: var(--success); }
.delay.warning .delay-bar span { background: var(--warning); }
.delay.danger .delay-bar span { background: var(--danger); }
.delay-text { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Alle Header */
.header-search { width: 260px; min-height: 30px; padding: 6px 10px; font-weight: 500; }
.hdr-table td { vertical-align: top; }
.hdr-name { font-weight: 600; white-space: nowrap; }
.hdr-value { white-space: pre-wrap !important; overflow-wrap: anywhere; font: 12px/1.5 var(--mono); min-width: 300px; }
.hdr-decoded { display: block; margin-top: 3px; color: var(--success); font-family: var(--font); font-size: 12px; font-weight: 600; }
mark { background: #ffe8b3; color: inherit; padding: 0 1px; border-radius: 2px; }

.empty { padding: 28px 16px; color: var(--muted); text-align: center; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .topbar-inner { padding: 0 16px; }
  .brand { min-height: 52px; }
  .topbar-badge { display: none; }
  .content { padding: 18px 16px; }
  .page-header { flex-direction: column; }
  .page-actions { justify-content: flex-start; }
  .footer { padding: 14px 16px 22px; }
  .help-list { grid-template-columns: 1fr; }
  .help-list dd { margin-bottom: 6px; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { padding-bottom: 0; border-bottom: 0; }
  .header-search { width: 100%; }
  .panel-header { flex-wrap: wrap; }
}
