/* =========================================================
   AI TIME-MACHINE — Sci-Fi Portal UI
   Low-GPU-impact version
========================================================= */

/* ------ Trigger Button (no heavy animations) ------ */
.tm-trigger-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem !important;
  font-size: 1.15rem !important;
  font-weight: 900;
  background: linear-gradient(135deg, var(--violet-600), var(--azure-800), var(--cyan-500)) !important;
  color: white !important;
  border: none !important;
  border-radius: 0.625rem !important;
  box-shadow: 0 0 0.75rem rgba(124, 58, 237, 0.3);
  cursor: pointer;
  transition: all 0.3s ease;
}

.tm-trigger-btn:hover {
  transform: scale(1.05) !important;
  box-shadow: 0 0 1.5rem rgba(124, 58, 237, 0.5) !important;
}

.tm-btn-icon {
  font-size: 1.4rem;
}

.tm-btn-text {
  font-weight: 900;
}

/* ------ Era Header Badge ------ */
.tm-era-header-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.625rem 1.5rem;
  background: linear-gradient(
    135deg,
    rgba(80, 58, 237, 0.4),
    rgba(37, 99, 235, 0.4)
  );
  border: 0.0625rem solid rgba(124, 58, 237, 0.5);
  box-shadow: 0 0 1rem rgba(100, 100, 255, 0.4);
  border-radius: 0.5rem;
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--violet-200);
  white-space: nowrap;
}

.tm-era-header-badge::before {
  content: "";
  display: inline-block;
  width: 1.4rem;
  height: 1.4rem;
  background-color: currentColor;
  -webkit-mask: url("../assets/icons/calendar-event.svg") no-repeat center;
  mask: url("../assets/icons/calendar-event.svg") no-repeat center;
  -webkit-mask-size: contain;
  mask-size: contain;
  vertical-align: -0.2rem;
  margin-inline-end: 0.35rem;
}

/* ------ Modal ------ */
.tm-modal .tm-modal-content {
  max-width: 95%;
  width: 95%;
  max-height: 90vh;
  min-height: 90vh;
  overflow-y: auto;
  padding: 2.5rem;
  position: relative;
  background: linear-gradient(
    135deg,
    rgba(13, 17, 23, 0.97),
    rgba(30, 20, 60, 0.95)
  ) !important;
  border: 0.0625rem solid rgba(124, 58, 237, 0.3) !important;
  box-shadow: 0 0 1.5rem rgba(124, 58, 237, 0.15) !important;
  will-change: transform, opacity;
}

.tm-close-btn {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: none;
  font-size: 2.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: bold;
  line-height: 1;
  z-index: 10;
  transition: color 0.2s;
}

.tm-close-btn:hover {
  color: var(--danger-color);
}

/* ------ Loading Phase ------ */
.tm-loading-phase {
  text-align: center;
  padding: 3rem 1rem;
}

.tm-portal-ring {
  width: 12rem;
  height: 12rem;
  margin: 0 auto 2rem;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    var(--violet-600),
    var(--azure-800),
    var(--cyan-500),
    var(--emerald-600),
    var(--violet-600)
  );
  padding: 0.375rem;
  animation: tmPortalSpin 2s linear infinite;
  box-shadow: 0 0 1rem rgba(124, 58, 237, 0.3);
}

.tm-portal-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(30, 20, 60, 0.9),
    rgba(13, 17, 23, 1)
  );
  display: flex;
  align-items: center;
  justify-content: center;
}

.tm-hourglass {
  font-size: 4rem;
  animation: tmHourglassFlip 1.5s ease-in-out infinite;
}

@keyframes tmPortalSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes tmHourglassFlip {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  50% {
    transform: rotate(180deg) scale(1.15);
  }
}

.tm-loading-title {
  font-size: 2rem;
  font-weight: 900;
  background: linear-gradient(90deg, var(--violet-600), var(--azure-800), var(--cyan-500));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.75rem;
}

.tm-loading-sub {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
}

.tm-era-badge {
  display: inline-block;
  padding: 0.4rem 1.2rem;
  background: rgba(124, 58, 237, 0.15);
  border: 0.0625rem solid rgba(124, 58, 237, 0.3);
  border-radius: 1.5rem;
  color: var(--violet-400);
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 1.5rem;
}

