/**
 * Telegram Mini App (TMA) Native Stylesheet
 * Refactored using Telegram theme tokens, safe-area formulas, and native mobile ergonomics.
 */

:root {
  /* System font stack matching native Telegram clients */
  --font-main: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;

  /* Telegram Theme Variables with iOS/Android Native Fallbacks */
  --tg-theme-bg-color: #ffffff;
  --tg-theme-secondary-bg-color: #f4f4f5;
  --tg-theme-section-bg-color: #ffffff;
  --tg-theme-text-color: #000000;
  --tg-theme-hint-color: #8e8e93;
  --tg-theme-link-color: #2481cc;
  --tg-theme-button-color: #2481cc;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-header-bg-color: #ffffff;
  --tg-theme-accent-text-color: #2481cc;
  --tg-theme-section-header-text-color: #6d6d72;
  --tg-theme-subtitle-text-color: #8e8e93;
  --tg-theme-destructive-text-color: #ff3b30;

  /* Dynamic Border & Shadows based on Theme Tokens */
  --tg-border-color: rgba(120, 120, 128, 0.16);
  --tg-card-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  --tg-glass-bg: rgba(255, 255, 255, 0.88);
  --tg-badge-bg: rgba(36, 129, 204, 0.10);
  --tg-card-media-bg: #e5e7eb;

  /* Safe Area Inset Tokens with Fallbacks */
  --tg-safe-area-inset-top: env(safe-area-inset-top, 0px);
  --tg-safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --tg-safe-area-inset-left: env(safe-area-inset-left, 0px);
  --tg-safe-area-inset-right: env(safe-area-inset-right, 0px);

  /* Telegram Viewport Heights */
  --tg-viewport-height: 100vh;
  --tg-viewport-stable-height: 100vh;

  /* Radius Tokens */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
}

/* Telegram Dark Mode Defaults */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tg-theme-bg-color: #17212b;
    --tg-theme-secondary-bg-color: #0e1621;
    --tg-theme-section-bg-color: #242f3d;
    --tg-theme-text-color: #f5f5f5;
    --tg-theme-hint-color: #708499;
    --tg-theme-link-color: #5288c1;
    --tg-theme-button-color: #5288c1;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-header-bg-color: #17212b;
    --tg-theme-accent-text-color: #64b5f6;
    --tg-theme-section-header-text-color: #7996b2;
    --tg-theme-subtitle-text-color: #7996b2;
    --tg-theme-destructive-text-color: #eb5757;

    --tg-border-color: rgba(255, 255, 255, 0.08);
    --tg-card-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    --tg-glass-bg: rgba(23, 33, 43, 0.90);
    --tg-badge-bg: rgba(82, 136, 193, 0.15);
    --tg-card-media-bg: #1e293b;
  }
}

/* Base Reset & Native App Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, textarea, [contenteditable="true"] {
  user-select: text;
}

html, body {
  width: 100%;
  min-height: 100%;
  min-height: var(--tg-viewport-stable-height, 100vh);
  font-family: var(--font-main);
  background-color: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  overflow-x: hidden;
}

/* Subtle ambient backdrop adapting to theme button color */
.glow-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.12;
}

.orb-1 {
  width: 260px;
  height: 260px;
  background: var(--tg-theme-button-color);
  top: -40px;
  right: -40px;
}

.orb-2 {
  width: 220px;
  height: 220px;
  background: var(--tg-theme-link-color);
  bottom: 20%;
  left: -40px;
}

.app-wrapper {
  position: relative;
  z-index: 1;
  max-width: 600px;
  margin: 0 auto;
  min-height: var(--tg-viewport-stable-height, 100vh);
  display: flex;
  flex-direction: column;
}

/* Header with Viewport Safe-Area Handling */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--tg-glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: calc(10px + var(--tg-safe-area-inset-top)) 16px 10px 16px;
  border-bottom: 1px solid var(--tg-border-color);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

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

.greeting-sub {
  font-size: 0.78rem;
  color: var(--tg-theme-hint-color);
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  display: block;
}

.header-title {
  font-family: var(--font-heading);
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.4px;
  color: var(--tg-theme-text-color);
}

.gradient-text {
  color: var(--tg-theme-button-color);
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--tg-badge-bg);
  border: 1px solid var(--tg-border-color);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--tg-theme-button-color);
}

