/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #f4f6f8;
  color: #1a1a2e;
  height: 100vh;
  overflow: hidden;
}

/* ── Login ────────────────────────────────────────────────── */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
}

.login-card {
  background: #fff;
  border-radius: 10px;
  padding: 40px 48px;
  width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 4px;
}

.login-subtitle {
  color: #666;
  margin-bottom: 28px;
  font-size: 13px;
}

.login-form .form-group {
  margin-bottom: 18px;
}

.login-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: #333;
}

.login-form input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color .15s;
}

.login-form input:focus {
  outline: none;
  border-color: #0f3460;
  box-shadow: 0 0 0 3px rgba(15,52,96,.12);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  background: #0f3460;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  width: 100%;
}

.btn-primary:hover:not(:disabled) { background: #1a4a80; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}

.btn-secondary:hover { background: rgba(255,255,255,.1); }

/* ── Error / loading ──────────────────────────────────────── */
.error-message {
  background: #fef0f0;
  border: 1px solid #f5c6c6;
  border-radius: 6px;
  color: #c0392b;
  padding: 9px 12px;
  margin-bottom: 14px;
  font-size: 13px;
}

.loading-screen, .error-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
  color: #555;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #ddd;
  border-top-color: #0f3460;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ── App layout ───────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.top-bar {
  background: #0f3460;
  color: #fff;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.app-name { font-weight: 700; font-size: 15px; }

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── List area ────────────────────────────────────────────── */
.list-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  transition: flex .2s;
}

.list-area.with-detail {
  flex: 0 0 60%;
}

/* ── Filter panel ─────────────────────────────────────────── */
.filter-panel {
  background: #fff;
  border-bottom: 1px solid #e0e4ea;
  padding: 12px 20px;
  display: flex;
  align-items: flex-start;
  gap: 32px;
  flex-shrink: 0;
}

.filter-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: #888;
  letter-spacing: .06em;
  margin-top: 4px;
  margin-right: 8px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-label {
  font-weight: 600;
  color: #444;
  font-size: 13px;
  white-space: nowrap;
}

.filter-options {
  display: flex;
  gap: 12px;
}

.filter-text-input {
  min-width: 240px;
  padding: 7px 10px;
  border: 1px solid #ccd3dd;
  border-radius: 6px;
  font-size: 13px;
}

.filter-text-input:focus {
  outline: none;
  border-color: #0f3460;
  box-shadow: 0 0 0 3px rgba(15,52,96,.12);
}

.filter-radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  cursor: pointer;
  color: #333;
}

.filter-radio-label input { cursor: pointer; }

/* ── Results bar ──────────────────────────────────────────── */
.results-bar {
  padding: 6px 20px;
  background: #f4f6f8;
  border-bottom: 1px solid #e0e4ea;
  font-size: 12px;
  color: #666;
  flex-shrink: 0;
}

/* ── Member table ─────────────────────────────────────────── */
.table-wrapper {
  flex: 1;
  overflow: auto;
}

.member-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.member-table thead th {
  background: #f4f6f8;
  border-bottom: 2px solid #d0d7e2;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #555;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.member-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.member-table th.sortable:hover { background: #eaeef4; }

.member-table tbody tr.member-row {
  cursor: pointer;
  border-bottom: 1px solid #eef0f4;
  transition: background .1s;
}

.member-table tbody tr.member-row:hover { background: #f0f4ff; }
.member-table tbody tr.member-row.selected { background: #dceeff; }

.member-table td {
  padding: 9px 14px;
  font-size: 13px;
  vertical-align: middle;
}

.centered { text-align: center; }

/* ── Status badge ─────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.status-active   { background: #d4edda; color: #155724; }
.status-inactive { background: #f8d7da; color: #721c24; }
.status-pending  { background: #fff3cd; color: #856404; }

/* ── Detail pane ──────────────────────────────────────────── */
.detail-pane {
  flex: 0 0 40%;
  border-left: 2px solid #d0d7e2;
  background: #fff;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e4ea;
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
}

.detail-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: #0f3460;
}

.close-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: #888;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.close-btn:hover { background: #eee; color: #333; }

.detail-body { padding: 0 20px 24px; }

.detail-section {
  margin-top: 20px;
}

.section-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #888;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #eef0f4;
}

.field-list { display: contents; }

.field-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 4px 12px;
  padding: 5px 0;
  border-bottom: 1px solid #f4f6f8;
  align-items: baseline;
}

.field-row dt {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  list-style: none;
}

.field-row dd {
  font-size: 13px;
  color: #222;
  list-style: none;
  word-break: break-word;
}

/* ── Action area ──────────────────────────────────────────── */
.action-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.action-row .btn-primary {
  width: auto;
  padding: 8px 18px;
}

.action-note {
  font-size: 12px;
  color: #888;
  font-style: italic;
}

.email-sent-status {
  margin-top: 8px;
  font-size: 13px;
  color: #155724;
  background: #d4edda;
  border-radius: 6px;
  padding: 8px 12px;
}

/* ── Status select (in detail pane) ──────────────────────── */
.status-select {
  font-size: 13px;
  padding: 3px 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.status-select:focus {
  outline: none;
  border-color: #0f3460;
  box-shadow: 0 0 0 2px rgba(15,52,96,.12);
}

/* ── Send Welcome Pane ────────────────────────────────────── */

.swp-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #f4f6f8;
  overflow: hidden;
}

