:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e6e8ef;
  --border-strong: #d7dae4;
  --text: #14161f;
  --muted: #6b7280;
  --muted-2: #9296a3;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0fe;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --error: #dc2626;
  --error-soft: #fee2e2;
  --instagram: #c026d3;
  --telegram: #0ea5e9;
  --website: #78716c;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 31, 0.05);
  --shadow-md: 0 4px 14px rgba(20, 22, 31, 0.07);
  --shadow-lg: 0 12px 32px rgba(20, 22, 31, 0.12);
  /* calendar view (ported from eventwatch-viewer's dark theme) */
  --text-soft: var(--muted);
  --text-faint: var(--muted-2);
  --surface-2: #f1f2f8;
  --border-soft: var(--border);
  --accent-2: var(--accent-hover);
  --accent-pink: #ec4899;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── header ──────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15.5px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 15px; height: 15px; }

.nav { display: flex; align-items: center; gap: 18px; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: color 0.12s;
}
.nav a:hover { color: var(--accent); }
.nav .nav-email {
  color: var(--muted-2);
  font-size: 12.5px;
  padding: 4px 10px;
  background: var(--bg);
  border-radius: 999px;
}
.nav .nav-badge {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 999px;
}

.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 40px 24px 72px;
}

h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 22px;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--text);
}

.subtitle, .hint {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 16px;
}

/* ── hero / role picker (login, home, complete-profile) ────────────────── */

.hero { text-align: center; padding-top: 48px; }
.hero h1 { font-size: 28px; margin-bottom: 10px; }
.hero .subtitle { max-width: 460px; margin: 0 auto 28px; font-size: 15px; }

/* ── login page ──────────────────────────────────────────────────────── */

.login-hero { padding-top: 32px; }
.login-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); padding: 5px 14px; border-radius: 999px;
  margin-bottom: 18px;
}
.login-hero h1 {
  font-size: 34px; max-width: 640px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--text), var(--accent) 120%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.login-hero .subtitle { max-width: 560px; font-size: 15.5px; }
.login-cta { padding: 12px 30px; font-size: 15px; margin-bottom: 48px; box-shadow: var(--shadow-md); }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  max-width: 820px;
  margin: 0 auto;
  text-align: left;
}
.feature-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.feature-card .feature-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px; font-size: 18px;
  background: var(--accent-soft);
}
.feature-card h2 { font-size: 15.5px; margin-bottom: 6px; }
.feature-card p { color: var(--muted); font-size: 13px; margin: 0; line-height: 1.55; }

.role-cards {
  display: flex;
  gap: 18px;
  justify-content: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.role-card {
  display: block;
  width: 270px;
  padding: 26px 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
.role-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.role-card .role-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px; font-size: 18px;
  background: var(--accent-soft);
}
.role-card h2 { font-size: 17px; margin-bottom: 6px; }
.role-card p { color: var(--muted); font-size: 13.5px; margin: 0; line-height: 1.55; }

/* ── cards / sections ────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.simple-form {
  max-width: 340px;
  margin: 0 auto;
  text-align: left;
}
.field { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input { display: block; width: 100%; margin-top: 6px; }

/* ── tables ──────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.table tbody tr { transition: background 0.1s; }
.table tbody tr:hover { background: #fafbfd; }
.table td.wrap { white-space: normal; }
.table .empty-row td { color: var(--muted); font-style: italic; white-space: normal; }

/* ── buttons / inputs ────────────────────────────────────────────────── */

button, .btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.12s, color 0.12s, background 0.12s, box-shadow 0.12s;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25);
}
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--bg); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:disabled:hover { border-color: var(--border-strong); color: var(--text); }

