* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --radius: 12px;
  --radius-sm: 8px;
  --field-bg: var(--tg-theme-secondary-bg-color);
  --border: rgba(128, 128, 128, 0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 100px;
}

/* ── Top Bar ── */

.top-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
}

.top-bar .select-wrap {
  flex: 1;
}

/* ── Tabs ── */

.tabs {
  display: flex;
  padding: 12px 16px 0;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  background: none;
  border: none;
  color: var(--tg-theme-hint-color);
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.tab.active {
  color: var(--tg-theme-button-color);
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--tg-theme-button-color);
  border-radius: 1px;
}

/* ── Tab content ── */

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ── Filter bar ── */

.filter-bar {
  padding: 12px 16px;
}

/* ── Select ── */

.select-wrap {
  position: relative;
}

.select-wrap select {
  width: 100%;
  padding: 12px 36px 12px 14px;
  font-size: 15px;
  font-family: inherit;
  background: var(--field-bg);
  color: var(--tg-theme-text-color);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.select-sm select {
  padding: 8px 30px 8px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.select-wrap select:focus {
  border-color: var(--tg-theme-button-color);
}

.select-wrap select:disabled {
  opacity: 0.5;
  cursor: default;
}

.select-chevron {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--tg-theme-hint-color);
  pointer-events: none;
}

/* ── Form ── */

.form-body {
  padding: 16px 16px 24px;
}

.field {
  margin-bottom: 16px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--tg-theme-hint-color);
  margin-bottom: 6px;
  padding-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.field-label .optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.6;
  font-size: 12px;
}

#title-input,
#desc-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  background: var(--field-bg);
  color: var(--tg-theme-text-color);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
  resize: none;
}

#title-input::placeholder,
#desc-input::placeholder {
  color: var(--tg-theme-hint-color);
  opacity: 0.6;
}

#title-input:focus,
#desc-input:focus {
  border-color: var(--tg-theme-button-color);
}

#desc-input {
  min-height: 80px;
  line-height: 1.45;
}

/* ── Image Upload ── */

.image-upload {
  position: relative;
  cursor: pointer;
}

.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  background: var(--field-bg);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--tg-theme-hint-color);
  font-size: 13px;
  font-weight: 500;
  transition: border-color 0.15s;
}

.image-placeholder:active {
  border-color: var(--tg-theme-button-color);
}

.image-preview {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
}

.image-preview img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
}

.image-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.1s;
}

.image-remove:active {
  transform: scale(0.9);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── Priority Pills ── */

.priority-pills {
  display: flex;
  gap: 6px;
}

.pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 9px 4px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  background: var(--field-bg);
  color: var(--tg-theme-hint-color);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pill:active {
  transform: scale(0.96);
}

.pill.selected {
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  border-color: var(--tg-theme-button-color);
  font-weight: 600;
}

/* ── Labels ── */

.labels-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.labels-empty {
  font-size: 13px;
  color: var(--tg-theme-hint-color);
  opacity: 0.6;
}

.label-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  background: var(--field-bg);
  color: var(--tg-theme-hint-color);
  border: 1.5px solid transparent;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

.label-chip:active {
  transform: scale(0.96);
}

.label-chip .label-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.label-chip.selected {
  color: var(--tg-theme-text-color);
  border-color: var(--tg-theme-button-color);
  font-weight: 600;
}

/* ── Tasks List ── */

.tasks-list {
  padding: 0 16px;
}

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

.status-group {
  margin-bottom: 20px;
}

.status-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--tg-theme-hint-color);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-count {
  font-weight: 400;
  opacity: 0.6;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--field-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.15s;
}

.task-item:active {
  opacity: 0.7;
}

.task-id {
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-theme-hint-color);
  white-space: nowrap;
  padding-top: 1px;
}

.task-info {
  flex: 1;
  min-width: 0;
}

.task-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}

.task-labels {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.task-label-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0.8;
}

.task-priority {
  width: 4px;
  height: 16px;
  border-radius: 2px;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ── Success View ── */

#success-view {
  min-height: 70vh;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

#success-view.active {
  display: flex;
}

.success-content {
  text-align: center;
}

.success-check {
  margin-bottom: 20px;
}

.check-circle {
  stroke-dasharray: 138;
  stroke-dashoffset: 138;
  animation: circle-draw 0.6s ease-out 0.1s forwards;
}

.check-mark {
  stroke-dasharray: 30;
  stroke-dashoffset: 30;
  animation: check-draw 0.35s ease-out 0.55s forwards;
}

@keyframes circle-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes check-draw {
  to { stroke-dashoffset: 0; }
}

.success-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.success-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  background: #7C5CFC22;
  color: #7C5CFC;
  margin-bottom: 12px;
  letter-spacing: 0.3px;
}

.success-id {
  font-size: 14px;
  color: var(--tg-theme-hint-color);
  margin-bottom: 16px;
  font-weight: 500;
}

.success-link {
  display: inline-block;
  font-size: 14px;
  color: var(--tg-theme-link-color, var(--tg-theme-button-color));
  text-decoration: none;
  margin-bottom: 32px;
  font-weight: 500;
}

.success-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn-primary,
.btn-secondary {
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:active,
.btn-secondary:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}

.btn-secondary {
  background: var(--field-bg);
  color: var(--tg-theme-hint-color);
}

/* ── Loading ── */

#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--tg-theme-button-color);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden {
  display: none !important;
}

/* ── Animations ── */

.field {
  animation: field-in 0.3s ease-out backwards;
}

.field:nth-child(1) { animation-delay: 0.03s; }
.field:nth-child(2) { animation-delay: 0.06s; }
.field:nth-child(3) { animation-delay: 0.09s; }
.field:nth-child(4) { animation-delay: 0.12s; }
.field:nth-child(5) { animation-delay: 0.15s; }
.field:nth-child(6) { animation-delay: 0.18s; }
.field:nth-child(7) { animation-delay: 0.21s; }

@keyframes field-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.task-item {
  animation: field-in 0.2s ease-out backwards;
}

.tasks-loading {
  text-align: center;
  padding: 40px;
  color: var(--tg-theme-hint-color);
  font-size: 14px;
}
