/* public/style.css — Task 37 native Telegram design system */

:root {
  /* Fallbacks; overwritten from Telegram.WebApp.themeParams on load and on
     themeChanged (see app.js applyTheme()). Light-mode defaults here. */
  --bg: #ffffff;
  --card: #f1f1f4;
  --text: #000000;
  --hint: #707579;
  --link: #3390ec;
  --btn: #3390ec;
  --btn-text: #ffffff;
  --accent: #3390ec;
  --danger: #e5484d;

  --radius: 12px;
  --pad: 16px;
  --gap: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17212b;
    --card: #232e3c;
    --text: #ffffff;
    --hint: #708499;
    --link: #6ab7ff;
    --btn: #5288c1;
    --btn-text: #ffffff;
    --accent: #5288c1;
    --danger: #ff6b6b;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

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

button {
  cursor: pointer;
  background: none;
  border: none;
}

a { color: var(--link); }

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app {
  padding: var(--pad);
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.app-header h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  background: var(--card);
  color: var(--text);
}

.icon-btn:active { opacity: 0.7; }

/* ---------- Filter tab row (signature component) ---------- */

.filter-tabs {
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 4px;
  scrollbar-width: none;
}

.filter-tabs::-webkit-scrollbar { display: none; }

.filter-tab {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.filter-tab.filter-tab--all {
  font-size: 12px;
  font-weight: 600;
}

.filter-tab.active {
  color: #ffffff;
}

.filter-label {
  font-size: 13px;
  color: var(--hint);
  min-height: 16px;
  margin: 4px 0 12px;
}

.filter-label:empty { display: none; }

/* ---------- Day groups + list ---------- */

.day-group + .day-group {
  margin-top: 16px;
}

.day-group h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  margin: 0 0 var(--gap) 2px;
  text-transform: none;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---------- Reminder card ---------- */

.card-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
}

.card-delete-bg {
  position: absolute;
  inset: 0;
  background: var(--danger);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 20px;
  font-size: 20px;
}

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 12px 16px;
  background: var(--card);
  border-radius: var(--radius);
  touch-action: pan-y;
  transform: translateX(0);
  transition: transform 0.18s ease;
}

.card-accent-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent-color, var(--accent));
  border-radius: var(--radius) 0 0 var(--radius);
}

.card-emoji-bubble {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-text {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-meta {
  margin-top: 2px;
  font-size: 13px;
  color: var(--hint);
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--btn-text);
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  z-index: 20;
}

.fab:active { transform: scale(0.94); }

/* ---------- Empty state ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  padding: 48px 16px;
  color: var(--hint);
}

.empty-state[hidden] { display: none; }

.btn-primary {
  padding: 10px 20px;
  border-radius: var(--radius);
  background: var(--btn);
  color: var(--btn-text);
  font-size: 15px;
  font-weight: 600;
}

.btn-primary:active { opacity: 0.85; }

.btn-danger-text {
  color: var(--danger);
  font-size: 15px;
  font-weight: 600;
  padding: 10px;
}

/* ---------- Sheets (form / settings / stats) ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 8%;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 31;
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
}

.sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--hint);
  opacity: 0.4;
  margin: 8px auto;
  flex: none;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px var(--pad) 12px;
  flex: none;
}

.sheet-header h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--pad) calc(24px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

.sheet-fallback-save {
  flex: none;
  margin: 8px var(--pad) calc(12px + env(safe-area-inset-bottom, 0px));
}

.sheet-fallback-save[hidden] { display: none; }

/* ---------- Form fields (generic) ---------- */

.field {
  margin-bottom: 18px;
}

.field label,
.field-label {
  display: block;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 6px;
}

textarea, input[type="text"], input[type="date"], input[type="time"], input[type="email"], select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.field-row {
  display: flex;
  gap: var(--gap);
}

.field-row > * { flex: 1; }

/* ---------- Chip rows (category picker / offsets / channels / weekdays) ---------- */

.chip-row {
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar { display: none; }

.cat-chip {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  border: 2px solid transparent;
}

.cat-chip.selected {
  border-color: var(--chip-color, var(--accent));
  background: var(--chip-tint, var(--card));
}

.pill {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}

.pill.active {
  background: var(--accent);
  color: #ffffff;
}

.weekday-pills { margin-top: 10px; }

.weekday-pill {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--card);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.weekday-pill.active {
  background: var(--accent);
  color: #ffffff;
}

.channel-toggle {
  flex: 0 0 auto;
  width: 48px;
  height: 44px;
  border-radius: 10px;
  background: var(--card);
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.channel-toggle.active {
  background: var(--accent);
  color: #ffffff;
}

[hidden] { display: none !important; }

/* ---------- Settings list ---------- */

.settings-group {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
}

.settings-row + .settings-row {
  border-top: 1px solid rgba(127, 127, 127, 0.18);
}

.settings-row .settings-row-label {
  font-size: 15px;
}

.settings-row .settings-row-hint {
  font-size: 13px;
  color: var(--hint);
  margin-top: 2px;
}

.settings-row select,
.settings-row input {
  background: transparent;
  text-align: right;
  border: none;
  width: auto;
  max-width: 55%;
}

.settings-row input[readonly] {
  color: var(--hint);
}

.settings-group-title {
  font-size: 13px;
  color: var(--hint);
  margin: 0 0 6px 2px;
}

/* ---------- Category management ---------- */

.category-list {
  display: flex;
  flex-direction: column;
}

.category-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}

.category-row + .category-row {
  border-top: 1px solid rgba(127, 127, 127, 0.18);
}

.category-row .cat-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex: none;
}

.category-row .category-name {
  flex: 1;
  font-size: 15px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-row .preset-badge {
  font-size: 11px;
  color: var(--hint);
  background: rgba(127, 127, 127, 0.18);
  padding: 2px 8px;
  border-radius: 999px;
  flex: none;
}

.category-row .cat-action-btn {
  font-size: 16px;
  padding: 6px;
  color: var(--hint);
}

.category-row .cat-action-btn.danger {
  color: var(--danger);
}

.add-category-form {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-category-form .field-row input {
  background: var(--bg);
}

.color-swatch-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
}

.color-swatch.selected {
  border-color: var(--text);
}

/* ---------- Stats ---------- */

.stats-row {
  display: flex;
  gap: var(--gap);
  margin-bottom: 16px;
}

.stats-card {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
}

.stats-card h3 {
  font-size: 13px;
  color: var(--hint);
  margin: 0 0 8px;
  font-weight: 600;
}

.stats-card .stats-line {
  font-size: 15px;
  margin-bottom: 4px;
}

.streak-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.streak-row {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 15px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.streak-row .streak-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-empty {
  color: var(--hint);
  font-size: 15px;
  text-align: center;
  padding: 24px 0;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .card, .sheet, .sheet-backdrop, .filter-tab, .fab, .cat-chip, .pill, .weekday-pill, .channel-toggle {
    transition: none !important;
  }
}

/* ---------- Responsive floor (320px) ---------- */

@media (max-width: 360px) {
  #app { padding: 12px; padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
  .filter-tab { flex-basis: 40px; width: 40px; height: 40px; }
  .card-emoji-bubble { flex-basis: 32px; width: 32px; height: 32px; }
  .fab { width: 50px; height: 50px; font-size: 24px; right: 12px; }
  .sheet { top: 4%; }
}
