:root {
  --navy: #0b2e59;
  --navy-dark: #072040;
  --teal: #0d8a8a;
  --teal-dark: #096b6b;
  --teal-soft: #e6f5f5;
  --bg: #f3f7fa;
  --surface: #ffffff;
  --border: #d8e3ec;
  --text: #162436;
  --muted: #52657a;
  --amber-bg: #fff6e5;
  --amber-border: #f0c36d;
  --amber-text: #855200;
  --danger: #c62828;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(11, 46, 89, 0.07);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 65%, #0d4a6e 100%);
  color: #ffffff;
  border-bottom: 4px solid var(--teal);
  padding: 18px 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #ffffff;
  padding: 2px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  flex-shrink: 0;
  object-fit: cover;
}

.brand-org {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #8be0e0;
}

.site-title {
  margin: 2px 0 4px;
  font-size: 1.4rem;
  line-height: 1.25;
  font-weight: 700;
}

.brand-meta {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.82);
}

.header-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.deadline-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 246, 229, 0.14);
  border: 1px solid rgba(240, 195, 109, 0.55);
  color: #ffe3a8;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.25);
}

.recipient-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  color: #e6f5f5;
}

.recipient-pill code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  color: #ffffff;
}

/* Mailing Procedure Bar */
.procedure-bar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

.procedure-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.procedure-step {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 10px 12px;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.proc-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--teal);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.procedure-step strong {
  display: block;
  font-size: 0.85rem;
  color: var(--navy);
  margin-bottom: 2px;
}

.procedure-step p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.procedure-step code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  color: var(--navy);
  font-weight: 600;
}

/* Main Grid */
.main-grid {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 24px;
  padding-top: 24px;
  padding-bottom: 40px;
  align-items: start;
}

.form-column {
  position: sticky;
  top: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-card {
  padding: 22px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--navy);
}

.card-subtitle {
  margin: 4px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
}

/* Progress Bar */
.progress-wrap {
  margin-bottom: 16px;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.progress-track {
  height: 7px;
  background: #e2ecf3;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal) 0%, var(--navy) 100%);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Form Fields */
.field {
  margin-bottom: 13px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 118px;
  gap: 10px;
}

.field label {
  display: block;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 5px;
}

.req {
  color: var(--danger);
}

.field input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: #ffffff;
  border: 1.5px solid #cbd8e4;
  border-radius: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 138, 138, 0.16);
}

.field input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(198, 40, 40, 0.12);
}

.field-error {
  display: block;
  min-height: 0;
  margin-top: 4px;
  font-size: 0.76rem;
  color: var(--danger);
}

/* Quick Select Chips */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.chip {
  padding: 4px 9px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--navy);
  background: #eef5f9;
  border: 1px solid #cddce8;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover,
.chip.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}

/* Actions */
.action-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.action-heading {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 5px;
}

.action-hint {
  margin: 0 0 12px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.btn-primary,
.btn-secondary,
.btn-provider,
.btn-ghost-sm,
.copy-mini {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s ease;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  font-size: 0.94rem;
  font-weight: 600;
  color: #ffffff;
  background: linear-gradient(135deg, var(--teal) 0%, var(--navy) 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(11, 46, 89, 0.22);
}

.btn-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-icon {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
}

.btn-icon-sm {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.provider-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.btn-provider {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  background: #ffffff;
  border: 1.5px solid var(--border);
}

.btn-provider:hover {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--navy);
}

.provider-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

/* Smartphone Direct App Buttons */
.mobile-primary-providers {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 10px;
}

.mobile-primary-providers[hidden] {
  display: none;
}

.btn-mobile-app {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  padding: 12px 16px;
  font: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-mobile-gmail {
  background: #ffffff;
  color: #b3261e;
  border: 2px solid #ea4335;
  box-shadow: 0 3px 10px rgba(234, 67, 53, 0.14);
}

.btn-mobile-gmail:hover {
  background: #fef2f2;
}

.btn-mobile-outlook {
  background: #ffffff;
  color: #005a9e;
  border: 2px solid #0078d4;
  box-shadow: 0 3px 10px rgba(0, 120, 212, 0.14);
}

.btn-mobile-outlook:hover {
  background: #eff6ff;
}

.android-note {
  margin-top: 10px;
  padding: 9px 11px;
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--amber-text);
  line-height: 1.45;
}

.android-note[hidden] {
  display: none;
}

body.is-mobile #desktopProviderGrid .btn-gmail,
body.is-mobile #desktopProviderGrid .btn-outlook {
  display: none;
}

body.is-mobile #desktopProviderGrid {
  grid-template-columns: 1fr;
}

