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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232733;
  --border: #2e3340;
  --text: #e4e6ed;
  --text2: #9ca3b4;
  --accent: #6c8cff;
  --accent-hover: #8aa4ff;
  --green: #34d399;
  --red: #f87171;
  --orange: #fbbf24;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #e8eaef;
  --border: #d0d4db;
  --text: #1a1d27;
  --text2: #5f6672;
  --accent: #4f6ae6;
  --accent-hover: #3b53c7;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #d97706;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

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

.app { max-width: 640px; margin: 0 auto; padding: 12px 16px; }

/* ── Top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 12px;
}
.top-bar h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  padding: 0;
}
.top-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.top-btn:hover, .top-btn:active { color: var(--accent); border-color: var(--accent); }

/* ── Login page ── */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 28px 36px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  background: var(--accent);
  color: #fff;
  border-radius: 14px;
  font-size: 1.6rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 24px;
  padding: 0;
}
.login-error {
  color: var(--red);
  font-size: 0.85rem;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(248,113,113,0.1);
  border-radius: 8px;
}
.login-field {
  margin-bottom: 12px;
}
.login-field input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.login-field input:focus { outline: none; border-color: var(--accent); }
.login-field input::placeholder { color: var(--text2); }
.login-btn {
  width: 100%;
  margin-top: 8px;
  padding: 14px 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.login-btn:hover { background: var(--accent-hover); }
.login-btn:active { transform: scale(0.98); }

/* ── Week selector ── */
.week-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  background: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.week-bar select {
  flex: 1;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}
.week-bar .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.tab {
  flex: 1;
  padding: 10px 4px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  background: none;
  border: none;
  color: var(--text2);
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.tab.active { background: var(--accent); color: #fff; }
.tab:hover:not(.active) { color: var(--text); background: var(--surface2); }

/* ── Panels ── */
.panel { display: none; }
.panel.active { display: block; }

/* ── Day cards ── */
.day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.day-card h3 {
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 600;
}
.day-card textarea {
  width: 100%;
  min-height: 80px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  line-height: 1.5;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.day-card textarea:focus { outline: none; border-color: var(--accent); }

/* ── Pasta ── */
.pasta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.pasta-card h3 { font-size: 0.9rem; color: var(--orange); margin-bottom: 8px; font-weight: 600; }
.pasta-card input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.pasta-card input:focus { outline: none; border-color: var(--accent); }

/* ── Buttons ── */
.btn-row {
  display: flex;
  gap: 8px;
  margin: 16px 0;
  flex-wrap: wrap;
}
.btn {
  flex: 1;
  min-width: 120px;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--green); color: #000; }
.btn-success:hover { opacity: 0.9; }
.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1000;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }

/* ── Recipients ── */
.recipient-list { margin-top: 12px; }
.recipient-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 0.88rem;
}
.recipient-item .email { flex: 1; color: var(--text); word-break: break-all; }
.recipient-item .name { color: var(--text2); font-size: 0.8rem; }
.recipient-item .badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-active { background: var(--green); color: #000; }
.badge-inactive { background: var(--surface2); color: var(--text2); border: 1px solid var(--border); }
.icon-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 6px;
  font-size: 1.1rem;
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { color: var(--red); background: var(--surface2); }

.add-form {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.add-form input {
  flex: 1;
  min-width: 140px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: inherit;
  -webkit-appearance: none;
}
.add-form input:focus { outline: none; border-color: var(--accent); }
.add-form .btn { flex: 0; min-width: auto; padding: 10px 16px; }

/* ── BG selector ── */
.bg-selector {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.bg-selector label { font-size: 0.85rem; color: var(--text2); white-space: nowrap; }
.bg-selector select {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}

/* ── PDF Preview ── */
.pdf-preview {
  margin: 12px 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}
.pdf-preview iframe {
  width: 100%;
  height: 70vh;
  border: none;
  display: block;
}
.pdf-preview:empty {
  display: none;
}

/* ── Send result ── */
.send-result {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--green);
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.send-result h4 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--green);
  margin-bottom: 8px;
}
.send-result ul {
  list-style: none;
  padding: 0;
}
.send-result li {
  padding: 2px 0;
  color: var(--text2);
}
.send-result li::before {
  content: "✓ ";
  color: var(--green);
}

/* ── Loading ── */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.loading.show { display: flex; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
