*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f5;
  --card: #ffffff;
  --primary: #6c3bff;
  --primary-hover: #5a2de0;
  --primary-light: #ede7ff;
  --text: #1a1a1a;
  --text-secondary: #555;
  --muted: #888;
  --border: #e0e0e0;
  --danger: #dc3545;
  --success: #28a745;
  --warning: #ffc107;
  --info: #17a2b8;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,.06), 0 2px 4px rgba(0,0,0,.04);
  --transition: .15s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Focus & accessibility ──────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Nav ─────────────────────────────────────────────────────── */
nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner { max-width: 1100px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.logo { font-weight: 700; font-size: 1.15rem; color: var(--primary); text-decoration: none; white-space: nowrap; }
.nav-links { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: .85rem;
  padding: .35rem .7rem;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
}
.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-links a.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-email { font-size: .8rem; color: var(--muted); padding-right: .5rem; border-right: 1px solid var(--border); margin-right: .25rem; }

/* ── Main ────────────────────────────────────────────────────── */
main { max-width: 1100px; margin: 1.5rem auto; padding: 0 1rem; }

/* ── Flash messages ──────────────────────────────────────────── */
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .5rem;
  animation: flashIn .3s ease;
}
@keyframes flashIn { from { opacity: 0; transform: translateY(-.5rem); } to { opacity: 1; transform: translateY(0); } }
.flash-error { background: #fce4e4; color: #b91c1c; border: 1px solid #f8b4b4; }
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.flash a { color: inherit; font-weight: 600; }
.flash-close {
  background: none; border: none; font-size: 1.1rem; cursor: pointer; color: inherit; opacity: .6;
  padding: 0 .25rem; line-height: 1; flex-shrink: 0;
}
.flash-close:hover { opacity: 1; }

/* ── Auth card ───────────────────────────────────────────────── */
.auth-card { max-width: 420px; margin: 3rem auto; background: var(--card); padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow-md); }
.auth-card h1 { margin-bottom: 1.5rem; font-size: 1.4rem; }
.auth-card label { display: block; margin-bottom: 1rem; font-size: .9rem; font-weight: 500; color: var(--text-secondary); }
.auth-card input {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .75rem;
  border: 1px solid var(--border); border-radius: 6px; font-size: .95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.auth-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,59,255,.12); outline: none; }
