/* Additional CSS for ALPHV Kiralytics™ Emosi Dashboard */

:root {
    --color-brand: #1e40af;
    --color-brand-hover: #1d4ed8;
    --color-brand-deep: #172554;
    --color-focus: #1e40af;
    --color-surface: #ffffff;
    --color-surface-muted: #f8fafc;
    --color-text: #1f2937;
    --color-text-muted: #475569;
    --color-border: #e2e8f0;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface-muted);
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Smooth transitions */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
}

::selection {
    background: #bfdbfe;
    color: var(--color-brand-deep);
}

/* Hover effects for cards */
.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Animation for stats cards */
@keyframes countUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-count {
    animation: countUp 0.6s ease-out;
}

/* Custom checkbox styles */
input[type="checkbox"]:checked {
    background-color: var(--color-brand);
    border-color: var(--color-brand);
}

/* Sidebar navigation hover effects */
.nav-item {
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

.nav-item:hover::before {
    left: 100%;
}

/* Social media platform icons styling */
.platform-icon {
    transition: transform 0.2s ease-in-out;
}

.platform-icon:hover {
    transform: scale(1.1);
}

/* Custom table styles */
.table-row:hover {
    background-color: #f8fafc;
}

/* Responsive design improvements */
@media (max-width: 768px) {
    #sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
    }
    
    #sidebar.mobile-open {
        transform: translateX(0);
    }
    
    #sidebar.collapsed {
        transform: translateX(-100%);
    }
    
    #mainContent {
        margin-left: 0 !important;
    }
    
    #mainContent.expanded {
        margin-left: 0 !important;
    }
    
    .chart-container {
        height: 250px !important;
    }
}

/* Custom focus styles */
:where(a, button, select, input, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

/* Improved button styles */
.btn-primary {
    background: var(--color-brand);
    border: none;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.btn-primary:hover {
    background: var(--color-brand-hover);
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(30, 64, 175, 0.3);
}

/* Data visualization enhancements */
.metric-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid #e2e8f0;
}

.metric-card.positive {
    border-color: #a7f3d0;
}

.metric-card.negative {
    border-color: #fecaca;
}

.metric-card.neutral {
    border-color: #cbd5e1;
}

.metric-card.warning {
    border-color: #fde68a;
}

/* Interactive elements */
.interactive:hover {
    cursor: pointer;
    background-color: rgba(59, 130, 246, 0.1);
}

/* Sidebar collapse styles */
#sidebar {
    overflow-x: hidden;
    overflow-y: auto;
}

#sidebar.collapsed {
    width: 4rem;
}

#sidebar.collapsed .sidebar-text {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out, transform 0.3s ease-in-out;
    position: absolute;
    width: 0;
    overflow: hidden;
}

#sidebar.collapsed .platform-checkbox {
    opacity: 0;
    visibility: hidden;
    width: 0;
    margin: 0;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out, width 0.3s ease-in-out, margin 0.3s ease-in-out;
    position: absolute;
}

#sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.75rem;
    margin: 0.25rem auto;
    width: 3rem;
    display: flex;
    align-items: center;
    position: relative;
}

#sidebar.collapsed .nav-item i {
    margin: 0 !important;
    font-size: 1.25rem;
}

#sidebar.collapsed .platform-icon {
    margin-left: 0 !important;
    margin-right: 0 !important;
    font-size: 1.25rem;
}

#sidebar.collapsed label {
    justify-content: center;
    padding: 0.5rem;
    width: 3rem;
    display: flex;
    align-items: center;
    position: relative;
    margin: 0.25rem auto;
}

/* Better navigation centering in collapsed mode */
#sidebar.collapsed nav {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#sidebar.collapsed .space-y-2 {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Main content adjustment */
#mainContent {
    margin-left: 16rem; /* 256px = 16rem */
    min-width: 0; /* Allow content to shrink */
}

#mainContent.expanded {
    margin-left: 4rem; /* 64px = 4rem when collapsed */
}

/* Sidebar toggle button */
#sidebarToggle {
    position: relative;
    z-index: 60;
}

#sidebarToggle:hover {
    background-color: #f3f4f6;
}

/* Smooth transitions for sidebar elements */
.sidebar-text {
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out, transform 0.3s ease-in-out;
}

