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

:root {
  --bg: #09090b;
  --bg-card: #0c0c0e;
  --bg-hover: #18181b;
  --bg-muted: #27272a;
  --border: #27272a;
  --border-dim: #1e1e21;
  --ring: #3b82f6;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-dim: #52525b;
  --accent: #3b82f6;
  --accent-fg: #fff;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --purple: #a78bfa;
  --radius: 8px;
  --nav-height: 56px;
}

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

/* Nav */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  z-index: 100;
}

.nav-logo { font-size: 1rem; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.nav-links { display: flex; gap: 0.125rem; margin-left: 2rem; }

.nav-link {
  padding: 0.375rem 0.75rem;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
  cursor: pointer;
}
.nav-link:hover { color: var(--text); background: var(--bg-hover); }
.nav-link.active { color: var(--text); background: var(--bg-muted); }

.nav-right { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.nav-email { font-size: 0.8125rem; color: var(--text-muted); }

/* Buttons — shadcn style */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.25;
}
.btn:hover { background: var(--bg-muted); }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-primary:hover { background: #2563eb; }
.btn-sm { padding: 0.3125rem 0.625rem; font-size: 0.75rem; height: 28px; }
.btn-ghost { border: none; }
.btn-ghost:hover { background: var(--bg-muted); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: rgba(239,68,68,0.1); }

/* Content */
.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(var(--nav-height) + 1.5rem) 1.5rem 2rem;
}

.page-title { font-size: 1.25rem; font-weight: 600; color: var(--text); margin-bottom: 1rem; letter-spacing: -0.01em; }

/* Card / Table wrapper — shadcn card */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }

th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border-dim);
  color: var(--text);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

/* Badges — shadcn */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  border: 1px solid transparent;
  letter-spacing: 0.01em;
}

.badge-feedback { background: rgba(59,130,246,0.1); color: #60a5fa; border-color: rgba(59,130,246,0.2); }
.badge-sync { background: rgba(34,197,94,0.1); color: #4ade80; border-color: rgba(34,197,94,0.2); }
.badge-chat { background: rgba(167,139,250,0.1); color: var(--purple); border-color: rgba(167,139,250,0.2); }
.badge-started { background: rgba(234,179,8,0.1); color: #facc15; border-color: rgba(234,179,8,0.2); }
.badge-completed { background: rgba(34,197,94,0.1); color: #4ade80; border-color: rgba(34,197,94,0.2); }
.badge-failed { background: rgba(239,68,68,0.1); color: #f87171; border-color: rgba(239,68,68,0.2); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

select {
  padding: 0.4375rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8125rem;
  outline: none;
  height: 36px;
}
select:focus { border-color: var(--ring); box-shadow: 0 0 0 2px rgba(59,130,246,0.2); }

/* Switch — shadcn style */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}

.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--bg-muted);
  border: 2px solid var(--border);
  border-radius: 9999px;
  transition: background 0.15s, border-color 0.15s;
}

.switch-thumb {
  position: absolute;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background: var(--text-muted);
  border-radius: 9999px;
  transition: transform 0.15s, background 0.15s;
}

.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateY(-50%) translateX(16px); background: #fff; }

.switch-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Operations row — clickable with expand chevron */
.op-row {
  cursor: pointer;
  transition: background 0.1s;
}
.op-row:hover td { background: var(--bg-hover); }

.op-expand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--text-dim);
  transition: transform 0.15s, color 0.15s;
  flex-shrink: 0;
}
.op-expand.open { transform: rotate(90deg); color: var(--text-muted); }

.op-expand svg { width: 14px; height: 14px; }

/* Detail row */
.detail-content {
  padding: 1rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  margin: 0.25rem 0.5rem 0.5rem;
  font-size: 0.8125rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 500px;
  overflow-y: auto;
  line-height: 1.6;
}

.detail-section {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
}
.detail-section:first-child { margin-top: 0; }

/* Routine config column */
.routine-config {
  max-width: 240px;
  line-height: 1.6;
  font-size: 0.8125rem;
}

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

/* Loading */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Login page — shadcn card */
.login-card {
  max-width: 360px;
  margin: 120px auto 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.login-card h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
  text-align: center;
  letter-spacing: -0.01em;
}

.login-subtitle {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

/* Form — shadcn */
.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.form-input,
.form-select,
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8125rem;
  outline: none;
  font-family: inherit;
  height: 36px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group textarea { height: auto; min-height: 60px; resize: vertical; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.2);
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.email-input-wrap { display: flex; align-items: stretch; }
.email-input-wrap input { border-radius: 6px 0 0 6px; border-right: none; }

.email-suffix {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 0 6px 6px 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.login-error {
  color: var(--red);
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
  display: none;
}

.login-card .btn { width: 100%; justify-content: center; padding: 0.5rem; height: 36px; }

/* Modal — shadcn dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
  letter-spacing: -0.01em;
}

.modal-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Schedule presets — shadcn toggle group */
.schedule-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.schedule-preset {
  padding: 0.3125rem 0.625rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.schedule-preset:hover { background: var(--bg-muted); color: var(--text); }
.schedule-preset.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

/* Recipients table — shadcn style list */
.recipients-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  max-height: 200px;
  overflow-y: auto;
}

.recipient-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--accent);
}

.recipient-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.4375rem 0.75rem;
  border-bottom: 1px solid var(--border-dim);
  font-size: 0.8125rem;
  transition: background 0.1s;
}
.recipient-item:last-child { border-bottom: none; }
.recipient-item:hover { background: var(--bg-hover); }

.recipient-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.recipient-name { color: var(--text); flex: 1; }
.recipient-email { color: var(--text-dim); font-size: 0.75rem; }

/* Responsive */
@media (max-width: 768px) {
  .content { padding-left: 1rem; padding-right: 1rem; }
  .nav { padding: 0 1rem; }
  .nav-links { margin-left: 1rem; }
}