input[type="text"], input[type="date"], input[type="number"], input[type="email"], select {
  font: inherit;
  font-size: 13.5px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.trigger-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.trigger-form label {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.add-form input[type="text"] { flex: 1; min-width: 220px; }

.status-msg { font-size: 13px; margin-left: 4px; }
.status-msg.ok { color: var(--ok); }
.status-msg.error { color: var(--error); }

/* ── toasts ──────────────────────────────────────────────────────────── */

#toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  color: #fff;
  background: var(--text);
  animation: toast-in 0.18s ease-out;
  max-width: 320px;
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--error); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── badges ──────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge.ok { background: var(--ok-soft); color: #15803d; }
.badge.error { background: var(--error-soft); color: #b91c1c; }
.badge.muted { background: #f1f2f6; color: var(--muted); text-transform: none; font-weight: 600; }

.platform-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
}
.platform-tag.instagram { background: linear-gradient(135deg, #f58529, #dd2a7b, #8134af); }
.platform-tag.telegram { background: var(--telegram); }
.platform-tag.website { background: var(--website); }

/* ── skeleton / loading ──────────────────────────────────────────────── */

.skeleton-row { color: var(--muted-2); font-style: italic; font-size: 13.5px; padding: 10px 0; }
.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── user page: sources list ─────────────────────────────────────────── */

.sources-list { list-style: none; margin: 0; padding: 0; }
.sources-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.sources-list li:last-child { border-bottom: none; }
.source-name { display: flex; align-items: center; gap: 10px; }

.follow-toggle {
  position: relative;
  width: 40px;
  height: 23px;
  border-radius: 999px;
  background: var(--border-strong);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s;
}
.follow-toggle::after {
  content: "";
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: left 0.15s;
}
.follow-toggle.on { background: var(--accent); }
.follow-toggle.on::after { left: 19.5px; }

/* ── event cards ─────────────────────────────────────────────────────── */

.events-feed {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.event-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #fff;
  transition: box-shadow 0.15s, transform 0.15s;
  cursor: default;
}
.event-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.event-card .event-thumb {
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: var(--bg);
  display: block;
}
.event-card .event-body { padding: 13px 14px; }
.event-card .event-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}
.event-card .event-title { font-weight: 600; font-size: 14px; line-height: 1.35; }
.event-card .event-meta { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.event-card .event-detail { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.event-card a { color: var(--accent); text-decoration: none; font-weight: 500; }
.event-card a:hover { text-decoration: underline; }
.event-card.clickable { cursor: pointer; }

/* ── modal (event detail) ────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 22, 31, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 24px;
}
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal pre {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 11.5px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal .modal-close {
  float: right;
  border: none;
  background: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

/* ── list/calendar view tabs ─────────────────────────────────────────── */

.view-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.view-tab {
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--muted);
  font-weight: 600;
}
.view-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── calendar view (ported from eventwatch-viewer) ──────────────────────── */

.power-banner { position: relative; overflow: hidden; color: #fff;
  background: radial-gradient(900px 260px at 0% 0%, rgba(255,255,255,.18), transparent 60%),
              linear-gradient(135deg, var(--accent), #9333ea 55%, var(--accent-pink));
  border-radius: var(--radius-lg); padding: 20px 24px; margin-bottom: 20px;
  box-shadow: var(--shadow-md); }
.power-banner .headline { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; margin: 0 0 4px;
  display: flex; align-items: center; gap: 8px; }
.pulse-fire { display: inline-block; animation: pulseGlow 2s ease-in-out infinite; }
.power-banner .stats { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 12px; }
.power-banner .stat { display: flex; flex-direction: column; }
.power-banner .stat .n { font-size: 21px; font-weight: 800; line-height: 1.1; }
.power-banner .stat .l { font-size: 11px; opacity: .85; text-transform: uppercase; letter-spacing: .05em; }
@keyframes pulseGlow { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }

.cal-layout { display: flex; gap: 20px; align-items: flex-start; }

.cal-sidebar { flex: 0 0 210px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px; box-shadow: var(--shadow-sm);
  position: sticky; top: 90px; }
.cal-sidebar h4 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); margin: 2px 4px 10px; }
.cal-source-row, .cal-city-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px;
  border-radius: 9px; cursor: pointer; font-size: 12.5px; font-weight: 600; user-select: none;
  border: 1px solid transparent; transition: all .15s ease; }
.cal-source-row:hover, .cal-city-row:hover { background: var(--surface-2); border-color: var(--border); }
.cal-source-row .cal-source-dot { width: 10px; height: 10px; border-radius: 50%; flex: none;
  box-shadow: 0 0 8px 0 currentColor; }
.cal-source-row .cal-source-name, .cal-city-row .cal-city-name { flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.cal-source-row .cal-source-count, .cal-city-row .cal-city-count { color: var(--text-faint);
  font-weight: 600; font-size: 11px; }
.cal-source-row.inactive, .cal-city-row.inactive { opacity: .35; }
.cal-source-row.inactive .cal-source-name, .cal-city-row.inactive .cal-city-name { text-decoration: line-through; }
.cal-sidebar .cal-source-all { font-size: 11px; color: var(--accent-2); cursor: pointer; font-weight: 600;
  margin: 2px 4px 10px; display: block; }
.cal-sidebar .cal-source-all:hover { text-decoration: underline; }

.cal-months { flex: 1 1 auto; min-width: 0; }
.cal-month { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 18px 14px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.cal-month-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.cal-month-header h3 { font-size: 16px; margin: 0; font-weight: 800; letter-spacing: -0.01em; }
.cal-month-header .cal-count { font-size: 12px; color: var(--text-soft); font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); text-align: center; padding-bottom: 4px; }
.cal-day { position: relative; aspect-ratio: 1 / 1; border-radius: 9px; border: 1px solid var(--border-soft);
  background: var(--bg); padding: 4px; display: flex; flex-direction: column; gap: 2px;
  overflow: hidden; transition: transform .15s ease, border-color .15s ease; }
.cal-day.empty { border: none; background: transparent; }
.cal-day.has-events { background: var(--accent-soft); border-color: rgba(79,70,229,.4); }
.cal-day.has-events:hover { transform: scale(1.04); border-color: var(--accent); z-index: 5; }
.cal-day-num { font-size: 10.5px; font-weight: 700; color: var(--text-faint); }
.cal-day.has-events .cal-day-num { color: var(--text); }
.cal-dots { display: flex; flex-direction: column; gap: 1px; overflow: hidden; flex: 1; min-height: 0; }
.cal-dot-row { display: flex; align-items: center; gap: 3px; cursor: pointer; line-height: 1.25;
  white-space: nowrap; overflow: hidden; }
.cal-dot-row:hover .cal-dot-label { text-decoration: underline; color: var(--accent-2); }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.cal-dot-label { font-size: 9px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.cal-dot-more { font-size: 9px; font-weight: 700; color: var(--text-faint); }

.cal-tooltip { position: fixed; z-index: 9999; max-width: 240px;
  background: #1c1f2c; color: #fff; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; font-size: 12px; line-height: 1.4;
  pointer-events: none; box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden; transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease, visibility .12s; }
.cal-tooltip.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.cal-tooltip .tip-title { font-weight: 800; margin-bottom: 3px; }
.cal-tooltip .tip-line { opacity: .8; font-size: 11px; margin-top: 1px; }
.cal-tooltip .tip-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; }

@media (max-width: 900px) {
  .cal-layout { flex-direction: column; }
  .cal-sidebar { position: static; width: 100%; flex: none; }
}

/* ── responsive ──────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .page { padding: 24px 16px 56px; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .role-cards { flex-direction: column; align-items: stretch; }
  .role-card { width: auto; }
  .table th:nth-child(n+5), .table td:nth-child(n+5) { display: none; }
}