/* Search Bar */
.search-container {
  margin-bottom: 10px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--tg-theme-secondary-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-md);
  padding: 0 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box:focus-within {
  border-color: var(--tg-theme-button-color);
  box-shadow: 0 0 0 2px rgba(36, 129, 204, 0.18);
}

.search-icon {
  width: 18px;
  height: 18px;
  color: var(--tg-theme-hint-color);
  flex-shrink: 0;
  margin-right: 8px;
}

.search-box input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-main);
  font-size: 15px; /* iOS zoom prevention */
  color: var(--tg-theme-text-color);
  padding: 10px 0;
}

.search-box input::placeholder {
  color: var(--tg-theme-hint-color);
}

.clear-search-btn {
  background: var(--tg-border-color);
  border: none;
  color: var(--tg-theme-hint-color);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}

.clear-search-btn:active {
  background: var(--tg-theme-hint-color);
  color: var(--tg-theme-button-text-color);
}

/* Horizontal Tag Carousel */
.tag-carousel-wrapper {
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin: 0 -16px;
  padding: 2px 16px;
}

.tag-carousel-wrapper::-webkit-scrollbar {
  display: none;
}

.tag-carousel {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.tag-chip {
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
  font-family: var(--font-main);
}

.tag-chip:active {
  transform: scale(0.95);
}

.tag-chip.active {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(36, 129, 204, 0.25);
}

/* Main Content with Safe-Area Padding */
.main-content {
  flex: 1;
  padding: 14px 16px calc(24px + var(--tg-safe-area-inset-bottom)) 16px;
}

/* Loading Skeleton */
.skeleton-card {
  height: 200px;
  background: linear-gradient(
    90deg,
    var(--tg-theme-secondary-bg-color) 25%,
    var(--tg-border-color) 50%,
    var(--tg-theme-secondary-bg-color) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 50px 20px;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 10px;
}

.empty-state h3 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  margin-bottom: 6px;
  color: var(--tg-theme-text-color);
}

.empty-state p {
  color: var(--tg-theme-hint-color);
  font-size: 0.88rem;
  max-width: 300px;
  margin: 0 auto;
}

/* Recipe Grid & Native Tactile Cards */
.recipe-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 480px) {
  .recipe-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.recipe-card {
  background: var(--tg-theme-section-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--tg-card-shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
}

.recipe-card:active {
  transform: scale(0.982);
  filter: brightness(0.97);
}

.card-media {
  position: relative;
  height: 150px;
  background: var(--tg-card-media-bg);
  overflow: hidden;
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.play-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #ffffff;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.instagram-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #ffffff;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.card-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 6px;
  color: var(--tg-theme-text-color);
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}

.card-tags:empty {
  display: none;
}

.card-tag {
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-link-color);
  border: 1px solid var(--tg-border-color);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
}

.card-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--tg-theme-hint-color);
  border-top: 1px solid var(--tg-border-color);
  padding-top: 8px;
}

.card-footer .cta-link {
  color: var(--tg-theme-link-color);
  font-weight: 600;
}

.ingredient-pill {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Modal Bottom Sheet */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  background: var(--tg-theme-section-bg-color);
  border: 1px solid var(--tg-border-color);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
}

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

.modal-close-handle {
  width: 100%;
  background: transparent;
  border: none;
  padding: 10px 0 6px 0;
  cursor: pointer;
  display: flex;
  justify-content: center;
}

.handle-bar {
  width: 38px;
  height: 4px;
  background: var(--tg-theme-hint-color);
  opacity: 0.5;
  border-radius: var(--radius-full);
}

.modal-scrollable-content {
  overflow-y: auto;
  padding: 6px 18px calc(24px + var(--tg-safe-area-inset-bottom)) 18px;
  -webkit-overflow-scrolling: touch;
}

.modal-video-box {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  margin-bottom: 14px;
  border: 1px solid var(--tg-border-color);
}

.modal-video-box video {
  width: 100%;
  max-height: 260px;
  display: block;
}

.modal-title-wrapper {
  margin-bottom: 10px;
}

.modal-title-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 0;
  line-height: 1.25;
  color: var(--tg-theme-text-color);
  flex: 1;
}

