* { box-sizing: border-box; }

/* Dark theme (default) */
:root, [data-theme="dark"] {
  --bg: #0c0c0f;
  --surface: #16161a;
  --surface-hover: #1c1c21;
  --border: #2a2a30;
  --border-focus: #6366f1;
  --muted: #71717a;
  --text: #e4e4e7;
  --text-strong: #fafafa;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-muted: rgba(99, 102, 241, 0.15);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-muted: rgba(220, 38, 38, 0.12);
  --success: #16a34a;
  --success-muted: rgba(22, 163, 74, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

/* Light theme */
[data-theme="light"] {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-hover: #fafafa;
  --border: #e4e4e7;
  --border-focus: #6366f1;
  --muted: #71717a;
  --text: #18181b;
  --text-strong: #09090b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-muted: rgba(99, 102, 241, 0.1);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-muted: rgba(220, 38, 38, 0.08);
  --success: #16a34a;
  --success-muted: rgba(22, 163, 74, 0.12);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

body {
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  padding-bottom: calc(64px + var(--safe-bottom));
  transition: background 0.2s, color 0.2s;
}
a { color: var(--primary); text-decoration: none; -webkit-tap-highlight-color: transparent; }
a:hover { text-decoration: underline; }
a:active { opacity: 0.9; }

.layout { min-height: 100vh; min-height: 100dvh; }
.main {
  padding: max(1rem, var(--safe-top)) 1rem 1.5rem;
  max-width: 520px;
  margin: 0 auto;
}
h1 { font-size: 1.5rem; margin: 0 0 1rem; font-weight: 600; color: var(--text-strong); }
h2 { font-size: 0.8125rem; margin: 0 0 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: max(0.75rem, var(--safe-top));
  right: 1rem;
  z-index: 101;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle svg { width: 20px; height: 20px; }

/* Bottom nav (mobile) */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.5rem;
  padding-bottom: max(0.5rem, var(--safe-bottom));
  z-index: 100;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
}
.nav a {
  flex: 1;
  text-align: center;
  padding: 0.65rem 0.5rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, background 0.2s;
}
.nav a:hover { color: var(--text); background: var(--surface-hover); }
.nav a.active { color: var(--primary); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.25rem; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; min-width: 280px; }
th, td { text-align: left; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--surface-hover); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.25rem;
  min-height: 44px;
  min-width: 44px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover, .btn--primary:active { background: var(--primary-hover); }
.btn--secondary { background: var(--border); color: var(--text); }
.btn--secondary:hover { background: var(--surface-hover); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: var(--danger-hover); }
.btn--ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn--small { padding: 0.4rem 0.75rem; min-height: 36px; min-width: 36px; font-size: 0.8125rem; }
.btn + .btn { margin-left: 0.5rem; margin-top: 0.25rem; }

.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge--draft { background: var(--border); color: var(--muted); }
.badge--queued { background: var(--primary-muted); color: var(--primary); }
.badge--sending { background: var(--success-muted); color: var(--success); }
.badge--paused { background: #fef3c7; color: #b45309; }
[data-theme="dark"] .badge--paused { background: #78350f; color: #fcd34d; }
.badge--stopped { background: var(--danger-muted); color: var(--danger); }
.badge--done { background: var(--primary-muted); color: var(--primary); }

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.5rem; color: var(--muted); font-size: 0.8125rem; font-weight: 500; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-muted);
}
.form-group textarea { min-height: 100px; resize: vertical; padding: 0.75rem 1rem; }
.form-group input[type="checkbox"] { width: auto; min-height: 22px; min-width: 22px; accent-color: var(--primary); }
.form-group .hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.35rem; }

/* Variant list (rotation) */
.variants {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.variant-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  align-items: flex-start;
}
.variant-item:last-child { border-bottom: 0; }
.variant-item input, .variant-item textarea { flex: 1; margin: 0; min-height: 38px; }
.variant-item textarea { min-height: 60px; }
.variant-item .btn-remove { flex-shrink: 0; padding: 0.4rem; min-width: 36px; min-height: 36px; }
.add-variant { margin-top: 0.5rem; }

.toggle-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.toggle-row input[type="checkbox"] { width: auto; margin: 0; }
.toggle-row label { margin: 0; font-size: 0.9rem; color: var(--text); cursor: pointer; }

.toast {
  position: fixed;
  bottom: calc(72px + var(--safe-bottom));
  left: 1rem;
  right: 1rem;
  max-width: 400px;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 200;
}
.toast[aria-hidden="false"] { opacity: 1; transform: translateY(0); }
.toast--success { border-color: var(--success); background: var(--success-muted); }
.toast--error { border-color: var(--danger); background: var(--danger-muted); }

.error { color: var(--danger); font-size: 0.9rem; }

@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .layout { display: flex; }
  .nav {
    position: static;
    width: 220px;
    flex-direction: column;
    border-top: 0;
    border-right: 1px solid var(--border);
    padding: 1rem 0;
    box-shadow: none;
  }
  .nav a { text-align: left; padding: 0.65rem 1.25rem; }
  .main { max-width: none; padding: 1.5rem 2rem; }
  .theme-toggle { top: 1rem; }
}
