:root {
  --navy: #0B1F33;
  --navy-light: #1c3a57;
  --bg: #F7F9FC;
  --surface: #FFFFFF;
  --border: #E3E7EE;
  --text: #172336;
  --text-muted: #667085;
  --success-bg: #E6F6EE;
  --success-text: #0F7A47;
  --warning-bg: #FFF6E5;
  --warning-text: #9A6700;
  --info-bg: #E8F0FE;
  --info-text: #1D4ED8;
  --radius: 10px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }

.topbar {
  background: var(--navy);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 40px;
}
.brand { color: #fff; font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.nav { display: flex; gap: 4px; }
.nav-link {
  color: rgba(255,255,255,0.7);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,0.08); }
.nav-link.active { color: #fff; background: rgba(255,255,255,0.14); }

.app { max-width: 1200px; margin: 0 auto; padding: 40px 32px 80px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 32px;
}
.page-header h1 { font-size: 24px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.01em; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 14px; max-width: 520px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: #F0F3F8; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-light); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #F0F3F8; }
.btn-danger { color: #B42318; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 26px; font-weight: 600; margin-top: 6px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}

input[type=text], input[type=email], input[type=tel], select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
input[type=file] { font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-pad { padding: 24px 28px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-muted); font-weight: 500; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; background: #FAFBFD; }
tr:last-child td { border-bottom: none; }
tr.company-row td {
  background: #F3F5F9;
  font-weight: 600;
  color: var(--navy);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 8px 16px;
}
tr.company-row { cursor: pointer; }
tr.company-row:hover td { background: #EBEFF5; }
tr.contact-row:hover { background: #FAFBFD; cursor: pointer; }
tr.unsubscribed td { color: var(--text-muted); }
tr.unsubscribed .primary { text-decoration: line-through; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }
.badge-info { background: var(--info-bg); color: var(--info-text); }
.badge-navy { background: var(--navy); color: #fff; }
.badge-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,31,51,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 480px;
  padding: 28px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin: 0 0 20px; font-size: 18px; font-weight: 600; }
.modal-wide { max-width: 560px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.field input, .field select { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

.company-contact-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  max-height: 260px;
  overflow-y: auto;
}
.company-contact-row {
  display: grid;
  grid-template-columns: 1.2fr 1.4fr 1fr;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}
.company-contact-row:last-child { border-bottom: none; }
.company-contact-row:hover { background: #FAFBFD; }

.reply-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.reply-row:last-child { border-bottom: none; }

.import-drop {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  background: var(--surface);
}

.sheet-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
}
.sheet-block-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.sheet-block-header .sheet-name { font-weight: 600; font-size: 15px; }
.sheet-block-body { padding: 20px; display: none; }
.sheet-block.open .sheet-block-body { display: block; }
.mapping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.mapping-grid .field label { font-size: 12.5px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }

.toast-root { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  animation: fadein .15s ease-out;
}
.toast.error { background: #B42318; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.small { font-size: 12.5px; }