/* Tooltip for collapsed sidebar */
#sidebar.collapsed .nav-item {
    position: relative;
}

#sidebar.collapsed .nav-item::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 0.5rem);
    top: 50%;
    transform: translateY(-50%);
    background: #1f2937;
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    pointer-events: none;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

#sidebar.collapsed .nav-item:hover::after {
    opacity: 1;
    visibility: visible;
}

#sidebar.collapsed label {
    position: relative;
}

#sidebar.collapsed label::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 0.5rem);
    top: 50%;
    transform: translateY(-50%);
    background: #1f2937;
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    pointer-events: none;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

#sidebar.collapsed label:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Chart responsive adjustments */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    min-width: 0;
}

.chart-container-wrapper {
    height: 20rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

.chart-with-legend {
    display: flex;
    height: 20rem;
    min-width: 0;
    gap: 1rem;
}

.chart-canvas-container {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-legend {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 120px;
    flex-shrink: 0;
}

.chart-legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
}

.chart-legend-item:last-child {
    margin-bottom: 0;
}

.legend-color {
    width: 1rem;
    height: 1rem;
    border-radius: 0.25rem;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.legend-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: #1f2937;
    margin: 0;
}

.legend-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}

/* Responsive chart adjustments */
@media (max-width: 1200px) {
    .chart-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .chart-with-legend {
        flex-direction: column;
        height: auto;
    }
    
    .chart-canvas-container {
        height: 16rem;
    }
    
    .chart-legend {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.75rem 1rem;
        justify-content: flex-start;
        min-width: auto;
        margin-top: 1rem;
    }
    
    .chart-legend-item {
        margin-bottom: 0;
        margin-right: 0;
    }
    
    .chart-legend-item:last-child {
        margin-right: 0;
    }
}

@media (max-width: 480px) {
    .chart-with-legend,
    .chart-legend {
        max-width: 100%;
    }

    .chart-legend-item {
        flex: 1 1 calc(50% - 0.5rem);
        min-width: 0;
    }

    .legend-text,
    .legend-value {
        overflow-wrap: anywhere;
    }
}

/* Mobile overlay */
#mobileOverlay {
    transition: opacity 0.3s ease-in-out;
}

#mobileOverlay.hidden {
    opacity: 0;
    visibility: hidden;
}

/* Sidebar mobile state */
@media (max-width: 768px) {
    #sidebar.mobile-open {
        transform: translateX(0);
    }
    
    #mobileOverlay {
        display: block;
    }
}

/* Feed page styles */
.feed-item {
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out, opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
}

.feed-item:hover {
    transform: translateY(-1px);
}

.relevance-high {
    background-color: #dcfce7;
    color: #166534;
}

.relevance-medium {
    background-color: #fef3c7;
    color: #92400e;
}

.relevance-low {
    background-color: #fee2e2;
    color: #991b1b;
}

.sentiment-positive {
    background-color: #dcfce7;
    color: #166534;
}

.sentiment-negative {
    background-color: #fee2e2;
    color: #991b1b;
}

.sentiment-neutral {
    background-color: #f3f4f6;
    color: #374151;
}

/* Feed filter buttons */
.filter-btn {
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out, color 0.2s ease-in-out, transform 0.2s ease-in-out;
    border: 1px solid transparent;
}

.filter-btn:hover {
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.filter-btn.active {
    background-color: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

/* Keywords sidebar styling */
.keyword-item {
    transition: background-color 0.2s ease-in-out, opacity 0.2s ease-in-out;
}

.keyword-item:hover {
    background-color: #f9fafb;
}

/* Feed responsive adjustments */
@media (max-width: 768px) {
    .feed-filters {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .feed-filters .ml-auto {
        margin-left: 0;
        margin-top: 0.5rem;
        width: 100%;
    }

    .feed-filters .filter-dropdown,
    .feed-filters .filter-dropdown-trigger,
    #feedExtraFilters .filter-dropdown,
    #feedExtraFilters .filter-dropdown-trigger {
        width: 100%;
    }
    
    .feed-item .flex {
        flex-direction: column;
        align-items: stretch;
    }
    
    .feed-item .flex-shrink-0 {
        flex-shrink: 1;
        margin-bottom: 0.75rem;
    }
    
    .feed-actions {
        margin-top: 0.75rem;
        justify-content: space-between;
    }
}

/* Functional interface states */
.hidden {
    display: none !important;
}

button,
select,
input {
    accent-color: var(--color-brand);
}

button,
select,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]) {
    min-height: 2.75rem;
}

