/* Polyscopea - Story Intelligence Platform */
/* Design Tokens & Custom Styles */

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

::selection {
    background: #8E3B46;
    color: white;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #8E3B46; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #6d2d36; }

/* ---- Navigation ---- */
.nav-link {
    @apply px-3 py-2 text-sm font-medium rounded-lg transition-colors;
    @apply hover:bg-black/5 dark:hover:bg-white/10;
    @apply text-ink-secondary dark:text-[#A0A0A0];
}
.nav-link.active {
    @apply text-accent-primary dark:text-accent-primary font-semibold;
    @apply bg-accent-primary/5;
}

/* ---- Cards ---- */
.story-card {
    @apply bg-white dark:bg-white/5 rounded-2xl border border-black/5 dark:border-white/10;
    @apply p-6 transition-all duration-300 hover:shadow-lg hover:border-black/10 dark:hover:border-white/20;
    @apply hover:-translate-y-0.5;
}

.stat-card {
    @apply bg-white dark:bg-white/5 rounded-xl border border-black/5 dark:border-white/10 p-5;
}

/* ---- Sector Badges ---- */
.sector-badge {
    @apply inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold uppercase tracking-wider;
}
.sector-badge.markets { @apply bg-sector-markets/10 text-sector-markets; }
.sector-badge.tech { @apply bg-sector-tech/10 text-sector-tech; }
.sector-badge.regulation { @apply bg-sector-regulation/10 text-sector-regulation; }
.sector-badge.venture { @apply bg-sector-venture/10 text-sector-venture; }
.sector-badge.geopolitics { @apply bg-accent-primary/10 text-accent-primary; }
.sector-badge.energy { @apply bg-sector-energy/10 text-sector-energy; }
.sector-badge.health { @apply bg-trust-verified/10 text-trust-verified; }
.sector-badge.general { @apply bg-gray-500/10 text-gray-500; }

/* ---- Trust Indicators ---- */
.trust-badge {
    @apply inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold;
}
.trust-high { @apply bg-trust-updated/10 text-trust-updated; }
.trust-medium { @apply bg-sector-venture/10 text-sector-venture; }
.trust-low { @apply bg-trust-risk/10 text-trust-risk; }

/* ---- Timeline ---- */
.timeline-line {
    @apply absolute top-0 bottom-0 w-0.5 bg-black/10 dark:bg-white/10;
    left: 7px;
}
[dir="rtl"] .timeline-line {
    left: auto;
    right: 7px;
}

.timeline-dot {
    @apply w-4 h-4 rounded-full border-2 border-accent-primary bg-paper-light dark:bg-paper-dark;
    @apply flex-shrink-0 relative z-10;
}
.timeline-dot.breaking {
    @apply border-red-500 bg-red-500;
    animation: pulse-dot 2s ease-in-out infinite;
}
.timeline-dot.high { @apply border-accent-primary bg-accent-primary; }

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ---- Buttons ---- */
.btn-primary {
    @apply px-6 py-2.5 bg-accent-primary text-white rounded-xl font-medium text-sm;
    @apply hover:bg-accent-primary/90 transition-all duration-200 active:scale-[0.98];
    @apply focus:outline-none focus:ring-2 focus:ring-accent-primary/30;
}
.btn-secondary {
    @apply px-6 py-2.5 bg-black/5 dark:bg-white/10 rounded-xl font-medium text-sm;
    @apply hover:bg-black/10 dark:hover:bg-white/15 transition-all duration-200 active:scale-[0.98];
}
.btn-outline {
    @apply px-6 py-2.5 border border-black/10 dark:border-white/20 rounded-xl font-medium text-sm;
    @apply hover:bg-black/5 dark:hover:bg-white/10 transition-all duration-200;
}

/* ---- Forms ---- */
.form-input {
    @apply w-full px-4 py-3 rounded-xl bg-white dark:bg-white/5;
    @apply border border-black/10 dark:border-white/15;
    @apply text-ink-primary dark:text-[#F4F2EE] text-sm;
    @apply focus:outline-none focus:ring-2 focus:ring-accent-primary/30 focus:border-accent-primary;
    @apply transition-all duration-200;
    @apply placeholder:text-ink-secondary/50 dark:placeholder:text-[#A0A0A0]/50;
}
.form-label {
    @apply block text-sm font-medium text-ink-primary dark:text-[#F4F2EE] mb-1.5;
}
.form-select {
    @apply form-input appearance-none cursor-pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 2.5rem;
}

/* ---- Agent Cards ---- */
.agent-card {
    @apply bg-white dark:bg-white/5 rounded-2xl border border-black/5 dark:border-white/10;
    @apply p-6 transition-all duration-300;
    @apply hover:shadow-lg hover:border-accent-primary/30;
}
.agent-status {
    @apply inline-flex items-center gap-1.5 text-xs font-medium;
}
.agent-status.running {
    @apply text-trust-updated;
}
.agent-status.running::before {
    content: '';
    @apply w-2 h-2 rounded-full bg-trust-updated;
    animation: pulse-status 2s ease-in-out infinite;
}
.agent-status.idle { @apply text-ink-secondary; }
.agent-status.idle::before {
    content: '';
    @apply w-2 h-2 rounded-full bg-ink-secondary;
}

@keyframes pulse-status {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ---- Hero Section ---- */
.hero-gradient {
    background: linear-gradient(135deg, #8E3B46 0%, #4B2A7A 50%, #214E8A 100%);
}

/* ---- RTL Support ---- */
[dir="rtl"] .form-select {
    background-position: left 12px center;
    padding-right: 1rem;
    padding-left: 2.5rem;
}

/* ---- Loading & Animations ---- */
.skeleton {
    @apply bg-black/5 dark:bg-white/10 rounded-lg animate-pulse;
}

.fade-in {
    animation: fadeIn 0.5s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Dashboard ---- */
.dash-stat {
    @apply bg-white dark:bg-white/5 rounded-xl p-5 border border-black/5 dark:border-white/10;
}

.review-status {
    @apply inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium;
}
.review-status.approved { @apply bg-trust-updated/10 text-trust-updated; }
.review-status.pending { @apply bg-sector-venture/10 text-sector-venture; }
.review-status.rejected { @apply bg-trust-risk/10 text-trust-risk; }
.review-status.revision_needed { @apply bg-accent-secondary/10 text-accent-secondary; }

/* ---- Toast Notifications ---- */
.toast {
    @apply fixed bottom-4 right-4 z-50 px-6 py-3 rounded-xl text-sm font-medium shadow-xl;
    @apply transform transition-all duration-300;
    animation: slideUp 0.3s ease-out;
}
.toast.success { @apply bg-trust-updated text-white; }
.toast.error { @apply bg-trust-risk text-white; }
.toast.info { @apply bg-accent-secondary text-white; }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Responsive Adjustments ---- */
@media (max-width: 640px) {
    .story-card { @apply p-4; }
    .hero-gradient { @apply py-16; }
}

/* ---- Scroll Reveal Animations ---- */
.reveal,
.reveal-left,
.reveal-right,
.reveal-scale {
    opacity: 0;
    transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: opacity, transform;
}
.reveal { transform: translateY(30px); }
.reveal-left { transform: translateX(-40px); }
.reveal-right { transform: translateX(40px); }
.reveal-scale { transform: scale(0.92); }

.reveal.revealed,
.reveal-left.revealed,
.reveal-right.revealed,
.reveal-scale.revealed {
    opacity: 1;
    transform: translateY(0) translateX(0) scale(1);
}

/* RTL: swap directional reveals */
[dir="rtl"] .reveal-left { transform: translateX(40px); }
[dir="rtl"] .reveal-right { transform: translateX(-40px); }
[dir="rtl"] .reveal-left.revealed,
[dir="rtl"] .reveal-right.revealed { transform: translateX(0); }

/* Stagger children - sequential reveal */
.stagger-children > * {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.stagger-children.revealed > *:nth-child(1) { transition-delay: 0.05s; }
.stagger-children.revealed > *:nth-child(2) { transition-delay: 0.1s; }
.stagger-children.revealed > *:nth-child(3) { transition-delay: 0.15s; }
.stagger-children.revealed > *:nth-child(4) { transition-delay: 0.2s; }
.stagger-children.revealed > *:nth-child(5) { transition-delay: 0.25s; }
.stagger-children.revealed > *:nth-child(6) { transition-delay: 0.3s; }
.stagger-children.revealed > *:nth-child(7) { transition-delay: 0.35s; }
.stagger-children.revealed > *:nth-child(8) { transition-delay: 0.4s; }
.stagger-children.revealed > *:nth-child(9) { transition-delay: 0.45s; }
.stagger-children.revealed > *:nth-child(10) { transition-delay: 0.5s; }
.stagger-children.revealed > *:nth-child(11) { transition-delay: 0.55s; }
.stagger-children.revealed > *:nth-child(12) { transition-delay: 0.6s; }
.stagger-children.revealed > * {
    opacity: 1;
    transform: translateY(0);
}

/* Page enter animation — uses forwards fill so main is visible after anim */
main#main-content {
    opacity: 1; /* Fallback: always visible */
    animation: pageEnter 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes pageEnter {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Micro-interactions ---- */
.hover-lift {
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.3s ease;
}
.hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px -8px rgba(0,0,0,0.12);
}
[data-theme="dark"] .hover-lift:hover {
    box-shadow: 0 12px 24px -8px rgba(0,0,0,0.4);
}

.hover-glow {
    transition: box-shadow 0.3s ease;
}
.hover-glow:hover {
    box-shadow: 0 0 20px rgba(142, 59, 70, 0.25);
}

.link-underline {
    position: relative;
    text-decoration: none;
}
.link-underline::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: #8E3B46;
    transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
[dir="rtl"] .link-underline::after {
    left: auto;
    right: 0;
}
.link-underline:hover::after {
    width: 100%;
}

/* ---- Navbar scroll transition ---- */
#main-navbar {
    transition: box-shadow 0.3s ease, background-color 0.3s ease;
}

/* ---- Glassmorphism ---- */
.glass {
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}
[data-theme="dark"] .glass {
    background: rgba(17, 20, 23, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ---- Enhanced story-card hover ---- */
.story-card {
    position: relative;
    overflow: hidden;
}
.story-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, transparent 40%, rgba(142, 59, 70, 0.3) 100%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}
.story-card:hover::before {
    opacity: 1;
}

/* ---- Custom scrollbar (dark mode) ---- */
[data-theme="dark"] ::-webkit-scrollbar-track { background: #111417; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #333; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #555; }

/* ---- Focus-visible ---- */
*:focus-visible {
    outline: 2px solid #8E3B46;
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---- Button pressed state ---- */
.btn-primary:active,
.btn-secondary:active,
.btn-outline:active {
    transform: scale(0.97);
    transition-duration: 0.1s;
}

/* ---- Floating animation (decorative) ---- */
@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-6px); }
}
.animate-float {
    animation: float 3s ease-in-out infinite;
}

/* ---- Gradient shift animation ---- */
@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
.animate-gradient {
    background-size: 200% 200%;
    animation: gradientShift 8s ease infinite;
}

/* ---- Counter number animation ---- */
.count-up {
    display: inline-block;
    font-variant-numeric: tabular-nums;
}

/* ---- Accessibility: Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .reveal,
    .reveal-left,
    .reveal-right,
    .reveal-scale {
        opacity: 1 !important;
        transform: none !important;
    }
    .stagger-children > * {
        opacity: 1 !important;
        transform: none !important;
        transition-delay: 0s !important;
    }
    main#main-content {
        animation: none !important;
    }
    .hover-lift:hover {
        transform: none !important;
    }
}

/* ---- Dropdown Panel System ---- */
.dropdown-panel {
    display: none;
    animation: dropdownIn 0.15s ease-out;
}
.dropdown-panel.active {
    display: block;
}
.dropdown-panel::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
}
@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
[dir="rtl"] .dropdown-panel::before {
    left: 0;
    right: 0;
}

/* ---- Trust Score Circle Animation ---- */
.trust-circle-animate circle.trust-fill {
    transition: stroke-dasharray 1.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Dashboard Stat Card Accents ---- */
.stat-card {
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--stat-accent, #8E3B46);
    border-radius: 12px 12px 0 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}
[dir="rtl"] .stat-card::before {
    left: auto;
    right: 0;
}
.stat-card:hover::before {
    opacity: 1;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

/* ---- Activity Dot Pulse ---- */
.activity-dot-recent {
    position: relative;
}
.activity-dot-recent::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background: #2E7D32;
    border-radius: 50%;
    animation: activityPulse 2s ease-in-out infinite;
}
@keyframes activityPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.4); }
}

/* ---- Print ---- */
@media print {
    nav, footer, .no-print { display: none !important; }
    body { background: white !important; color: black !important; }
}