.auth-card button {
  width: 100%; padding: .75rem; background: var(--primary); color: #fff; border: none;
  border-radius: 6px; font-size: 1rem; font-weight: 500; cursor: pointer; margin-top: .75rem;
  transition: background var(--transition), transform var(--transition);
}
.auth-card button:hover { background: var(--primary-hover); }
.auth-card button:active { transform: scale(.98); }
.auth-card select {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .75rem;
  border: 1px solid var(--border); border-radius: 6px; font-size: .95rem; background: #fff;
  transition: border-color var(--transition);
}
.auth-card select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,59,255,.12); outline: none; }
.auth-card h2 { font-size: 1.1rem; margin-bottom: .5rem; color: var(--text); }
.auth-switch { margin-top: 1.25rem; text-align: center; font-size: .85rem; color: var(--muted); }
.auth-switch a { color: var(--primary); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-footer { margin-top: 1rem; text-align: center; }
.auth-footer a { color: var(--primary); font-size: .85rem; text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }
.hint { color: var(--text-secondary); font-size: .85rem; margin-bottom: 1rem; line-height: 1.5; }

/* ── Sections ────────────────────────────────────────────────── */
.section {
  background: var(--card);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}
.section h1 { font-size: 1.25rem; margin-bottom: .5rem; }
.section h2 { font-size: 1.1rem; margin-bottom: .75rem; color: var(--text); }

/* ── Buttons ─────────────────────────────────────────────────── */
.actions { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; flex-wrap: wrap; }
.btn-primary {
  padding: .6rem 1.5rem; background: var(--primary); color: #fff; border: none;
  border-radius: 6px; font-size: .9rem; font-weight: 500; cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 2px 8px rgba(108,59,255,.25); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-secondary {
  padding: .6rem 1.5rem; background: var(--card); color: var(--text-secondary); border: 1px solid var(--border);
  border-radius: 6px; font-size: .9rem; font-weight: 500; cursor: pointer; text-decoration: none;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--bg); border-color: #ccc; }
.btn-danger {
  padding: .6rem 1.5rem; background: var(--danger); color: #fff; border: none;
  border-radius: 6px; font-size: .9rem; font-weight: 500; cursor: pointer;
  transition: background var(--transition);
}
.btn-danger:hover { background: #c82333; }

/* Small button variants */
.btn-danger-sm { padding: .3rem .75rem; background: var(--danger); color: #fff; border: none; border-radius: 5px; font-size: .8rem; cursor: pointer; transition: background var(--transition); }
.btn-danger-sm:hover { background: #c82333; }
.btn-primary-sm { padding: .3rem .75rem; background: var(--primary); color: #fff; border: none; border-radius: 5px; font-size: .8rem; cursor: pointer; transition: background var(--transition); }
.btn-primary-sm:hover { background: var(--primary-hover); }
.btn-secondary-sm { padding: .3rem .75rem; background: var(--card); color: var(--text-secondary); border: 1px solid var(--border); border-radius: 5px; font-size: .8rem; cursor: pointer; transition: background var(--transition); }
.btn-secondary-sm:hover { background: var(--bg); }

#status-msg { font-size: .85rem; min-height: 1.2em; }
.status-error { color: var(--danger); }
.status-success { color: var(--success); }

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -.25rem; padding: 0 .25rem; }
.history-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.history-table th { text-align: left; padding: .6rem .75rem; border-bottom: 2px solid var(--border); color: var(--text-secondary); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.history-table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.history-table tbody tr { transition: background var(--transition); }
.history-table tbody tr:hover { background: #fafafa; }
.contact-table { margin-top: 1.25rem; }
.error-cell { color: var(--danger); font-size: .8rem; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: help; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 12px; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.badge-pending { background: #e9ecef; color: #495057; }
.badge-running { background: #cce5ff; color: #004085; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-failed { background: #fce4e4; color: #b91c1c; }
.badge-registered { background: #d1fae5; color: #065f46; }
.badge-existing { background: #fef3c7; color: #92400e; }
.badge-skipped { background: #e9ecef; color: #495057; }
.badge-paused { background: #fef3c7; color: #92400e; }
.badge-forbidden { background: #fce4e4; color: #b91c1c; }
.badge-importing { background: #e0e7ff; color: #3730a3; }

/* ── Job detail ──────────────────────────────────────────────── */
.job-header { display: flex; align-items: center; gap: .75rem; margin-bottom: .5rem; flex-wrap: wrap; }
.job-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
  text-align: center;
  background: var(--bg);
  padding: .75rem .5rem;
  border-radius: 6px;
}
.stat-value { display: block; font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .7rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; margin-top: .15rem; display: block; }

/* ── Progress bar ────────────────────────────────────────────── */
.progress-bar { height: 10px; background: var(--border); border-radius: 5px; overflow: hidden; margin-bottom: 1.25rem; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #8b5cf6); transition: width .4s ease; border-radius: 5px; }

/* ── Admin ────────────────────────────────────────────────────── */
.invite-form { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.invite-form label { flex: 1; min-width: 200px; }
.invite-form input { width: 100%; }
.invite-link-input { font-size: .8rem; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 5px; width: 100%; min-width: 180px; background: var(--bg); cursor: pointer; font-family: monospace; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-size: .9rem; white-space: nowrap; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--primary); }
.user-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

/* ── Divider ─────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Settings ────────────────────────────────────────────────── */
.settings-wide { max-width: 560px; }
.schedule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.schedule-block { background: var(--bg); padding: 1rem; border-radius: 6px; }
.schedule-block h3 { font-size: .9rem; margin-bottom: .75rem; font-weight: 600; }
.schedule-block select, .schedule-block input { width: 100%; }
.delay-range { display: flex; align-items: flex-end; gap: .5rem; margin-top: .5rem; }
.delay-range label { flex: 1; }
.delay-dash { font-size: 1.2rem; color: var(--muted); padding-bottom: .5rem; }

/* ── CSV upload ──────────────────────────────────────────────── */
.csv-bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.csv-upload-group { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.csv-file-label { cursor: pointer; }
.csv-filename { font-size: .85rem; color: var(--text-secondary); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Column guide ────────────────────────────────────────────── */
.column-guide { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; font-size: .85rem; color: var(--text-secondary); }
.col-tag { display: inline-block; padding: .2rem .5rem; border-radius: 4px; background: #e9ecef; color: #495057; font-size: .78rem; }
.col-required { background: var(--primary-light); color: var(--primary); font-weight: 600; }

/* ── Form rows ───────────────────────────────────────────────── */
.form-row { display: flex; gap: 1rem; margin-bottom: .75rem; }
.form-field { flex: 1; display: block; font-size: .9rem; font-weight: 500; color: var(--text-secondary); }
.form-field span { display: block; margin-bottom: .3rem; }
.form-field input {
  display: block; width: 100%; padding: .55rem .75rem;
  border: 1px solid var(--border); border-radius: 6px; font-size: .9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,59,255,.12); outline: none; }
.form-field small { font-weight: 400; color: var(--muted); }

/* ── Duplicate warnings ──────────────────────────────────────── */
.dupe-warnings {
  background: #fef3c7; border: 1px solid #fbbf24; border-radius: var(--radius);
  padding: .75rem 1rem; margin-top: .75rem; font-size: .85rem; color: #92400e;
}
.dupe-warnings p { margin-bottom: .4rem; }
.dupe-warnings p:last-child { margin-bottom: 0; }

/* ── Job tags display ────────────────────────────────────────── */
.job-tags-display { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* ── Blocklist ───────────────────────────────────────────────── */
.blocklist-form { display: flex; align-items: flex-end; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.blocklist-form select {
  display: block; width: 100%; padding: .55rem .75rem;
  border: 1px solid var(--border); border-radius: 6px; font-size: .9rem; background: #fff; margin-top: .3rem;
  transition: border-color var(--transition);
}
.blocklist-form select:focus { border-color: var(--primary); outline: none; }
.blocklist-value-field { flex: 2; min-width: 180px; }
.blocklist-form .btn-primary { white-space: nowrap; align-self: flex-end; }
.blocklist-hint-examples { font-size: .85rem; margin-bottom: .75rem; color: var(--text-secondary); }
.blocklist-hint-examples code { background: var(--bg); padding: .15rem .4rem; border-radius: 3px; font-size: .8rem; }

/* ── Handsontable overrides ──────────────────────────────────── */
#spreadsheet { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty-state p { font-size: .95rem; }

/* ── Loading spinner ─────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: spin .6s linear infinite;
  vertical-align: middle; margin-right: .4rem;
}
.spinner-dark { border-color: rgba(0,0,0,.15); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  main { padding: 0 .75rem; margin: 1rem auto; }
  .section { padding: 1rem; }

  nav { padding: .6rem 1rem; }
  .nav-inner { flex-wrap: wrap; }
  .nav-email { display: none; }
  .nav-links { gap: .15rem; }
  .nav-links a { font-size: .8rem; padding: .3rem .5rem; }

  .auth-card { margin: 1.5rem auto; padding: 1.5rem; max-width: 100%; }
  .settings-wide { max-width: 100%; }

  .schedule-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; gap: .5rem; }
  .csv-bar { flex-direction: column; align-items: stretch; }
  .csv-upload-group { flex-wrap: wrap; }

  .invite-form { flex-direction: column; }
  .invite-form label { min-width: auto; }
  .blocklist-form { flex-direction: column; }
  .blocklist-value-field { min-width: auto; }

  .job-stats { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .stat { padding: .5rem .25rem; }
  .stat-value { font-size: 1.2rem; }

  .history-table { font-size: .82rem; }
  .history-table th, .history-table td { padding: .45rem .5rem; }
  .error-cell { max-width: 150px; }

  .actions { flex-wrap: wrap; gap: .5rem; }
  .user-actions { gap: .3rem; }

  .column-guide { display: none; }
}

@media (max-width: 480px) {
  .job-stats { grid-template-columns: repeat(2, 1fr); }
  .nav-links a { font-size: .75rem; padding: .25rem .4rem; }
}
