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

:root {
  --blue:      #2563eb;
  --blue-dk:   #1d4ed8;
  --blue-lt:   #eff6ff;
  --green:     #16a34a;
  --red:       #dc2626;
  --gray-50:   #f9fafb;
  --gray-100:  #f3f4f6;
  --gray-200:  #e5e7eb;
  --gray-300:  #d1d5db;
  --gray-400:  #9ca3af;
  --gray-500:  #6b7280;
  --gray-700:  #374151;
  --gray-900:  #111827;
  --sidebar-w: 230px;
  --radius:    8px;
  --shadow:    0 1px 6px rgba(0,0,0,.08);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--gray-900);
  background: var(--gray-50);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }

/* ── Login screen ─────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1e3a5f 0%, #2563eb 100%);
}

.login-box {
  background: #fff;
  border-radius: 16px;
  padding: 48px 40px;
  width: 360px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
}

.login-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--gray-400);
  margin-bottom: 6px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--gray-900);
}

.login-sub {
  font-size: 15px;
  color: var(--gray-500);
  margin-bottom: 32px;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 20px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-700);
  transition: border-color .15s, box-shadow .15s;
}

.btn-google:hover {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.login-error {
  margin-top: 16px;
  font-size: 14px;
  color: var(--red);
  min-height: 20px;
}

/* ── App shell ────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--gray-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-logo {
  font-size: 24px;
  line-height: 1;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  opacity: .6;
}

.sidebar-missionary {
  font-size: 15px;
  font-weight: 600;
  margin-top: 2px;
}

.nav-list {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: rgba(255,255,255,.7);
  border-radius: 6px;
  margin: 2px 8px;
  font-size: 15px;
  transition: background .12s, color .12s;
  text-decoration: none;
  position: relative;
}

.nav-item:hover        { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-item.active       { background: var(--blue); color: #fff; }

.nav-icon { font-size: 16px; opacity: .8; }

.nav-badge {
  margin-left: auto;
  background: #ef4444;
  color: #fff;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 12px;
  color: rgba(255,255,255,.4);
}

#account-email-display { display: block; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-logout {
  background: none;
  border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.5);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  transition: border-color .15s, color .15s;
}

.btn-logout:hover { border-color: rgba(255,255,255,.5); color: #fff; }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 36px 40px;
  max-width: 960px;
}

.page        { display: none; }
.page.active { display: block; }

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--gray-900);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header .page-title { margin-bottom: 0; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s;
}
.btn-primary:hover { background: var(--blue-dk); }

.btn-secondary {
  background: #fff;
  color: var(--gray-700);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  transition: border-color .15s;
}
.btn-secondary:hover { border-color: var(--gray-400); }

.btn-send { background: var(--green); }
.btn-send:hover { background: #15803d; }

.btn-back {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 14px;
  padding: 0;
}

.btn-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--gray-400);
  line-height: 1;
  padding: 4px;
}

/* ── Stats ────────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--blue);
  line-height: 1;
}

.stat-label {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 6px;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--gray-700);
}

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

.btn-action {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  background: var(--blue);
  color: #fff;
  border: none;
  transition: background .15s;
}

.btn-action:hover             { background: var(--blue-dk); }
.btn-action.secondary         { background: #fff; color: var(--gray-700); border: 1.5px solid var(--gray-200); }
.btn-action.secondary:hover   { border-color: var(--gray-400); }

/* ── Tab bar ──────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--gray-200);
  padding-bottom: -2px;
}

.tab {
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}

.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab:hover  { color: var(--gray-700); }

/* ── Item list ────────────────────────────────────────────────────────────── */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.item-row:hover { border-color: var(--gray-300); }

.item-title   { font-size: 15px; font-weight: 600; color: var(--gray-900); }
.item-meta    { font-size: 13px; color: var(--gray-500); margin-top: 2px; }
.item-actions { display: flex; gap: 8px; flex-shrink: 0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: system-ui, sans-serif;
}

.badge-pending { background: #fef3c7; color: #92400e; }
.badge-sent    { background: #d1fae5; color: #065f46; }
.badge-draft   { background: var(--gray-100); color: var(--gray-500); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  font-size: 15px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s;
  background: #fff;
  color: var(--gray-900);
  font-family: inherit;
}

.form-control:focus { border-color: var(--blue); }

textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-hint {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 5px;
}

/* ── Letter editor ────────────────────────────────────────────────────────── */
.editor-wrap {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
}

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

.editor-toolbar {
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--gray-50);
  border: 1.5px solid var(--gray-300);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.editor-toolbar button {
  padding: 4px 10px;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 14px;
  color: var(--gray-700);
  transition: background .1s;
}

.editor-toolbar button:hover { background: var(--gray-200); }

.editor-body {
  min-height: 360px;
  padding: 16px;
  border: 1.5px solid var(--gray-300);
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 16px;
  font-family: Georgia, serif;
  line-height: 1.8;
  outline: none;
  color: var(--gray-900);
}

.editor-body:focus { border-color: var(--blue); }
.editor-body:empty:before { content: attr(placeholder); color: var(--gray-400); }

.editor-status {
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
  color: var(--green);
}

.editor-status.error { color: var(--red); }

/* ── Attachments ──────────────────────────────────────────────────────────── */
.attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gray-100);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--gray-700);
}

.attachment-chip button {
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}

.btn-upload {
  display: inline-block;
  padding: 7px 14px;
  border: 1.5px dashed var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--gray-500);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.btn-upload:hover { border-color: var(--blue); color: var(--blue); }

/* ── Search bar ───────────────────────────────────────────────────────────── */
.search-bar { margin-bottom: 16px; }
.search-bar .form-control { max-width: 400px; }

/* ── Bulk import panel ────────────────────────────────────────────────────── */
.import-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.import-panel-inner {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.import-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.import-header h2 { font-size: 20px; }

.import-hint {
  font-size: 14px;
  color: var(--gray-500);
  margin-bottom: 16px;
  line-height: 1.6;
}

.import-textarea {
  width: 100%;
  min-height: 160px;
  padding: 12px;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  resize: vertical;
  margin-bottom: 16px;
  outline: none;
}

.import-textarea:focus { border-color: var(--blue); }

.import-actions { display: flex; gap: 10px; margin-bottom: 20px; }

.import-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.import-preview th {
  text-align: left;
  padding: 8px 10px;
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
  color: var(--gray-700);
  font-weight: 600;
}

.import-preview td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

.import-preview .status-new       { color: var(--green); font-weight: 600; }
.import-preview .status-duplicate { color: var(--gray-400); }
.import-preview .status-invalid   { color: var(--red); }

.import-summary {
  font-size: 14px;
  padding: 12px 16px;
  background: var(--gray-50);
  border-radius: var(--radius);
  margin-bottom: 16px;
  color: var(--gray-700);
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ── Loading / empty ──────────────────────────────────────────────────────── */
.loading-row {
  text-align: center;
  padding: 48px;
  color: var(--gray-400);
  font-size: 15px;
}

.empty-row {
  text-align: center;
  padding: 48px;
  color: var(--gray-400);
  font-size: 15px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar       { width: 100%; height: auto; position: relative; }
  .main-content  { margin-left: 0; padding: 24px 16px; }
  .app-shell     { flex-direction: column; }
  .stat-grid     { grid-template-columns: 1fr 1fr; }
  .form-row      { grid-template-columns: 1fr; }
}
