:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-strong: #f9fafb;
  --border: #d9dde5;
  --text: #111827;
  --muted: #687385;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b91c1c;
  --warning: #b45309;
  --success: #2f855a;
  --blue: #2563eb;
  --shadow: 0 12px 32px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

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

body.modal-open {
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: nowrap;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 36px);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar-title {
  display: flex;
  flex: 1 1 auto;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.topbar h1,
.login-panel h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-controls {
  display: grid;
  flex: 0 1 auto;
  gap: 8px;
  justify-items: end;
  min-width: 0;
}

.topbar-language {
  display: flex;
  justify-content: flex-end;
}

.topbar-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: #1f2937;
  font-weight: 800;
}

.tab-list,
.control-row,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.topbar .tab-list {
  flex: 0 1 auto;
  justify-content: flex-end;
}

.topbar form {
  margin: 0;
  flex: 0 0 auto;
}

.tab-button,
.ghost-button,
.primary-button,
.download-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 13px;
  font-weight: 700;
  line-height: 1.2;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease,
    transform 150ms ease;
}

.tab-button,
.ghost-button {
  color: var(--text);
  background: var(--surface-strong);
  border-color: var(--border);
}

.tab-button.active {
  color: #ffffff;
  background: #1f2937;
  border-color: #1f2937;
}

.tab-button:hover,
.ghost-button:hover {
  background: #e4eaf2;
  border-color: #aeb8c8;
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.08);
  transform: translateY(-1px);
}

.tab-button.active:hover {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.2);
}

.primary-button,
.download-button {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
}

.primary-button:hover,
.download-button:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 10px 22px rgba(17, 94, 89, 0.22);
  transform: translateY(-1px);
  text-decoration: none;
}

.ghost-button.small {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 13px;
}

.ghost-button.danger {
  color: var(--danger);
}

.ghost-button.danger:hover {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

button:disabled:hover {
  box-shadow: none;
  transform: none;
}

.language-control {
  display: grid;
  flex: 0 0 auto;
  gap: 0;
  min-width: 86px;
}

.language-control span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.language-control select {
  min-height: 34px;
  padding: 6px 28px 6px 10px;
  background: var(--surface-strong);
}

.app-layout {
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 34px);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.panel,
.table-wrap,
.notice,
.empty-state {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.notice,
.empty-state {
  margin-bottom: 16px;
  padding: 14px 16px;
  color: var(--muted);
  box-shadow: none;
}

.notice.warn {
  color: #7c2d12;
  background: #fff7ed;
  border-color: #fed7aa;
}

.notice.good {
  color: #14532d;
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.smtp-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.smtp-status-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.smtp-status-grid strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.run-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
  gap: 12px;
  align-items: stretch;
}

.run-summary > div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
}

.run-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.progress-track {
  height: 12px;
  margin-top: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.progress-track > div {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 180ms ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  min-height: 24px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

.table-wrap.compact {
  margin-top: 16px;
  box-shadow: none;
}

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

.compact table {
  min-width: 620px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #374151;
  background: var(--surface-strong);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.good,
.good {
  color: var(--success);
}

.badge.good {
  background: #ecfdf3;
}

.badge.warn,
.warn {
  color: var(--warning);
}

.badge.warn {
  background: #fffbeb;
}

.badge.bad,
.bad {
  color: var(--danger);
}

.badge.bad {
  background: #fef2f2;
}

.badge.neutral,
.neutral {
  color: var(--blue);
}

.badge.neutral {
  background: #eff6ff;
}

.badge.muted {
  color: var(--muted);
  background: #f3f4f6;
}

.email-error-badge {
  cursor: help;
  text-decoration: underline dotted currentColor;
  text-underline-offset: 3px;
}

.hover-tooltip {
  position: fixed;
  z-index: 1000;
  width: min(620px, calc(100vw - 28px));
  max-height: min(360px, calc(100vh - 28px));
  overflow: auto;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 12px 14px;
  color: #7f1d1d;
  background: #fff7f7;
  box-shadow: 0 18px 42px rgba(127, 29, 29, 0.18);
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 12px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  white-space: pre-wrap;
}

.hover-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.stat-progress {
  display: grid;
  min-width: 170px;
  gap: 7px;
}

.mini-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.mini-progress-track > div {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 180ms ease;
}

.mini-progress-text {
  color: var(--muted);
  font-size: 12px;
}

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

label,
fieldset {
  min-width: 0;
}

label span,
fieldset legend {
  display: block;
  margin-bottom: 7px;
  color: #374151;
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: #ffffff;
}

textarea {
  resize: vertical;
}

fieldset {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.wide-field,
.weekday-grid {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.form-actions .primary-button {
  flex: 1 1 auto;
}

.edit-notice {
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px 12px;
  color: #1e3a8a;
  background: #eff6ff;
  font-weight: 700;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: clamp(14px, 4vw, 34px);
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.48);
  backdrop-filter: blur(3px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(1040px, 100%);
  max-height: min(86vh, 860px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(17, 24, 39, 0.24);
}

.modal-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h3 {
  margin: 0;
  font-size: 18px;
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(56px, 1fr));
  gap: 8px;
}

.weekday-grid label,
.toggle-line {
  display: flex;
  gap: 8px;
  align-items: center;
}

.weekday-grid input,
.toggle-line input {
  width: auto;
  min-height: auto;
}

.toggle-line span,
.weekday-grid span {
  margin: 0;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.chart-panel h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.highchart-container {
  display: block;
  width: 100%;
  min-height: 340px;
  height: 340px;
}

.chart-empty {
  display: grid;
  min-height: 300px;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 36px));
  min-height: 0;
  transform: translateY(20px);
  border-radius: 8px;
  padding: 0;
  color: #ffffff;
  background: #1f2937;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    padding 160ms ease;
}

#toast.ok,
#toast.bad {
  min-height: 44px;
  padding: 12px 14px;
  opacity: 1;
  transform: translateY(0);
}

#toast.bad {
  background: var(--danger);
}

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

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel .brand-mark {
  margin-bottom: 16px;
}

.login-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.login-head .brand-mark {
  margin-bottom: 0;
}

.compact-language {
  width: min(180px, 52%);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.form-error,
.form-warning {
  margin: 0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.form-error {
  color: #7f1d1d;
  background: #fef2f2;
}

.form-warning {
  color: #7c2d12;
  background: #fff7ed;
}

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

  .topbar-controls,
  .topbar-language,
  .topbar-actions {
    justify-items: stretch;
    justify-content: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .topbar .tab-list {
    justify-content: flex-start;
  }

  .section-head,
  .run-summary {
    align-items: stretch;
  }

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

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

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .app-layout {
    padding: 14px;
  }

  .topbar {
    padding: 12px 14px;
  }

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

  .tab-button,
  .ghost-button,
  .primary-button,
  .download-button {
    width: 100%;
  }

  .language-control {
    width: auto;
  }

  .compact-language {
    width: min(180px, 58%);
  }

  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .run-summary,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .modal {
    padding: 10px;
    place-items: stretch;
  }

  .modal-dialog {
    max-height: calc(100vh - 20px);
    padding: 14px;
  }

  .modal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .smtp-status-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .highchart-container {
    height: 300px;
    min-height: 300px;
  }
}