body.is-mobile #defaultMailBtn {
  background: #f2f7fb;
  color: var(--navy);
  border: 1.5px solid #c9d9e6;
  box-shadow: none;
  padding: 10px 14px;
  font-size: 0.86rem;
}

.secondary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  font-size: 0.81rem;
  font-weight: 600;
  color: var(--navy);
  background: #f2f7fb;
  border: 1px solid #c9d9e6;
}

.btn-secondary:hover {
  background: #e4eff7;
  border-color: var(--navy);
}

.btn-ghost-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.btn-ghost-sm:hover {
  color: var(--navy);
  border-color: var(--navy);
  background: #f4f8fb;
}

.mobile-preview-link {
  display: none;
  margin-top: 12px;
  text-align: center;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--teal-dark);
  text-decoration: none;
}

/* Preview Card */
.preview-card {
  overflow: hidden;
}

.preview-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  background: #f8fbfd;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.row-count-pill {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border: 1px solid #b5e0e0;
  padding: 4px 10px;
  border-radius: 999px;
}

.email-headers {
  padding: 14px 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-header-row {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  font-size: 0.88rem;
}

.eh-label {
  font-weight: 600;
  color: var(--muted);
}

.eh-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.eh-value strong {
  color: var(--navy);
  word-break: break-word;
}

.copy-mini {
  padding: 3px 9px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border: 1px solid #b5e0e0;
  flex-shrink: 0;
}

.copy-mini:hover {
  background: var(--teal);
  color: #ffffff;
  border-color: var(--teal);
}

/* Email Body */
.email-body {
  padding: 24px 24px 28px;
  font-size: 0.92rem;
  color: #1c2b3a;
}

.letter-address {
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 16px;
  line-height: 1.5;
}

.letter-salutation {
  margin: 0 0 12px;
  font-weight: 600;
}

.letter-intro {
  margin: 0 0 20px;
  text-align: justify;
}

/* Dynamic Placeholders */
.ph {
  display: inline;
  padding: 1px 6px;
  border-radius: 5px;
  font-weight: 600;
  background: var(--amber-bg);
  color: var(--amber-text);
  border: 1px dashed var(--amber-border);
  transition: all 0.2s ease;
}

.ph.is-filled {
  background: var(--teal-soft);
  color: var(--navy);
  border: 1px solid #a8dadc;
}

/* Table Section */
.table-section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 10px;
}

.table-section-bar h3,
.rationale-block h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--navy);
}

.table-wrapper {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 24px;
}

.table-wrapper.is-collapsed {
  display: none;
}

.draft-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  line-height: 1.5;
}

.draft-table thead th {
  background: var(--navy);
  color: #ffffff;
  text-align: left;
  padding: 10px 11px;
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-right: 1px solid rgba(255, 255, 255, 0.16);
}

.draft-table thead th:last-child {
  border-right: none;
}

.draft-table tbody td {
  padding: 11px;
  vertical-align: top;
  border-top: 1px solid var(--border);
  border-right: 1px solid #e7eef4;
  white-space: pre-line;
}

.draft-table tbody td:last-child {
  border-right: none;
}

.draft-table tbody tr:nth-child(even) {
  background: #f9fbfd;
}

.col-sl {
  width: 54px;
  text-align: center;
}