.tm-year-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.tm-year-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.tm-year-scroll {
  font-size: 3rem;
  font-weight: 900;
  font-family: "Segoe UI", monospace;
  color: var(--cyan-500);
  text-shadow: 0 0 0.5rem rgba(6, 182, 212, 0.5);
  min-height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tm-year-flip {
  animation: tmYearPop 0.35s ease-out;
}

@keyframes tmYearPop {
  0% {
    transform: translateY(-1.5rem);
    opacity: 0;
  }
  70% {
    transform: translateY(0.15rem);
    opacity: 1;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ------ Reveal Phase ------ */
.tm-reveal-phase {
  animation: tmRevealFade 0.6s ease-out;
}

@keyframes tmRevealFade {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.tm-reveal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.tm-time-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  background: rgba(124, 58, 237, 0.15);
  border: 0.0625rem solid rgba(124, 58, 237, 0.4);
  border-radius: 2rem;
  font-size: 1.1rem;
  color: var(--violet-400);
}

.tm-time-icon {
  font-size: 1.3rem;
}

.tm-era-arrived {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  background: rgba(6, 182, 212, 0.12);
  border: 0.0625rem solid rgba(6, 182, 212, 0.4);
  border-radius: 2rem;
  font-size: 1rem;
  color: var(--cyan-300);
  font-weight: bold;
}

.tm-ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.9rem;
  border-radius: 1rem;
  font-size: 0.85rem;
  font-weight: bold;
}

.tm-ai-badge.powered {
  background: rgba(16, 185, 129, 0.15);
  border: 0.0625rem solid rgba(16, 185, 129, 0.4);
  color: var(--emerald-300);
}

.tm-ai-badge.local {
  background: rgba(210, 153, 34, 0.15);
  border: 0.0625rem solid rgba(210, 153, 34, 0.4);
  color: var(--amber-400);
}

.tm-scenario-title {
  font-size: clamp(2.2rem, 3.5rem, 4rem);
  font-weight: 900;
  text-align: center;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, var(--violet-100), var(--violet-300), var(--violet-600));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.5;
}

.tm-narrative {
  background: rgba(255, 255, 255, 0.04);
  border: 0.0625rem solid rgba(255, 255, 255, 0.08);
  border-radius: 0.75rem;
  padding: 2rem;
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
  line-height: 1.9;
  color: var(--text-primary);
  text-align: right;
}

.tm-breaking-news {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: rgba(248, 81, 73, 0.1);
  border: 0.0625rem solid rgba(248, 81, 73, 0.3);
  border-radius: 0.75rem;
  margin-bottom: 1.5rem;
}

.tm-bn-tag {
  flex-shrink: 0;
  background: var(--danger-color);
  color: white;
  padding: 0.35rem 0.85rem;
  border-radius: 0.375rem;
  font-weight: bold;
  font-size: 1.05rem;
  white-space: nowrap;
}

.tm-bn-text {
  color: var(--danger-color);
  font-weight: bold;
  font-size: 1.4rem;
}

.tm-effects-title {
  font-size: 1.8rem;
  font-weight: 900;
  text-align: center;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
}

.tm-effects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.tm-effect-card {
  border-radius: 0.75rem;
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.3s ease;
}

.tm-effect-card:hover {
  transform: translateY(-0.25rem);
}

.tm-effect-card.up {
  background: rgba(16, 185, 129, 0.08);
  border: 0.0625rem solid rgba(16, 185, 129, 0.3);
}

.tm-effect-card.down {
  background: rgba(248, 81, 73, 0.08);
  border: 0.0625rem solid rgba(248, 81, 73, 0.3);
}

.tm-effect-card.neutral {
  background: rgba(139, 148, 158, 0.08);
  border: 0.0625rem solid rgba(139, 148, 158, 0.3);
}

.tm-effect-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.tm-effect-name {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--text-primary);
}

.tm-effect-sector {
  font-size: 1rem;
  color: var(--text-secondary);
  padding: 0.15rem 0.5rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0.3rem;
}