[data-keyword-menu],
[data-feed-action="viewed"],
[data-feed-action="bookmark"],
[data-analytics-action],
[data-chart-expand],
#sidebarToggle,
.app-modal-close {
    align-items: center;
    display: inline-flex;
    justify-content: center;
    min-width: 2.75rem;
}

button:disabled {
    cursor: wait;
    opacity: 0.62;
}

.filter-dropdown {
    display: inline-flex;
    min-width: 0;
    position: relative;
}

.filter-dropdown-trigger {
    gap: 0.4rem;
    justify-content: flex-start;
    white-space: nowrap;
}

.filter-dropdown-trigger .fa-chevron-down {
    margin-inline-start: 0.15rem;
    transition: transform 160ms ease-out;
}

.filter-dropdown-trigger[aria-expanded="true"] .fa-chevron-down {
    transform: rotate(180deg);
}

.filter-dropdown-trigger.is-active-filter {
    background: #dbeafe;
    color: #1e40af;
}

.filter-dropdown-menu {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
    inset-block-start: calc(100% + 0.5rem);
    inset-inline-start: 0;
    max-height: min(19rem, 55vh);
    min-width: max(100%, 12rem);
    overflow-y: auto;
    padding: 0.375rem;
    position: absolute;
    z-index: 80;
}

.filter-dropdown-align-end .filter-dropdown-menu {
    inset-inline-end: 0;
    inset-inline-start: auto;
}

.filter-dropdown-option {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: #334155;
    cursor: pointer;
    display: flex;
    font-size: 0.875rem;
    gap: 0.75rem;
    justify-content: space-between;
    min-height: 2.75rem;
    padding: 0.625rem 0.75rem;
    text-align: start;
    width: 100%;
}

.filter-dropdown-option:hover,
.filter-dropdown-option:focus-visible {
    background: #eff6ff;
    color: #1e40af;
    outline: none;
}

.filter-dropdown-option .fa-check {
    color: #2563eb;
    opacity: 0;
}

.filter-dropdown-option[aria-selected="true"] {
    background: #dbeafe;
    color: #1e3a8a;
    font-weight: 600;
}

.filter-dropdown-option[aria-selected="true"] .fa-check {
    opacity: 1;
}

[data-analytics-action][aria-pressed="true"],
[data-chart-expand][aria-pressed="true"],
[data-keyword-menu][aria-pressed="true"] {
    background: #dbeafe;
    color: #1e40af;
}

[data-sidebar-keyword].is-muted {
    opacity: 0.48;
}

.avatar-initials {
    align-items: center;
    border-radius: 999px;
    display: inline-flex;
    flex: 0 0 2.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    height: 2.5rem;
    justify-content: center;
    letter-spacing: 0.03em;
    width: 2.5rem;
}

.avatar-initials-indigo {
    background: #e0e7ff;
    color: #3730a3;
}

.avatar-initials-amber {
    background: #fef3c7;
    color: #92400e;
}

.feed-item.is-viewed {
    background: #f8fafc;
    opacity: 0.76;
}

.feed-item.is-filtered,
.feed-item.is-hidden {
    display: none;
}

.feed-item [data-feed-action="bookmark"][aria-pressed="true"] {
    color: #1e40af;
}

.bookmark-item,
.notification-item {
    align-items: flex-start;
    background: #f8fafc;
    border-radius: 12px;
    display: flex;
    gap: 0.875rem;
    justify-content: space-between;
    padding: 1rem;
}

.notification-item:not(.is-read) {
    background: #eff6ff;
}

.notification-item.is-read {
    color: #64748b;
}

.analytics-focus-mode {
    background: #f8fafc;
    inset: 0;
    overflow: auto;
    padding: 5rem 1.5rem 2rem;
    position: fixed;
    z-index: 45;
}

.analytics-stacked-layout {
    grid-template-columns: 1fr !important;
}

[data-chart-card].is-expanded {
    grid-column: 1 / -1;
}

.app-modal {
    align-items: center;
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 1rem;
    position: fixed;
    z-index: 70;
}

