:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e1e7ed;
  --text: #1a202c;
  --muted: #64748b;
  --primary: #00a04a;
  --primary-dark: #007a38;
  --primary-light: #e6f7ef;
  --success: #00a04a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar-bg: #152032;
  --sidebar-w: 230px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #152032 0%, #1a2d44 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}

.logo {
  padding: 22px 18px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.logo-text {
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.logo-sub {
  font-size: 10px;
  color: #64a882;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

nav { flex: 1; padding: 10px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  color: #94a3b8;
  text-decoration: none;
  transition: all 0.15s;
  font-size: 13.5px;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }

.nav-item.active {
  background: rgba(0,160,74,0.15);
  color: #4ade80;
  border-left-color: var(--primary);
}

.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-status {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #64748b;
}

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.online { background: var(--primary); box-shadow: 0 0 6px rgba(0,160,74,0.6); }
.dot.offline { background: var(--danger); }

/* ── Main content ── */
.content { flex: 1; overflow-y: auto; padding: 28px 32px; }
.view { display: none; }
.view.active { display: block; }

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ── Stats strip ── */
.stats-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-value.warn { color: var(--warning); }
.stat-value.success { color: var(--primary); }

/* ── Draft toggle ── */
.toggle-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.toggle-label { font-size: 15px; font-weight: 600; }
.toggle-desc { font-size: 13px; color: var(--muted); margin-top: 3px; }
.toggle-switch { position: relative; width: 52px; height: 28px; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track { position: absolute; inset: 0; background: #cbd5e1; border-radius: 28px; transition: background 0.2s; }
.toggle-track::after { content: ''; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle-switch input:checked + .toggle-track { background: var(--primary); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(24px); }

/* ── Activity feed ── */
.activity-feed {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.feed-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #f8fafb;
}

.feed-item {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.1s;
}

.feed-item:last-child { border-bottom: none; }
.feed-item:hover { background: var(--primary-light); }
.feed-meta { flex: 1; min-width: 0; }
.feed-subject { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-from { font-size: 12px; color: var(--muted); margin-top: 2px; }
.feed-right { text-align: right; flex-shrink: 0; }
.feed-time { font-size: 12px; color: var(--muted); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-draft { background: #ede9fe; color: #6d28d9; }
.badge-loc { background: var(--primary-light); color: var(--primary-dark); font-size: 10px; }

/* ── Table ── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

table { width: 100%; border-collapse: collapse; }

th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: #f8fafb;
  font-weight: 600;
}

td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--primary-light); cursor: pointer; }

/* ── Confidence bar ── */
.conf-bar { height: 4px; background: #e2e8f0; border-radius: 2px; width: 60px; display: inline-block; vertical-align: middle; }
.conf-fill { height: 100%; border-radius: 2px; }

/* ── Pagination ── */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
  padding-bottom: 4px;
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.12s;
  min-width: 36px;
  text-align: center;
}

.page-btn:hover:not(.active):not(.disabled) { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.page-btn.disabled { opacity: 0.4; cursor: not-allowed; }
.page-ellipsis { padding: 6px 4px; color: var(--muted); font-size: 13px; }

/* ── Forms & buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f1f5f9; }

.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,160,74,0.12); }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 13px; }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone p { color: var(--muted); margin-top: 8px; font-size: 13px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.card-title { font-weight: 700; margin-bottom: 14px; font-size: 14px; color: var(--text); }

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

#modal-overlay.hidden { display: none; }

#modal-box {
  background: var(--surface);
  border-radius: 14px;
  padding: 28px;
  width: 580px;
  max-width: 95vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 18px; }
.modal-actions { margin-top: 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* ── Email detail ── */
.email-body-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

.detail-row { display: flex; gap: 12px; margin-bottom: 8px; font-size: 13px; }
.detail-label { font-weight: 600; min-width: 80px; color: var(--muted); }

/* ── Checklist ── */
.checklist { display: flex; flex-wrap: wrap; gap: 8px; }
.check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s, background 0.12s;
}
.check-item:hover { border-color: var(--primary); background: var(--primary-light); }
.check-item input[type=checkbox] { accent-color: var(--primary); }

/* ── Alert ── */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.alert-warn { background: #fef9c3; color: #854d0e; border: 1px solid #fde68a; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
tr.row-unsure { background: #fffbeb; }
tr.row-unsure:hover { background: #fef3c7; }

/* ── Category bar chart ── */
.cat-bar { margin-bottom: 10px; }
.cat-bar-label { font-size: 12px; color: var(--muted); margin-bottom: 3px; display: flex; justify-content: space-between; font-weight: 500; }
.cat-bar-track { height: 8px; background: #e2e8f0; border-radius: 4px; }
.cat-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.5s ease; }

/* ── Filter row ── */
.filter-row { display: flex; gap: 10px; margin-bottom: 18px; align-items: center; flex-wrap: wrap; }
.select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  font-size: 13px;
}
.select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,160,74,0.12); }

/* ── Loading ── */
.loading { text-align: center; padding: 48px; color: var(--muted); }
.spinner {
  display: inline-block;
  width: 26px;
  height: 26px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 2000;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  max-width: 360px;
}
#toast.show { transform: none; opacity: 1; }

/* ── Sync progress ── */
.sync-live-card {
  background: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.sync-live-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--primary-dark);
}
.progress-track {
  height: 10px;
  background: rgba(0,0,0,0.08);
  border-radius: 5px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 5px;
  transition: width 0.4s ease;
}
.spinner-sm {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(0,160,74,0.3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}

/* ── Utilities ── */
.mt16 { margin-top: 16px; }
.mt8 { margin-top: 8px; }
.flex-gap { display: flex; gap: 10px; align-items: center; }
.text-muted { color: var(--muted); font-size: 12px; }