.title-action-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.title-btn-action {
  background: var(--tg-theme-secondary-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  color: var(--tg-theme-hint-color);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.title-btn-action:active {
  transform: scale(0.92);
}

.ai-action-btn {
  background: linear-gradient(135deg, rgba(255, 107, 44, 0.15), rgba(147, 51, 234, 0.15));
  border: 1px solid rgba(255, 107, 44, 0.3);
  color: #ff6b2c;
  font-size: 0.95rem;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
}

.ai-action-btn:hover {
  border-color: #ff6b2c;
}

.ai-action-btn.loading {
  animation: pulseAi 1s infinite alternate;
  pointer-events: none;
  opacity: 0.7;
}

@keyframes pulseAi {
  from { transform: scale(1); filter: brightness(1); }
  to { transform: scale(1.08); filter: brightness(1.3); }
}

.modal-title-edit-box {
  margin-top: 8px;
  background: var(--tg-theme-secondary-bg-color);
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--tg-border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.title-edit-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--tg-theme-button-color, #ff6b2c);
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  outline: none;
  box-sizing: border-box;
}

.title-edit-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-save-title {
  background: var(--tg-theme-button-color, #ff6b2c);
  color: var(--tg-theme-button-text-color, #ffffff);
  border: none;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-cancel-title {
  background: transparent;
  color: var(--tg-theme-hint-color);
  border: 1px solid var(--tg-border-color);
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.modal-source-row {
  margin: 2px 0 12px 0;
  display: flex;
  align-items: center;
}

.instagram-source-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  background: linear-gradient(135deg, rgba(225, 48, 108, 0.12), rgba(253, 29, 29, 0.12));
  color: #e1306c;
  border: 1px solid rgba(225, 48, 108, 0.25);
  transition: all 0.15s ease;
  cursor: pointer;
}

.instagram-source-link:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.instagram-source-link .instagram-icon {
  flex-shrink: 0;
  fill: #e1306c;
}

.old-recipe-source-hint {
  font-size: 0.78rem;
  color: var(--tg-theme-hint-color);
  background: var(--tg-theme-secondary-bg-color);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--tg-border-color);
  display: inline-block;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.modal-tags:empty {
  display: none;
}

.section-heading {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 18px 0 10px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--tg-theme-text-color);
}

/* Interactive Checklist */
.checklist {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius-md);
  padding: 6px 14px;
  border: 1px solid var(--tg-border-color);
}

.check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--tg-border-color);
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease;
}

.check-item:last-child {
  border-bottom: none;
}

.check-item:active {
  opacity: 0.8;
}

.check-box {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--tg-theme-hint-color);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.check-item.checked .check-box {
  background: var(--tg-theme-button-color);
  border-color: var(--tg-theme-button-color);
}

.check-item.checked .check-box::after {
  content: '✓';
  color: var(--tg-theme-button-text-color);
  font-size: 13px;
  font-weight: bold;
}

.check-text {
  font-size: 0.92rem;
  color: var(--tg-theme-text-color);
  transition: all 0.15s ease;
}

.check-item.checked .check-text {
  color: var(--tg-theme-hint-color);
  text-decoration: line-through;
}

/* Steps List */
.steps-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-card {
  background: var(--tg-theme-secondary-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  gap: 12px;
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--tg-badge-bg);
  color: var(--tg-theme-button-color);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.step-text {
  font-size: 0.9rem;
  color: var(--tg-theme-text-color);
  line-height: 1.5;
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-instagram-action {
  flex: 1 1 100%;
  background: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  box-shadow: 0 3px 10px rgba(225, 48, 108, 0.25);
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn-instagram-action:active {
  opacity: 0.88;
  transform: scale(0.985);
}

.card-ig-link {
  font-size: 0.72rem;
  font-weight: 600;
  color: #e1306c;
  background: rgba(225, 48, 108, 0.1);
  border: 1px solid rgba(225, 48, 108, 0.25);
  padding: 2px 7px;
  border-radius: 6px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: all 0.15s ease;
}

.card-ig-link:active {
  transform: scale(0.95);
  background: rgba(225, 48, 108, 0.2);
}

.btn-primary {
  flex: 1;
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  border: none;
  border-radius: var(--radius-md);
  padding: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 3px 10px rgba(36, 129, 204, 0.25);
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn-primary:active {
  opacity: 0.88;
  transform: scale(0.985);
}

.raw-description-box {
  background: var(--tg-theme-secondary-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 0.9rem;
  color: var(--tg-theme-text-color);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-text-accordion {
  margin-top: 14px;
  background: var(--tg-theme-secondary-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all 0.2s ease;
}

.accordion-summary {
  padding: 12px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--tg-theme-hint-color);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.accordion-summary:active {
  background: var(--tg-border-color);
}

.accordion-content {
  padding: 0 14px 14px 14px;
  font-size: 0.88rem;
  color: var(--tg-theme-text-color);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid var(--tg-border-color);
  margin-top: 6px;
  padding-top: 10px;
}

/* Modal Tag Manager & Editing */
.modal-tags-container {
  margin-bottom: 16px;
}

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

.modal-tags-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--tg-theme-hint-color);
}

.modal-tags-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.modal-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-link-color);
  border: 1px solid var(--tg-border-color);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  transition: all 0.15s ease;
}

.modal-tag-chip:hover {
  border-color: var(--tg-theme-link-color);
}

.tag-remove-btn {
  background: transparent;
  border: none;
  color: var(--tg-theme-hint-color);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.15s ease;
}

.tag-remove-btn:hover,
.tag-remove-btn:active {
  color: var(--tg-theme-destructive-text-color);
  transform: scale(1.2);
}

.add-tag-trigger-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 1px dashed var(--tg-theme-link-color);
  color: var(--tg-theme-link-color);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.15s ease;
}

.add-tag-trigger-btn:active {
  background: var(--tg-badge-bg);
  transform: scale(0.96);
}

.add-tag-box {
  width: 100%;
  margin-top: 10px;
  background: var(--tg-theme-secondary-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: slideUp 0.15s ease;
}

.add-tag-input-row {
  display: flex;
  gap: 8px;
}

.add-tag-input {
  flex: 1;
  background: var(--tg-theme-section-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 16px; /* Prevents auto zoom in iOS */
  color: var(--tg-theme-text-color);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.add-tag-input:focus {
  border-color: var(--tg-theme-button-color);
}

.btn-submit-tag {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}

.btn-submit-tag:active {
  opacity: 0.85;
}

.btn-cancel-tag {
  background: transparent;
  border: 1px solid var(--tg-border-color);
  color: var(--tg-theme-hint-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

.quick-tags-title {
  font-size: 0.75rem;
  color: var(--tg-theme-hint-color);
  font-weight: 600;
}

.quick-tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-tag-chip {
  background: var(--tg-theme-section-bg-color);
  border: 1px solid var(--tg-border-color);
  color: var(--tg-theme-text-color);
  border-radius: var(--radius-full);
  padding: 3px 9px;
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-tag-chip:active {
  background: var(--tg-badge-bg);
  border-color: var(--tg-theme-link-color);
  color: var(--tg-theme-link-color);
  transform: scale(0.96);
}

/* Delete Button in Modal */
.btn-danger {
  flex: 1;
  background: rgba(255, 59, 48, 0.10);
  color: var(--tg-theme-destructive-text-color);
  border: 1px solid rgba(255, 59, 48, 0.28);
  border-radius: var(--radius-md);
  padding: 14px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.btn-danger:active {
  background: rgba(255, 59, 48, 0.20);
  transform: scale(0.985);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: calc(16px + var(--tg-safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
  width: max-content;
  max-width: 90%;
}

.toast {
  background: rgba(28, 28, 30, 0.94);
  color: #ffffff;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1), toastOut 0.3s ease 2.2s forwards;
  display: flex;
  align-items: center;
  gap: 8px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-8px) scale(0.94); }
}

/* Custom Confirmation Dialog (Fallback & Desktop) */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

.confirm-dialog {
  background: var(--tg-theme-section-bg-color);
  border: 1px solid var(--tg-border-color);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  max-width: 330px;
  width: 100%;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.confirm-title {
  font-family: var(--font-heading);
  font-size: 1.18rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--tg-theme-text-color);
}

.confirm-desc {
  font-size: 0.88rem;
  color: var(--tg-theme-hint-color);
  margin-bottom: 20px;
  line-height: 1.45;
}

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

.btn-confirm-cancel {
  flex: 1;
  background: var(--tg-theme-secondary-bg-color);
  border: 1px solid var(--tg-border-color);
  color: var(--tg-theme-text-color);
  border-radius: var(--radius-md);
  padding: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-confirm-cancel:active {
  filter: brightness(0.95);
}

.btn-confirm-delete {
  flex: 1;
  background: var(--tg-theme-destructive-text-color);
  border: none;
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-confirm-delete:active {
  filter: brightness(0.9);
}