.app-modal-backdrop {
    background: rgba(15, 23, 42, 0.62);
    border: 0;
    inset: 0;
    position: absolute;
}

.app-modal-panel {
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.24);
    max-height: min(80dvh, 42rem);
    max-width: 36rem;
    overflow: auto;
    position: relative;
    width: min(100%, 36rem);
    z-index: 1;
}

.app-modal-header {
    align-items: center;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
}

.app-modal-close {
    align-items: center;
    border-radius: 8px;
    color: #475569;
    display: inline-flex;
    height: 2.75rem;
    justify-content: center;
    width: 2.75rem;
}

.app-modal-body {
    color: #334155;
    overflow-wrap: anywhere;
    padding: 1.5rem;
}

.app-toast {
    align-items: center;
    background: #172554;
    border-radius: 12px;
    bottom: 1.25rem;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
    color: #ffffff;
    display: flex;
    gap: 0.75rem;
    inset-inline-end: 1.25rem;
    max-width: min(24rem, calc(100vw - 2.5rem));
    padding: 0.875rem 1rem;
    position: fixed;
    z-index: 80;
}

@media (max-width: 768px) {
    html,
    body {
        max-width: 100%;
        overflow-x: clip;
    }

    header {
        inset-inline: 0;
        left: 0;
        margin: 0;
        max-width: 100dvw;
        right: 0;
        width: 100dvw !important;
    }

    header > div {
        gap: 0.75rem;
        max-width: 100%;
        min-width: 0;
        width: 100%;
    }

    .header-brand {
        flex: 0 1 auto;
        min-width: 0;
    }

    .header-controls {
        flex: 0 0 auto;
        gap: 0.5rem;
        min-width: 0;
    }

    .header-controls > :not([hidden]) ~ :not([hidden]) {
        margin-inline-start: 0.5rem;
    }

    .brand-long {
        display: none;
    }

    .app-brand {
        font-size: 1rem !important;
        line-height: 1.2;
        white-space: nowrap;
    }

    #mainContent {
        padding: 1rem !important;
    }

    #globalPeriod {
        max-width: 7rem;
        min-width: 0;
    }

    #downloadReportButton {
        font-size: 0;
        min-height: 2.75rem;
        min-width: 2.75rem;
        padding: 0.625rem;
    }

    #downloadReportButton i {
        font-size: 0.875rem;
        margin: 0;
    }

    .feed-item {
        padding: 1rem;
    }

    .analytics-header,
    .analytics-summary-header {
        align-items: stretch;
        flex-direction: column;
        gap: 1rem;
    }

    .analytics-selectors {
        align-items: stretch;
        display: grid;
        gap: 0.75rem;
        grid-template-columns: 1fr;
    }

    .analytics-selectors > div {
        margin-left: 0 !important;
        min-width: 0;
    }

    .analytics-selectors select {
        min-width: 0;
        width: 100%;
    }

    .analytics-toolbar {
        display: grid;
        gap: 0.5rem;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        margin-left: 0 !important;
        width: 100%;
    }

    .analytics-toolbar > :not([hidden]) ~ :not([hidden]) {
        margin-left: 0;
    }

    .analytics-toolbar [data-analytics-filter] {
        justify-content: center;
        min-width: 0;
        width: 100%;
    }

    .analytics-toolbar > .filter-dropdown {
        grid-column: 1 / -1;
        width: 100%;
    }

    .analytics-toolbar [data-analytics-action] {
        width: 100%;
    }

    .analytics-focus-mode {
        padding: 4.75rem 1rem 1rem;
    }

    .app-toast {
        inset-inline: 1rem;
        max-width: none;
    }
}

@media (max-width: 420px) {
    header > div {
        padding-inline: 0.75rem;
    }

    .header-brand {
        gap: 0.5rem;
    }

    .period-control > i {
        display: none;
    }

    #globalPeriod {
        max-width: 6.75rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .animate-count,
    .animate-pulse {
        animation: none !important;
    }

    .card-hover:hover,
    .feed-item:hover,
    .filter-btn:hover,
    .platform-icon:hover {
        transform: none;
    }

    #sidebar,
    #mobileOverlay,
    .sidebar-text,
    .feed-item,
    .filter-btn,
    .filter-dropdown-trigger .fa-chevron-down,
    .keyword-item {
        transition: none !important;
    }
}
