@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap");

:root {
  --bg: #f3f9ff;
  --bg-grid: rgba(104, 167, 255, 0.14);
  --surface: #ffffff;
  --surface-alt: #eaf5ff;
  --surface-strong: #d7ecff;
  --line: #8bb9e6;
  --line-strong: #3a84d8;
  --text: #0f2944;
  --muted: #547393;
  --accent: #1174d9;
  --accent-deep: #0957aa;
  --danger: #a33131;
  --shadow: 0 18px 48px rgba(12, 64, 117, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(0deg, transparent 23px, var(--bg-grid) 24px, transparent 25px),
    linear-gradient(90deg, transparent 23px, var(--bg-grid) 24px, transparent 25px),
    linear-gradient(180deg, #f8fcff 0%, #edf6ff 100%);
  background-size: 24px 24px, 24px 24px, 100% 100%;
  color: var(--text);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

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

button,
input,
select,
textarea,
.surface,
.login-panel,
.stat-card,
.tag,
.tab-button,
.primary-button,
.ghost-button {
  border-radius: 0;
}

a {
  color: inherit;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--line-strong);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.login-panel {
  width: min(100%, 980px);
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  border: 2px solid var(--line-strong);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(232, 245, 255, 0.98));
  box-shadow: var(--shadow);
}

.login-brand {
  padding: 44px;
  border-right: 2px solid var(--line);
  background:
    linear-gradient(135deg, rgba(17, 116, 217, 0.09), rgba(255, 255, 255, 0) 50%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(215, 236, 255, 0.66));
}

.login-brand h1,
.topbar h2,
.section-heading h3 {
  margin: 0;
  font-size: clamp(30px, 4vw, 52px);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.login-copy,
.sidebar-copy,
.settings-note,
.settings-status,
.login-hint,
.pagination-info,
.table-status {
  color: var(--muted);
}

.login-copy {
  max-width: 34rem;
  margin: 18px 0 0;
  font-size: 18px;
  line-height: 1.55;
}

.login-form {
  padding: 44px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field span {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  min-height: 50px;
  padding: 12px 14px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.field textarea {
  resize: vertical;
}

.login-hint {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  font-size: 14px;
}

.form-alert {
  padding: 14px;
  border: 1px solid rgba(163, 49, 49, 0.35);
  background: rgba(163, 49, 49, 0.08);
  color: var(--danger);
}

.form-alert p {
  margin: 0;
}

.primary-button,
.ghost-button,
.tab-button,
.inline-button {
  min-height: 46px;
  padding: 0 18px;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.primary-button {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #ffffff;
}

.primary-button:hover,
.ghost-button:hover,
.tab-button:hover,
.inline-button:hover {
  transform: translate(-2px, -2px);
}

.ghost-button {
  border-color: var(--line);
  background: var(--surface-alt);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
  border-right: 2px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(215, 236, 255, 0.9), rgba(255, 255, 255, 0.98)),
    var(--surface);
}

.sidebar h1 {
  margin: 0;
  font-size: 42px;
  line-height: 0.94;
  letter-spacing: -0.05em;
}

.sidebar-nav {
  display: grid;
  gap: 10px;
}

.tab-button {
  text-align: left;
  border-color: var(--line);
}

.tab-button.is-active {
  border-color: var(--line-strong);
  background: linear-gradient(180deg, #fdfefe 0%, var(--surface-strong) 100%);
  font-weight: 600;
}

.sidebar-meta {
  margin-top: auto;
}

.meta-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  text-transform: uppercase;
}

.sidebar-logout {
  margin-top: -8px;
}

.workspace {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.topbar,
.surface,
.stat-card {
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 18px 20px;
}

.topbar h2,
.section-heading h3 {
  font-size: clamp(24px, 3.2vw, 38px);
}

.topbar h2 {
  line-height: 1.02;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.tab-panel.is-active {
  display: flex;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 16px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  line-height: 1;
}

.controls-surface,
.settings-surface,
.table-surface {
  padding: 20px;
  min-width: 0;
}

.controls-row {
  display: grid;
  grid-template-columns: 1.6fr 180px;
  gap: 12px;
}

.controls-row + .controls-row,
.controls-row + .filter-builder,
.filter-builder + .table-wrap {
  margin-top: 14px;
}

.controls-row-quick {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-wide {
  min-width: 0;
}

.field-small {
  min-width: 0;
}

.section-heading,
.table-header,
.settings-actions {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-end;
}

.settings-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 12px 14px;
  border: 2px solid var(--line);
  background: var(--surface);
}

.field-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.field-checkbox span {
  color: var(--text);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
}

.heading-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.filter-row {
  display: grid;
  grid-template-columns: 220px 180px 1fr 1fr 140px;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
}

.filter-row .field {
  gap: 8px;
}

.table-header {
  margin-bottom: 16px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  max-height: 72vh;
  border: 2px solid var(--line);
  background: #fdfefe;
}

.records-table {
  width: max-content;
  min-width: 2800px;
  border-collapse: collapse;
  table-layout: auto;
}

.records-table th,
.records-table td {
  min-width: 120px;
  padding: 12px 14px;
  border-right: 1px solid rgba(139, 185, 230, 0.7);
  border-bottom: 1px solid rgba(139, 185, 230, 0.7);
  vertical-align: top;
  font-size: 14px;
  line-height: 1.4;
}

.records-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(180deg, #fbfeff 0%, #dbeeff 100%);
  text-align: left;
  white-space: nowrap;
}

.records-table th:first-child,
.records-table td:first-child {
  position: sticky;
  left: 0;
  min-width: 72px;
  z-index: 3;
}

.records-table th:first-child {
  background: linear-gradient(180deg, #fbfeff 0%, #dbeeff 100%);
}

.records-table td:first-child {
  background: #f7fbff;
}

.records-table th button {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: inherit;
}

.records-table tbody tr:nth-child(even) {
  background: rgba(234, 245, 255, 0.55);
}

.records-table tbody tr:hover {
  background: rgba(215, 236, 255, 0.78);
}

.cell-number {
  text-align: right;
  white-space: nowrap;
}

.cell-compact {
  white-space: nowrap;
}

.cell-wrap {
  white-space: normal;
  overflow-wrap: anywhere;
}

.cell-link {
  display: inline-block;
  max-width: 100%;
  color: var(--accent-deep);
  text-decoration: none;
  border-bottom: 1px solid rgba(9, 87, 170, 0.25);
}

.cell-link:hover {
  border-bottom-color: rgba(9, 87, 170, 0.7);
}

.link-stack,
.email-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.cell-clamp {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.inline-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  text-decoration: none;
  background: var(--surface-alt);
}

.inline-button.is-disabled {
  border-color: rgba(139, 185, 230, 0.6);
  color: var(--muted);
  pointer-events: none;
}

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

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

.mailing-compose-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 18px;
}

.mailing-options-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.mailing-textarea {
  min-height: 260px;
  line-height: 1.55;
}

.mailing-chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mailing-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  color: var(--line-strong);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.mail-preview-card {
  min-height: 420px;
  padding: 22px;
  border: 2px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f5fbff 100%);
}

.mail-preview-empty {
  color: var(--muted);
}

.mail-preview-header {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(139, 185, 230, 0.8);
}

.mail-preview-header strong,
.mail-preview-subject {
  overflow-wrap: anywhere;
}

.mail-preview-subject {
  margin-top: 18px;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 600;
}

.mail-preview-attachment {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-top: 18px;
  padding: 16px;
  border: 2px solid rgba(139, 185, 230, 0.8);
  background: rgba(234, 245, 255, 0.55);
}

.mail-preview-attachment-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  min-height: 44px;
  padding: 0 10px;
  background: #f45a4a;
  color: #ffffff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 14px;
}

.mail-preview-attachment p {
  margin: 6px 0 0;
  color: var(--muted);
}

.mail-preview-body {
  margin-top: 24px;
  font-size: 18px;
  line-height: 1.7;
}

.mailing-preview-meta {
  max-width: 18rem;
  color: var(--muted);
  text-align: right;
}

.mailing-table-wrap {
  max-height: 420px;
}

.mailing-recipients-table,
.mailing-campaigns-table {
  min-width: 1200px;
}

.mailing-stat-grid {
  margin-bottom: 18px;
}

.runtime-log-console {
  min-height: 220px;
  max-height: 420px;
  overflow: auto;
  padding: 16px 18px;
  border: 2px solid var(--line);
  background: #eef6ff;
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.runtime-log-line + .runtime-log-line {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(58, 132, 216, 0.22);
}

.runtime-log-meta {
  color: var(--line-strong);
}

.settings-actions {
  grid-column: 1 / -1;
  align-items: center;
}

.settings-status {
  min-height: 24px;
}

.settings-status[data-state="success"] {
  color: #19663b;
}

.settings-status[data-state="error"] {
  color: var(--danger);
}

.settings-details {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
}

.protocol-check {
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
}

.protocol-check strong {
  display: block;
  margin-bottom: 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.protocol-check p {
  margin: 0;
  line-height: 1.5;
}

.protocol-check.is-success {
  border-color: rgba(25, 102, 59, 0.4);
  background: rgba(25, 102, 59, 0.08);
}

.protocol-check.is-error {
  border-color: rgba(163, 49, 49, 0.35);
  background: rgba(163, 49, 49, 0.08);
}

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

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

  .sidebar {
    border-right: 0;
    border-bottom: 2px solid var(--line-strong);
  }

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

  .controls-row,
  .controls-row-quick,
  .filter-row,
  .settings-form,
  .mailing-compose-grid,
  .mailing-options-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .login-panel {
    grid-template-columns: 1fr;
  }

  .login-brand {
    border-right: 0;
    border-bottom: 2px solid var(--line);
  }

  .workspace,
  .sidebar,
  .login-form,
  .login-brand {
    padding: 20px;
  }

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

  .mail-preview-header {
    grid-template-columns: 1fr;
  }

  .mailing-chip-row {
    justify-content: flex-start;
  }

  .table-wrap {
    max-height: 58vh;
  }

  .topbar,
  .section-heading,
  .table-header,
  .pagination,
  .settings-actions,
  .login-hint {
    flex-direction: column;
    align-items: stretch;
  }
}
