/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #222);
  --hint: var(--tg-theme-hint-color, #999);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #fff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --section-bg: var(--tg-theme-section-bg-color, #fff);
  --danger: #e74c3c;
  --success: #27ae60;
  --tab-height: 64px;
  --tab-font: 15px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* === App Shell === */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

#views-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.view {
  display: none;
  padding: 12px 16px 16px;
}
.view.active { display: block; }
.hidden { display: none !important; }

/* === Tab Bar === */
#tab-bar {
  display: flex;
  flex-shrink: 0;
  height: var(--tab-height);
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid var(--secondary-bg);
  background: var(--bg);
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--hint);
  font-size: var(--tab-font);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active {
  color: var(--button);
  font-weight: 600;
}

.tab-menu {
  flex: 0 0 48px;
  font-size: 20px;
  font-weight: 400;
}

/* === View Header === */
.view-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}

.nav-title {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  flex: 1;
}

.nav-arrow {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-arrow:active { opacity: 0.6; }

.nav-arrow-placeholder {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.nav-subtitle {
  font-size: 12px;
  font-weight: 400;
  color: var(--hint);
}

/* === FAB === */
.fab {
  position: fixed;
  bottom: calc(var(--tab-height) + 20px + var(--safe-bottom));
  right: 20px;
  z-index: 40;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  border: none;
  background: var(--button);
  color: var(--button-text);
  font-size: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: transform 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.fab.hidden {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

/* === Section === */
.section {
  margin-bottom: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--hint);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.section-count {
  font-weight: 400;
  color: var(--hint);
  font-size: 13px;
}

/* === Main Task Slots === */
.main-slots {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.main-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--secondary-bg);
  min-height: 48px;
  transition: all 0.15s;
}

.main-slot.filled {
  animation: slideIn 0.2s ease-out;
  cursor: pointer;
}
.main-slot.filled:active { opacity: 0.7; }

.main-slot.empty {
  border: 2px dashed var(--hint);
  background: transparent;
  opacity: 0.7;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint);
  font-size: 15px;
  gap: 6px;
}
.main-slot.empty:active { opacity: 0.9; }

.main-slot .slot-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.main-slot.empty .slot-num {
  background: var(--hint);
  opacity: 0.5;
}

.main-slot .slot-text {
  flex: 1;
  word-break: break-word;
}
.main-slot.done .slot-text {
  text-decoration: line-through;
  opacity: 0.5;
}

.main-slot .slot-check {
  position: relative;
  width: 26px;
  height: 26px;
  border: 2px solid var(--hint);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  background: transparent;
  color: transparent;
  font-size: 14px;
}
.main-slot .slot-check::after {
  content: '';
  position: absolute;
  top: -11px; left: -11px;
  right: -11px; bottom: -11px;
}
.main-slot .slot-check.checked {
  background: var(--button);
  border-color: var(--button);
  color: var(--button-text);
}
.main-slot.empty .slot-check { display: none; }

.slot-empty-hint {
  color: var(--hint);
}

/* === Task List (other tasks) === */
.task-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.task-item-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  animation: slideIn 0.2s ease-out;
}

.task-swipe-bg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 14px;
  background: var(--danger);
  border-radius: 10px;
}

.task-swipe-delete-btn {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}

.task-swipe-content {
  position: relative;
  z-index: 1;
  background: var(--secondary-bg);
  border-radius: 10px;
  transition: transform 0.25s cubic-bezier(0.2, 0, 0, 1);
  touch-action: pan-y;
}

.task-swipe-content.swiped {
  transform: translateX(-90px);
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}

.task-item.done .task-text {
  text-decoration: line-through;
  opacity: 0.5;
}

.task-check {
  position: relative;
  width: 24px;
  height: 24px;
  border: 2px solid var(--hint);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  background: transparent;
  color: transparent;
  font-size: 14px;
}
.task-check::after {
  content: '';
  position: absolute;
  top: -12px; left: -12px;
  right: -12px; bottom: -12px;
}
.task-check.checked {
  background: var(--button);
  border-color: var(--button);
  color: var(--button-text);
  animation: checkPop 0.35s ease-out;
}

.main-slot .slot-check.checked {
  animation: checkPop 0.35s ease-out;
}

.task-text {
  flex: 1;
  word-break: break-word;
  font-size: 16px;
}

/* === Bottom Sheet === */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--section-bg);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: slideUp 0.25s cubic-bezier(0.2, 0, 0, 1);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--hint);
  opacity: 0.3;
  margin: 0 auto 16px;
}

.sheet-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}

.sheet-field {
  margin-bottom: 16px;
  position: relative;
}

.sheet-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.sheet-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--hint);
  margin-bottom: 6px;
  transition: color 0.15s;
}

.sheet-field:focus-within .sheet-label {
  color: var(--button);
}

.sheet-input {
  width: 100%;
  height: 48px;
  padding: 0 44px 0 16px;
  border: 1.5px solid rgba(128,128,128,0.3);
  border-radius: 14px;
  font-size: 17px;
  background: var(--secondary-bg);
  color: var(--text);
  outline: none;
}
.sheet-input:focus { border-color: var(--button); }

