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

:root {
  --brand:       #1a56db;
  --brand-dark:  #1e429f;
  --brand-light: #ebf5ff;
  --green:       #057a55;
  --green-light: #def7ec;
  --gray-50:     #f9fafb;
  --gray-100:    #f3f4f6;
  --gray-200:    #e5e7eb;
  --gray-400:    #9ca3af;
  --gray-500:    #6b7280;
  --gray-700:    #374151;
  --gray-900:    #111827;
  --red:         #e02424;
  --red-light:   #fde8e8;
  --radius:      10px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--gray-900);
  background: var(--gray-50);
  min-height: 100vh;
}

/* ── Auth page ────────────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a56db 0%, #1e429f 100%);
}

.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 40px rgba(0,0,0,.18);
}

.brand { text-align: center; margin-bottom: 2rem; }
.brand h1 { font-size: 1.4rem; font-weight: 700; color: var(--gray-900); }
.brand p  { font-size: .9rem; color: var(--gray-500); margin-top: .25rem; }

/* ── Header ───────────────────────────────────────────────────────────── */
.header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: .875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-brand  { display: flex; align-items: center; gap: .75rem; }
.header-logo   {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--brand); color: #fff;
  font-weight: 700; font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
}
.header-logo-img { max-height: 36px; max-width: 120px; object-fit: contain; }
.header-title  { font-weight: 600; font-size: 1rem; color: var(--gray-900); }
.header-sub    { font-weight: 400; color: var(--gray-500); }

/* ── Main layout ──────────────────────────────────────────────────────── */
.main {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Steps indicator ──────────────────────────────────────────────────── */
.steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: .5rem;
}
.step {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  font-weight: 500;
  color: var(--gray-400);
  white-space: nowrap;
}
.step.active { color: var(--brand); }
.step.done   { color: var(--green); }
.step-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--gray-200); color: var(--gray-500);
  font-size: .75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.step.active .step-num { background: var(--brand); color: #fff; }
.step.done   .step-num { background: var(--green); color: #fff; }
.step-divider {
  flex: 1; height: 1px;
  background: var(--gray-200);
  margin: 0 .5rem;
  min-width: 20px;
}

/* ── Card ─────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}
.card-title { font-size: 1.05rem; font-weight: 600; color: var(--gray-900); }
.card-title-row {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: .25rem;
}
.card-subtitle {
  font-size: .875rem; color: var(--gray-500);
  margin-bottom: 1rem;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; font-size: .875rem;
  font-weight: 500; color: var(--gray-700);
  margin-bottom: .375rem;
}
input[type="text"],
input[type="password"],
input[type="email"] {
  width: 100%; padding: .625rem .875rem;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: .9rem; color: var(--gray-900);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}

.search-row {
  display: flex; gap: .75rem;
  margin-top: 1rem;
}
.search-row input { flex: 1; }

textarea {
  width: 100%; padding: .625rem .875rem;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: .9rem; color: var(--gray-900);
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}

.manual-form { margin-top: 1rem; }
.required { color: var(--red); margin-left: 2px; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .6rem 1.25rem;
  border: none; border-radius: 8px;
  font-size: .9rem; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary  { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-ghost    { background: transparent; color: var(--gray-500); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-700); }
.btn-sm  { padding: .35rem .8rem; font-size: .8rem; }
.btn-lg  { padding: .8rem 2rem; font-size: 1rem; }
.btn-full { width: 100%; }

/* ── Result lists ─────────────────────────────────────────────────────── */
.result-list { margin-top: 1rem; display: flex; flex-direction: column; gap: .5rem; }

.result-item {
  padding: .875rem 1rem;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.result-item:hover {
  border-color: var(--brand);
  background: var(--brand-light);
}
.result-primary {
  font-weight: 500; color: var(--gray-900);
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
}
.result-secondary {
  font-size: .8rem; color: var(--gray-500);
  margin-top: .2rem;
}

/* ── Tags & badges ────────────────────────────────────────────────────── */
.tag {
  font-size: .75rem; font-weight: 600;
  background: var(--gray-100); color: var(--gray-700);
  padding: .15rem .5rem; border-radius: 5px;
}
.status-badge {
  font-size: .72rem; font-weight: 600;
  padding: .15rem .55rem; border-radius: 20px;
  background: var(--gray-100); color: var(--gray-700);
}
.status-badge.status-completed  { background: var(--green-light); color: var(--green); }
.status-badge.status-unscheduled { background: #fef3c7; color: #92400e; }
.status-badge.status-pending    { background: #fef3c7; color: #92400e; }
.status-badge.status-in-progress { background: #e0f2fe; color: #0369a1; }
.status-badge.status-cancelled  { background: var(--red-light); color: var(--red); }

.badge {
  display: inline-block;
  font-size: .8rem; font-weight: 500;
  padding: .3rem .75rem; border-radius: 20px;
}
.badge-green { background: var(--green-light); color: var(--green); }
.badge-gray  { background: var(--gray-100);    color: var(--gray-500); }

/* ── Template grid ────────────────────────────────────────────────────── */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}
.template-card {
  padding: 1rem;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.template-card:hover { border-color: var(--brand); background: var(--brand-light); }
.template-card.manual { opacity: .8; }
.template-name  { font-weight: 600; font-size: .9rem; margin-bottom: .5rem; }
.template-badge { font-size: .75rem; color: var(--gray-500); }
.template-note  {
  font-size: .72rem; color: var(--gray-400);
  margin-top: .5rem; line-height: 1.4;
}

/* ── Preview ──────────────────────────────────────────────────────────── */
.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem 1.5rem;
  margin: 1rem 0 1.25rem;
}
.preview-field {}
.preview-label { font-size: .75rem; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: .05em; }
.preview-value { font-size: .95rem; color: var(--gray-900); margin-top: .15rem; }

.autofill-badge { margin-bottom: 1.5rem; }

.send-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--gray-100);
}
.checkbox-label {
  display: flex; align-items: center; gap: .5rem;
  font-size: .875rem; cursor: pointer;
}
.muted { color: var(--gray-400); font-size: .8rem; }

/* ── Success ──────────────────────────────────────────────────────────── */
.success-body {
  text-align: center;
  padding: 2rem 1rem;
}
.success-icon {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--green-light); color: var(--green);
  font-size: 1.75rem;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.25rem;
}
.success-body h2 { font-size: 1.3rem; margin-bottom: .5rem; }
.success-body p  { color: var(--gray-500); margin-bottom: 1rem; }
.sign-url {
  font-size: .8rem; color: var(--brand);
  word-break: break-all;
  display: block; margin-top: .25rem;
}

/* ── Utility ──────────────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.loading  { color: var(--gray-400); font-size: .875rem; padding: .75rem 0; }
.empty    { color: var(--gray-400); font-size: .875rem; padding: .5rem 0; }
.error    { color: var(--red); font-size: .875rem; padding: .5rem 0; }

.alert { padding: .75rem 1rem; border-radius: 8px; font-size: .875rem; margin-bottom: 1rem; }
.alert-error { background: var(--red-light); color: var(--red); }

@media (max-width: 540px) {
  .preview-grid { grid-template-columns: 1fr; }
  .template-grid { grid-template-columns: 1fr; }
  .send-controls { flex-direction: column; align-items: flex-start; }
  .btn-lg { width: 100%; }
}
