:root {
  /* Telegram theme variables — задаются Web App SDK */
  --bg: var(--tg-theme-bg-color, #17212b);
  --surface: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #8d97a0);
  --accent: var(--tg-theme-button-color, #5288c1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #6ab2f2);
  --destructive: var(--tg-theme-destructive-text-color, #ec3942);
  --success: #4caf50;

  --radius: 12px;
  --gap: 12px;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 16px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 8%, transparent);
}

.topbar h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

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

.tab {
  flex: 0 0 auto;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 500;
  background: var(--surface);
  color: var(--hint);
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- Content / Groups ---------- */

main {
  flex: 1;
  padding: 8px 12px 100px;
}

.group {
  margin-top: 16px;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 4px 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--hint);
}

.group-title .count {
  font-weight: 400;
  opacity: 0.7;
}

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

/* ---------- Task card ---------- */

.task-wrap {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg);
}

.task-wrap .swipe-bg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding: 0 24px;
  font-size: 22px;
  color: #fff;
  z-index: 0;
}

.task-wrap .swipe-bg.left {
  background: var(--success);
  justify-content: flex-start;
}

.task-wrap .swipe-bg.right {
  background: var(--destructive);
  justify-content: flex-end;
}

.task {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  touch-action: pan-y;
  user-select: none;
  transition: transform 0.2s ease;
}

.task .icon {
  font-size: 20px;
  line-height: 1;
}

.task .body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.task .text {
  font-size: 15px;
  line-height: 1.3;
  word-wrap: break-word;
}

.task .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--hint);
}

.task .meta .due {
  font-weight: 600;
  color: var(--link);
}

.task .meta .due.overdue {
  color: var(--destructive);
}

.task .meta .due.today {
  color: var(--accent);
}

.task .meta .project {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--text);
  padding: 1px 8px;
  border-radius: 8px;
}

.task .meta .priority {
  color: var(--destructive);
}

.task .ambiguity {
  margin-top: 4px;
  font-size: 12px;
  color: #f0b400;
  font-style: italic;
}

.task .actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.task .suggest-btn {
  font-size: 12px;
  padding: 4px 10px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

.task.done .text {
  text-decoration: line-through;
  color: var(--hint);
}

/* ---------- Projects list ---------- */

.project-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
}

.project-card .name {
  font-size: 16px;
  font-weight: 600;
}

.project-card .count {
  font-size: 13px;
  color: var(--hint);
}

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

#fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
}

#fab:active {
  transform: scale(0.96);
}

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: 100%;
  background: var(--bg);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}

.modal-content h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

#new-task-text {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 0;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
}

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

.hidden {
  display: none;
}
