:root {
  --bg: #0f1115;
  --surface: #171922;
  --surface-2: #1e212c;
  --border: #2a2e3a;
  --text: #e7e9ee;
  --text-muted: #8a8f9c;
  --accent: #3b82f6;
  --accent-hover: #2f6fd6;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #eab308;

  --status-unread: #6b7280;
  --status-read: #64748b;
  --status-replied: #3b82f6;
  --status-progress: #eab308;
  --status-bought: #22c55e;
  --status-not-bought: #ef4444;

  --radius: 14px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 22px;
  border: 1px solid var(--border);
}
.login-box h1 {
  font-size: 22px;
  margin: 0 0 6px;
  text-align: center;
}
.login-box .muted {
  text-align: center;
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 14px;
}
.login-box input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 14px;
}
.error-text {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
  margin: 10px 0 0;
}

/* ---------- App shell ---------- */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  font-size: 18px;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 20px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

.content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(90px + var(--safe-bottom));
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  font-size: 11px;
  cursor: pointer;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 20px; }

/* ---------- Generic components ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  min-height: 46px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-hover); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-success { background: var(--success); border-color: var(--success); color: #06210f; }
.btn-block { width: 100%; }
.btn-lg { padding: 18px; font-size: 17px; }
.btn-sm { padding: 8px 12px; font-size: 13px; min-height: 36px; }

.input, textarea.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
  resize: vertical;
}
textarea.input { min-height: 80px; }
label.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ---------- Timer / session ---------- */
.timer-card {
  text-align: center;
  padding: 28px 16px;
}
.timer-display {
  font-size: 48px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  margin: 6px 0 20px;
}
.timer-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.session-status-pill {
  display: inline-block;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  margin-bottom: 8px;
}
.session-status-pill.active { color: var(--success); }
.session-status-pill.paused { color: var(--warning); }

.round-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.round-btn.play { background: var(--success); color: #06210f; }
.round-btn.stop { background: var(--danger); color: #fff; }
.round-btn.pause { background: var(--warning); color: #241a00; }

/* ---------- Finance summary widget ---------- */
.finance-summary {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.finance-stat { flex: 1; text-align: center; }
.finance-stat .value { font-size: 18px; font-weight: 700; }
.finance-stat .label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.progress-bar {
  height: 8px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 12px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
  transition: width 0.3s;
}

/* ---------- Session goal ---------- */
.goal-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 16px;
}

/* ---------- Recent sessions widget (productivity) ---------- */
.recent-sessions-card {
  padding: 6px 16px;
}
.recent-session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.recent-session-item:last-child { border-bottom: none; }
.recent-session-date {
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}
.recent-session-metrics {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  font-size: 12px;
  color: var(--text);
}

/* ---------- Contact list ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(90px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 26px;
  box-shadow: 0 6px 16px rgba(59,130,246,0.4);
  cursor: pointer;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.contact-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.contact-links { font-size: 13px; overflow: hidden; }
.contact-links a {
  color: var(--accent);
  text-decoration: none;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-date { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.contact-offer {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.contact-amount { font-size: 13px; color: var(--success); font-weight: 600; margin-bottom: 8px; }

.status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
}
.chip.active { color: #fff; border-color: transparent; }
.chip[data-status="unread"].active { background: var(--status-unread); }
.chip[data-status="read_no_reply"].active { background: var(--status-read); }
.chip[data-status="replied"].active { background: var(--status-replied); }
.chip[data-status="in_progress"].active { background: var(--status-progress); color: #241a00; }
.chip[data-status="bought"].active { background: var(--status-bought); color: #06210f; }
.chip[data-status="not_bought"].active { background: var(--status-not-bought); }

.status-badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
  color: #fff;
}
.status-badge.unread { background: var(--status-unread); }
.status-badge.read_no_reply { background: var(--status-read); }
.status-badge.replied { background: var(--status-replied); }
.status-badge.in_progress { background: var(--status-progress); color: #241a00; }
.status-badge.bought { background: var(--status-bought); color: #06210f; }
.status-badge.not_bought { background: var(--status-not-bought); }

.contact-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-end;
}
.text-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 8px;
  cursor: pointer;
}
.text-btn.danger { color: var(--danger); }

/* ---------- Filters ---------- */
.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Session history ---------- */
.session-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.session-item-top {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 6px;
}
.session-item-stats {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.session-item-stats b { color: var(--text); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.stat-box {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.stat-box .value { font-size: 20px; font-weight: 700; }
.stat-box .label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: 18px; }
}
.modal-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 16px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.modal-actions .btn { flex: 1; }

.finance-entry-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.finance-entry-row:last-child { border-bottom: none; }
.finance-entry-amount.income { color: var(--success); }
.finance-entry-amount.expense { color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.section-header h2 { font-size: 16px; margin: 0; }

/* ---------- Admin screen ---------- */
.admin-user-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.admin-user-row:last-child { border-bottom: none; }
.admin-user-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.admin-user-name .muted {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}
.admin-user-metrics {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
}
.admin-user-metrics .negative { color: var(--danger); }
.admin-user-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  align-items: flex-end;
}

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 60px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