.sheet-clear {
  position: absolute;
  right: 4px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--hint);
  font-size: 18px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sheet-clear.visible { display: flex; }
.sheet-clear:active { color: var(--text); }

.sheet-type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.sheet-type-btn {
  flex: 1;
  height: 40px;
  border: 1.5px solid rgba(128,128,128,0.3);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sheet-type-btn.active {
  border-color: var(--button);
  background: var(--button);
  color: var(--button-text);
}

.sheet-type-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.sheet-actions {
  display: flex;
  gap: 10px;
}

.sheet-btn {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sheet-btn:active { opacity: 0.7; }

.sheet-btn-cancel {
  background: var(--secondary-bg);
  color: var(--text);
}

.sheet-btn-save {
  background: var(--button);
  color: var(--button-text);
}

/* === Undo Toast === */
.undo-toast {
  position: sticky;
  bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-top: 8px;
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  font-size: 15px;
  animation: slideIn 0.2s ease-out;
  z-index: 50;
}

.undo-toast-btn {
  border: none;
  background: transparent;
  color: var(--button);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--hint);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 8px; }
.empty-state .empty-text { font-size: 16px; margin-bottom: 4px; }
.empty-state .empty-hint { font-size: 13px; }

/* === Week View === */
.week-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--secondary-bg);
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 52px;
}
.day-card:active { opacity: 0.7; }
.day-card.today {
  border: 2px solid var(--button);
}
.day-card.empty {
  opacity: 0.5;
}

.day-card .day-label {
  width: 48px;
  flex-shrink: 0;
  text-align: center;
}
.day-card .day-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
}
.day-card .day-date {
  font-size: 20px;
  font-weight: 700;
}
.day-card.today .day-date {
  color: var(--button);
}

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

.day-card .day-main-tasks {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.day-card .day-main-task {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 1px 0;
}
.day-card .day-main-task.done {
  text-decoration: line-through;
  opacity: 0.4;
}

.day-card .day-other-count {
  font-size: 11px;
  color: var(--hint);
  margin-top: 2px;
}

.day-card .day-stats {
  flex-shrink: 0;
  text-align: right;
}
.day-card .day-progress {
  font-size: 14px;
  font-weight: 700;
  color: var(--success);
}
.day-card .day-progress.partial {
  color: var(--button);
}
.day-card .day-progress.none {
  color: var(--hint);
}

/* === Sprint View === */
.sprint-weeks {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.week-card {
  border-radius: 12px;
  background: var(--secondary-bg);
  cursor: pointer;
  overflow: hidden;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.week-card:active { opacity: 0.7; }
.week-card.current {
  border: 2px solid var(--button);
}

.week-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
}

.week-card-label {
  display: flex;
  flex-direction: column;
}

.week-card-num {
  font-size: 15px;
  font-weight: 600;
}

.week-card-range {
  font-size: 12px;
  color: var(--hint);
}

.week-card-summary {
  text-align: right;
  font-size: 13px;
  color: var(--hint);
}
.week-card-summary .done-count {
  color: var(--success);
  font-weight: 600;
}

.week-card-bar {
  height: 3px;
  background: var(--hint);
  opacity: 0.2;
}
.week-card-bar .week-card-fill {
  height: 100%;
  background: var(--button);
  transition: width 0.3s;
}

/* === Sprint List === */
.sprint-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sprint-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--secondary-bg);
  gap: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sprint-list-item:active { opacity: 0.7; }
.sprint-list-item.active {
  border: 2px solid var(--button);
}

.sprint-list-info {
  flex: 1;
  min-width: 0;
}
.sprint-list-range {
  font-size: 16px;
  font-weight: 500;
}
.sprint-list-stats {
  font-size: 12px;
  color: var(--hint);
  margin-top: 2px;
}

.sprint-list-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.sprint-action-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sprint-action-btn:active { opacity: 0.6; }
.sprint-action-btn.danger { color: var(--danger); }

/* === Sprint / Week info === */
.sprint-info {
  text-align: center;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 8px;
}

.sprint-start-btn {
  display: block;
  margin: 0 auto 12px;
  padding: 4px 12px;
  border: 1px solid var(--hint);
  border-radius: 14px;
  background: transparent;
  color: var(--hint);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sprint-start-btn:active {
  background: var(--secondary-bg);
}

.sprint-create-btn {
  padding: 12px 28px;
  border: none;
  border-radius: 14px;
  background: var(--button);
  color: var(--button-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.sprint-create-btn:active { opacity: 0.7; }

.section-divider {
  text-align: center;
  font-size: 12px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 16px 0 8px;
  padding-top: 12px;
  border-top: 1px solid var(--secondary-bg);
}

/* === Inline Date Picker === */
.date-picker-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.date-picker-overlay input {
  opacity: 0;
  width: 0; height: 0;
}

/* === Animations === */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes checkPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* === Clear done === */
.clear-row {
  display: flex;
  justify-content: center;
  margin-top: 12px;
  padding-bottom: 8px;
}
.clear-done-btn {
  padding: 6px 16px;
  border: 1px solid var(--danger);
  border-radius: 16px;
  background: transparent;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.clear-done-btn:active {
  background: var(--danger);
  color: var(--button-text);
}