.draft-table tbody td.cell-sl {
  text-align: center;
  font-weight: 700;
  color: var(--navy);
  background: #f2f7fb;
}

.col-draft {
  width: 24%;
}

.col-suggestion {
  width: 36%;
}

.col-justification {
  width: 35%;
}

.draft-table tbody td.cell-draft {
  font-weight: 500;
  color: var(--navy-dark);
}

/* Rationale & Closing */
.rationale-block {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.rationale-block h3 {
  margin-bottom: 10px;
}

.rationale-block p {
  margin: 0 0 11px;
  text-align: justify;
}

.letter-closing {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

.letter-closing p {
  margin: 0 0 8px;
}

.signoff-line {
  font-weight: 600;
  color: var(--navy);
}

.signature-block {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: #ffffff;
  padding: 18px 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.site-footer p {
  margin: 0;
}

.site-footer code {
  color: var(--navy);
  font-weight: 600;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 32, 64, 0.56);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 540px;
  background: #ffffff;
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 18px 48px rgba(7, 32, 64, 0.3);
  animation: modalIn 0.18s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-icon-check {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--teal-soft);
  color: var(--teal-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-icon-check svg {
  width: 20px;
  height: 20px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--navy);
}

.modal-subtitle {
  margin: 3px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.modal-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}

.modal-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.step-item {
  display: flex;
  gap: 12px;
  padding: 11px 12px;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: 9px;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--navy);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.step-item strong {
  display: block;
  font-size: 0.86rem;
  color: var(--navy);
  margin-bottom: 2px;
}

.step-item p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  max-width: 380px;
  background: var(--navy-dark);
  color: #ffffff;
  padding: 12px 16px;
  border-radius: 10px;
  border-left: 4px solid var(--teal);
  box-shadow: 0 10px 28px rgba(7, 32, 64, 0.28);
  font-size: 0.86rem;
  font-weight: 500;
  z-index: 1100;
}

.toast[hidden] {
  display: none;
}

/* Responsive */
@media (max-width: 1020px) {
  .procedure-grid {
    grid-template-columns: 1fr;
  }

  .main-grid {
    grid-template-columns: 1fr;
  }

  .form-column {
    position: static;
  }

  .header-badges {
    align-items: flex-start;
  }

  .mobile-preview-link {
    display: block;
  }
}

@media (max-width: 680px) {
  .container {
    padding: 0 14px;
  }

  .brand-logo {
    width: 58px;
    height: 58px;
  }

  .site-title {
    font-size: 1.15rem;
  }

  .form-card,
  .email-body {
    padding: 16px;
  }

  .preview-topbar,
  .email-headers {
    padding: 14px 16px;
  }

  .field-row {
    grid-template-columns: 1fr 100px;
  }

  .secondary-actions,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .email-header-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  /* Responsive stacked table cards on narrow phones */
  .draft-table thead {
    display: none;
  }

  .draft-table,
  .draft-table tbody,
  .draft-table tr,
  .draft-table td {
    display: block;
    width: 100%;
  }

  .draft-table tbody tr {
    border-bottom: 2px solid var(--border);
    padding: 8px 0;
  }

  .draft-table tbody td {
    border: none;
    padding: 6px 12px;
  }

  .draft-table tbody td.cell-sl {
    text-align: left;
    background: var(--teal-soft);
    color: var(--navy);
    font-size: 0.82rem;
    padding: 7px 12px;
  }

  .draft-table tbody td::before {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--teal-dark);
    margin-bottom: 3px;
  }

  .draft-table tbody td.cell-sl::before {
    content: "Item #";
    display: inline;
    margin-right: 4px;
  }

  .draft-table tbody td.cell-draft::before {
    content: "Current Draft";
  }

  .draft-table tbody td.cell-suggestion::before {
    content: "Suggestion";
  }

  .draft-table tbody td.cell-justification::before {
    content: "Justification";
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: 14px;
    max-width: none;
  }
}