.swp-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #1a1a2e 0%, #0f3460 100%);
  color: #fff;
  flex-shrink: 0;
  min-height: 60px;
}

.swp-cancel-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.swp-cancel-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.swp-cancel-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.swp-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.swp-title-main {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.65);
}

.swp-title-member {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.swp-send-btn {
  white-space: nowrap;
  flex-shrink: 0;
  width: auto;  /* prevent btn-primary width:100% from applying */
}

.swp-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.swp-meta {
  background: #fff;
  border-bottom: 1px solid #dde1e7;
  padding: 10px 20px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.swp-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.swp-label {
  font-weight: 600;
  font-size: 12px;
  color: #666;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.swp-to-label {
  margin-left: 16px;
}

.swp-to-addr {
  font-size: 13px;
  color: #0f3460;
  font-weight: 500;
}

.swp-template-radios {
  display: flex;
  gap: 14px;
}

.swp-template-radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  cursor: pointer;
}

.swp-template-radio-label input {
  cursor: pointer;
}

.swp-subject-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.swp-subject-input {
  flex: 1;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.swp-subject-input:focus {
  border-color: #0f3460;
  box-shadow: 0 0 0 2px rgba(15, 52, 96, 0.1);
}

.swp-subject-input:disabled {
  background: #f8f9fa;
  opacity: 0.7;
}

.swp-error {
  background: #f8d7da;
  color: #721c24;
  padding: 8px 20px;
  font-size: 13px;
  border-bottom: 1px solid #f5c6cb;
  flex-shrink: 0;
}

.swp-editor-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.swp-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.swp-editor-pane {
  border-right: 2px solid #dde1e7;
}

.swp-pane-header {
  background: #f0f2f5;
  border-bottom: 1px solid #dde1e7;
  padding: 6px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.swp-body-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 16px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
  background: #fafbfc;
  color: #1a1a2e;
  tab-size: 2;
  box-sizing: border-box;
}

.swp-body-textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.swp-preview-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

/* ── Editor / preview mode-toggle (hidden on desktop) ────── */
.swp-mode-toggle {
  display: none;
  font-size: 11px;
  font-weight: 600;
  color: #0f3460;
  background: none;
  border: 1px solid #0f3460;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Mobile / responsive ────────────────────────────────────
   Detail pane becomes a full-screen overlay instead of a
   side-by-side panel; other chrome adapts to narrow viewports.
   ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Login ── */
  .login-card {
    width: calc(100vw - 40px);
    padding: 28px 24px;
  }

  /* Top bar: prevent long title from squishing the logout btn */
  .app-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  /* Filter panel: stack groups vertically ── */
  .filter-panel {
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
  }

  .filter-group {
    flex-wrap: wrap;
  }

  .filter-text-input {
    min-width: 0;
    flex: 1;
  }

  /* List area must NOT shrink when the detail overlay is open */
  .list-area.with-detail {
    flex: 1;
  }

  /* Detail pane: full-screen fixed overlay ── */
  .detail-pane {
    position: fixed;
    inset: 0;
    flex: none;
    z-index: 200;
    border-left: none;
    border-top: 3px solid #0f3460;
  }

  /* Field rows: stack label above value (fits narrow screens) */
  .field-row {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 7px 0;
  }

  .field-row dt {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  /* Action button: full-width, easy thumb tap */
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .action-row .btn-primary {
    width: 100%;
    padding: 12px;
    font-size: 15px;
  }

  /* Member table: keep Name (2), Status (6), Welcome Email (7)
     Hide: Submitted (1), Spouse (3), Anniversary (4),
           State/Country (5), First Marriage (8)             */
  .member-table th:nth-child(1),
  .member-table td:nth-child(1),
  .member-table th:nth-child(3),
  .member-table td:nth-child(3),
  .member-table th:nth-child(4),
  .member-table td:nth-child(4),
  .member-table th:nth-child(5),
  .member-table td:nth-child(5),
  .member-table th:nth-child(8),
  .member-table td:nth-child(8) {
    display: none;
  }

  /* Send Welcome Pane header:
     Row 1 — member name (full width)
     Row 2 — [Cancel] [Send Now] side-by-side               */
  .swp-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 16px 12px;
    min-height: auto;
  }

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

  .swp-header-actions .swp-cancel-btn,
  .swp-header-actions .swp-send-btn {
    flex: 1;
  }

  .swp-meta {
    padding: 10px 16px;
  }

  .swp-to-label {
    margin-left: 0;
  }

  /* Show the editor ↔ preview toggle button */
  .swp-mode-toggle {
    display: inline-flex;
    align-items: center;
  }

  /* Stack editor / preview vertically; only active pane shown */
  .swp-editor-area {
    flex-direction: column;
  }

  .swp-editor-pane {
    border-right: none;
    border-bottom: 2px solid #dde1e7;
  }

  .swp-editor-area.swp-edit-mode .swp-preview-pane {
    display: none;
  }

  .swp-editor-area.swp-preview-mode .swp-editor-pane {
    display: none;
  }
}