.tm-effect-change {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.tm-effect-icon {
  font-size: 1.8rem;
}

.tm-effect-card.up .tm-effect-icon,
.tm-effect-card.up .tm-effect-percent {
  color: var(--emerald-300);
}

.tm-effect-card.down .tm-effect-icon,
.tm-effect-card.down .tm-effect-percent {
  color: var(--rose-400);
}

.tm-effect-card.neutral .tm-effect-icon,
.tm-effect-card.neutral .tm-effect-percent {
  color: var(--text-secondary);
}

.tm-effect-percent {
  font-size: 2.2rem;
  font-weight: 900;
}

.tm-effect-prices {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.tm-price-old {
  color: var(--text-secondary);
  text-decoration: line-through;
  opacity: 0.7;
}

.tm-price-arrow {
  color: var(--text-secondary);
  font-size: 1.5rem;
}

.tm-price-new {
  font-weight: bold;
  color: var(--text-primary);
  font-size: 1.45rem;
}

.tm-price-diff {
  font-size: 1.1rem;
  font-weight: bold;
  opacity: 0.8;
}
.tm-price-diff.up {
  color: var(--emerald-300);
}
.tm-price-diff.down {
  color: var(--rose-400);
}
.tm-price-diff.neutral {
  color: var(--text-secondary);
}

.tm-effect-reason {
  font-size: 1.1rem;
  color: var(--text-secondary);
  line-height: 1.6;
  border-top: 0.0625rem solid rgba(255, 255, 255, 0.06);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

.tm-apply-btn {
  display: block;
  width: 100%;
  padding: 1rem 2rem !important;
  font-size: 1.4rem !important;
  font-weight: 900;
  background: linear-gradient(135deg, var(--violet-600), var(--azure-800)) !important;
  color: white;
  border: none !important;
  border-radius: 0.75rem !important;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 0 1.5rem rgba(124, 58, 237, 0.3);
}

.tm-apply-btn:hover {
  transform: translateY(-0.15rem);
  box-shadow: 0 0 2.5rem rgba(124, 58, 237, 0.5) !important;
}

/* ------ Verification Summary Table (Compact) ------ */
.tm-verify-table {
  margin: 0 auto 1.5rem auto;
  max-width: 38rem;
  background: rgba(255, 255, 255, 0.03);
  border: 0.0625rem solid rgba(255, 255, 255, 0.08);
  border-radius: 0.75rem;
  overflow: hidden;
}

.tm-verify-table summary {
  cursor: pointer;
  padding: 0.65rem 1rem;
  font-weight: 900;
  font-size: 1rem;
  color: var(--text-primary);
  background: rgba(124, 58, 237, 0.08);
  border-bottom: 0.0625rem solid rgba(255, 255, 255, 0.06);
  user-select: none;
}

.tm-verify-table summary:hover {
  background: rgba(124, 58, 237, 0.12);
}

.tm-verify-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.25rem;
  table-layout: fixed;
}

.tm-verify-table th {
  padding: 0.6rem 0.75rem;
  text-align: right;
  color: var(--text-secondary);
  font-weight: bold;
  font-size: 1.05rem;
  background: rgba(0, 0, 0, 0.15);
}

.tm-verify-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 0.0625rem solid rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.tm-verify-table th:first-child,
.tm-verify-table td:first-child {
  text-align: right;
  width: 25%;
  font-weight: bold;
}

.tm-verify-table th:nth-child(2),
.tm-verify-table td:nth-child(2) {
  width: 20%;
  text-align: right;
}

.tm-verify-table th:nth-child(3),
.tm-verify-table td:nth-child(3) {
  width: 20%;
  text-align: right;
}

.tm-verify-table th:nth-child(4),
.tm-verify-table td:nth-child(4) {
  width: 35%;
  text-align: left;
  padding-left: 1.5rem;
}

.tm-verify-table td.up {
  color: var(--emerald-300);
  font-weight: 900;
}
.tm-verify-table td.down {
  color: var(--rose-400);
  font-weight: 900;
}
.tm-verify-table td.neutral {
  color: var(--text-secondary);
}

.tm-verify-table tr:hover td {
  background: rgba(124, 58, 237, 0.06);
}

/* ------ Light Theme Overrides ------ */
.light-theme .tm-trigger-btn {
  box-shadow: 0 0 0.75rem rgba(124, 58, 237, 0.2);
}

.light-theme .tm-modal-content {
  background: linear-gradient(
    135deg,
    rgba(250, 250, 255, 0.98),
    rgba(237, 233, 254, 0.95)
  ) !important;
  box-shadow: 0 0 3.75rem rgba(124, 58, 237, 0.15);
}

.light-theme .tm-loading-title {
  background: linear-gradient(90deg, var(--violet-700), var(--azure-800), var(--cyan-600));
  -webkit-background-clip: text;
  background-clip: text;
}

.light-theme .tm-portal-inner {
  background: radial-gradient(
    circle,
    rgba(250, 250, 255, 0.95),
    rgba(237, 233, 254, 1)
  );
}

.light-theme .tm-scenario-title {
  background: linear-gradient(135deg, var(--violet-900), var(--violet-700), var(--violet-600));
  -webkit-background-clip: text;
  background-clip: text;
}

.light-theme .tm-narrative {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
}

.light-theme .tm-era-header-badge {
  background: linear-gradient(
    135deg,
    rgba(124, 58, 237, 0.1),
    rgba(37, 99, 235, 0.1)
  );
  color: var(--violet-700);
}

/* ------ Mobile and Small Screen Responsiveness ------ */
@media (max-width: 48rem) {
  .tm-modal .tm-modal-content {
    padding: 1.25rem;
    width: 100%;
    max-width: 100%;
    /* min-height: 90vh الأساسي يجعل النافذة تملأ الشاشة على الجوال */
    min-height: 0;
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
  }

  .tm-effects-grid {
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
    gap: 0.75rem;
  }

  .tm-scenario-title {
    font-size: clamp(1.25rem, 4vw, 2.8rem);
  }

  .tm-narrative {
    font-size: 1rem;
    padding: 1rem;
  }

  .tm-effect-card {
    padding: 0.875rem;
  }

  .tm-effect-percent {
    font-size: 1.35rem;
  }

  .tm-reveal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .tm-breaking-news {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .tm-bn-tag {
    align-self: flex-start;
  }
}

@media (max-width: 30rem) {
  .tm-effects-grid {
    grid-template-columns: 1fr;
  }

  .tm-verify-table {
    overflow-x: auto;
  }

  .tm-verify-table table {
    min-width: 32rem; /* allows scrolling inside the table on very small screens */
  }

  .tm-effect-prices {
    flex-wrap: wrap;
  }

  .tm-price-diff {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
  }

  .tm-portal-ring {
    width: 8rem;
    height: 8rem;
  }

  .tm-hourglass {
    font-size: 2.5rem;
  }
}
