/* Main Styles for Perspect Dashboard */

:root {
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    --font-mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
    --radius: 6px;
    --c-bg: #FAF9F8;
    --c-ink: #150811;
    --c-ink-2: #150811;
    --c-muted: #BEB8CD;
    --c-border: rgba(190, 184, 205, 0.55);
    /* Palette (Noir Fiction) */
    --c-noir-fiction: #150811;
    --c-cloud-petal: #FAF9F8;
    --c-shy-moment: #6D5BD0;
    --c-heartless: #623B70;
    --c-wild-lilac: #BEB8CD;
    --c-violet-carmine: #531745;
    /* App accents (mapped to palette) */
    --c-neon-pink: var(--c-shy-moment);
    --c-raspberry-plum: var(--c-heartless);
    --c-indigo-bloom: var(--c-shy-moment);
    --c-ultrasonic-blue: var(--c-heartless);
    --c-true-azure: var(--c-shy-moment);
    --c-vivid-royal: var(--c-heartless);
    --c-persian-blue: var(--c-heartless);
    --c-electric-sapphire: var(--c-shy-moment);
    --c-cloudy-sky: var(--c-wild-lilac);
    --c-sky-aqua: var(--c-shy-moment);

    /* App accents (mapped to palette) */
    --c-purple: var(--c-shy-moment);
    --c-purple-dark: var(--c-heartless);
    --c-purple-rgb: 109, 91, 208;
    --shadow-soft: 0 10px 24px rgba(15, 23, 42, 0.06);
    --shadow-hover: 0 14px 30px rgba(15, 23, 42, 0.10);
}

/* Palette utility overrides for Tailwind-style classes */
.text-purple {
    color: var(--c-shy-moment);
}

.bg-purple {
    background-color: var(--c-shy-moment);
}

.bg-purple-dark {
    background-color: var(--c-heartless);
}

.bg-white {
    background-color: var(--c-cloud-petal);
}

.border-purple {
    border-color: var(--c-shy-moment);
}

.border-purple-200 {
    border-color: rgba(109, 91, 208, 0.35);
}

.border-purple\/20 {
    border-color: rgba(109, 91, 208, 0.2);
}

.bg-purple\/10 {
    background-color: rgba(109, 91, 208, 0.1);
}

.bg-purple\/15 {
    background-color: rgba(109, 91, 208, 0.15);
}

.bg-purple\/40 {
    background-color: rgba(109, 91, 208, 0.4);
}

.bg-purple-50\/60 {
    background-color: rgba(190, 184, 205, 0.6);
}

.ring-purple\/30 {
    box-shadow: 0 0 0 2px rgba(109, 91, 208, 0.3);
}

.focus\:ring-purple:focus {
    box-shadow: 0 0 0 3px rgba(109, 91, 208, 0.35);
}

.focus\:border-purple:focus {
    border-color: rgba(109, 91, 208, 0.6);
}

.hover\:bg-purple-dark:hover {
    background-color: var(--c-heartless);
}

.hover\:text-purple-dark:hover {
    color: var(--c-heartless);
}

.hover\:bg-purple\/15:hover {
    background-color: rgba(109, 91, 208, 0.15);
}

/* Tooltip Styles */
.tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

.tooltip-content {
    visibility: hidden;
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--c-noir-fiction);
    color: white;
    padding: 10px 14px;
    border-radius: 0;
    font-size: 11px;
    width: 220px;
    text-align: left;
    z-index: 100;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    opacity: 0;
    transform: translateX(-50%) translateY(4px);
    transition: all 0.2s ease;
}

.tooltip-content::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--c-noir-fiction) transparent transparent transparent;
}

.tooltip-container:hover .tooltip-content {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

body {
    background-color: var(--c-bg);
    background-image:
        radial-gradient(980px 540px at 14% -18%, rgba(var(--c-purple-rgb), 0.16), transparent 60%),
        radial-gradient(820px 480px at 92% 0%, rgba(190, 184, 205, 0.18), transparent 60%),
        radial-gradient(760px 420px at 52% 12%, rgba(190, 184, 205, 0.12), transparent 62%);
    font-family: var(--font-sans);
    color: var(--c-ink);
}

@media (max-width: 640px) {
    body {
        padding-bottom: calc(28px + env(safe-area-inset-bottom));
    }

    .app-header {
        height: 56px;
        padding-left: 12px;
        padding-right: 12px;
    }

    .app-header h2 {
        font-size: 15px;
    }

    #themeToggle {
        font-size: 16px;
    }

    #userMenu summary {
        width: 36px;
        height: 36px;
        padding: 0;
        font-size: 12px;
    }

    #userMenu summary .fa-user-circle {
        font-size: 14px;
    }

    #mobileNavToggle {
        width: 36px;
        height: 36px;
    }

    .app-subnav {
        padding-left: 12px;
        padding-right: 12px;
    }

    .widget-card,
    .widget-ai-insight {
        padding: 16px !important;
    }

    .widget-title {
        font-size: 12px;
    }

    .widget-metric-large {
        font-size: 22px;
    }

    .widget-metric-medium {
        font-size: 18px;
    }

    .sortable-table th,
    .sortable-table td {
        padding: 10px 12px;
        font-size: 12px;
    }

    .app-subnav .nav-item {
        padding: 6px 10px;
        font-size: 12px;
    }

    .btn,
    button {
        min-height: 36px;
    }

    .table-compact td,
    .table-compact th {
        padding-top: 8px;
        padding-bottom: 8px;
    }
}

/* Buttons: slightly rounded corners */
button,
.action-btn {
    border-radius: var(--radius);
}

/* Keep segmented controls crisp inside rounded containers */
.inline-flex.rounded > button {
    border-radius: 0;
}

/* Keep numeric/technical blocks monospace when explicitly requested */
.font-mono,
code,
pre {
    font-family: var(--font-mono) !important;
}

/* Micro-animations */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes countUp {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Widget cards: visibili by default (no forced fade-in) */
.widget-card {
    opacity: 1;
    transform: none;
}

/* Metric values animation - triggered by JS */
.widget-metric-large,
.widget-metric-medium {
    opacity: 0;
    transform: scale(0.95);
}

.widget-metric-large.animate-in,
.widget-metric-medium.animate-in {
    animation: countUp 0.5s ease-out forwards;
    animation-delay: 0.3s;
}

/* AI Insight box animation */
.ai-insight-box {
    opacity: 0;
    transform: translateY(8px);
}

.ai-insight-box.animate-in {
    animation: fadeSlideIn 0.4s ease-out forwards;
    animation-delay: 0.2s;
}

/* Subtle hover lift for interactive elements */
.widget-card.animate-in {
    transform: translateY(0);
    transition: box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.widget-card.animate-in:hover {
    transform: translateY(0);
}

/* Table row highlight (no horizontal movement) */
tbody tr {
    transition: background 0.15s ease;
}

/* Nav item indicator animation */
.nav-item {
    position: relative;
}

/* Progress bar animation for debt bars */
.debt-bar-short,
.debt-bar-long-2023,
.debt-bar-short-2024,
.debt-bar-long-2024,
.debt-bar-short-2025,
.debt-bar-long-2025 {
    animation: fadeSlideIn 0.6s ease-out backwards;
}

/* Tooltip fade */
.tooltip-content {
    opacity: 0;
    transform: translateX(-50%) translateY(4px);
    transition: all 0.2s ease;
}

.tooltip-container:hover .tooltip-content {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Button/link subtle feedback */
.action-btn,
button {
    transition: all 0.15s ease;
}

.action-btn:active,
button:active {
    transform: scale(0.97);
}

/* Tooltip Styles */
.tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

.tooltip-content {
    visibility: hidden;
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--c-noir-fiction);
    color: white;
    padding: 10px 14px;
    border-radius: 0;
    font-size: 11px;
    width: 220px;
    text-align: left;
    z-index: 100;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.tooltip-content::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--c-noir-fiction) transparent transparent transparent;
}

.tooltip-container:hover .tooltip-content {
    visibility: visible;
}

/* Widget Styling - Corporate */
.widget-card {
    background: linear-gradient(135deg, rgba(var(--c-purple-rgb), 0.03) 0%, var(--c-cloud-petal) 82%);
    border: 1px solid rgba(var(--c-purple-rgb), 0.32);
    border-radius: var(--radius);
    transition: all 200ms ease;
    box-shadow: var(--shadow-soft);
}

.widget-card:hover {
    border-color: rgba(var(--c-purple-rgb), 0.70);
    box-shadow: var(--shadow-hover);
}

/* Widget Gradient Backgrounds - Corporate */
.widget-positive {
    background: linear-gradient(135deg, rgba(5, 150, 105, 0.08) 0%, rgba(250, 249, 248, 0) 100%);
    border-color: rgba(5, 150, 105, 0.35);
}

.widget-positive:hover {
    border-color: #059669;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.25);
}

.widget-negative {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.08) 0%, rgba(250, 249, 248, 0) 100%);
    border-color: rgba(220, 38, 38, 0.35);
}

.widget-negative:hover {
    border-color: #dc2626;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}

.widget-purple {
    background: linear-gradient(135deg, rgba(var(--c-purple-rgb), 0.035) 0%, var(--c-cloud-petal) 84%);
    border-color: rgba(var(--c-purple-rgb), 0.34);
}

.widget-purple:hover {
    border-color: rgba(var(--c-purple-rgb), 0.74);
    box-shadow: var(--shadow-hover);
}

/* Sub-widget styles for Executive Summary */
.subwidget-neutral {
    background: linear-gradient(135deg, rgba(var(--c-purple-rgb), 0.03) 0%, rgba(250, 249, 248, 0) 100%);
    border: 1px solid rgba(var(--c-purple-rgb), 0.30);
    border-radius: var(--radius);
}

.subwidget-negative {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.08) 0%, rgba(250, 249, 248, 0) 100%);
    border: 1px solid rgba(220, 38, 38, 0.35);
    border-radius: var(--radius);
}

/* AI Insight Widget - Corporate */
.widget-ai-insight {
    background: linear-gradient(135deg, rgba(var(--c-purple-rgb), 0.05) 0%, rgba(250, 249, 248, 0) 100%);
    border: 1px dashed rgba(var(--c-purple-rgb), 0.55);
    border-radius: var(--radius);
}

.widget-ai-insight:hover {
    border-color: var(--c-ultrasonic-blue);
    box-shadow: 0 4px 12px rgba(var(--c-purple-rgb), 0.22);
}

/* AI Badge */
.badge-ai {
    background: var(--c-indigo-bloom);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* AI Insight arrows */
.ai-insight-arrow::before {
    color: var(--c-indigo-bloom);
}

/* Risk badges */
.risk-badge {
    background: var(--c-indigo-bloom);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Table Styling */
table {
    font-size: 12px;
}

table th,
table td {
    font-size: 12px;
}

.sortable-table {
    font-size: 12px;
}

.sortable-table th,
.sortable-table td {
    font-size: 12px;
}

th[data-sort] {
    cursor: pointer;
    user-select: none;
}

th[data-sort]:hover {
    background: rgba(var(--c-purple-rgb), 0.08);
}

th[data-sort]::after {
    content: ' ↕';
    opacity: 0.4;
    font-size: 11px;
    margin-left: 4px;
}

.sticky-col {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #ffffff;
    box-shadow: 1px 0 0 #e5e7eb;
}

.sticky-col-header {
    position: sticky;
    left: 0;
    z-index: 3;
    background: #f9fafb;
    box-shadow: 1px 0 0 #e5e7eb;
}

.holdings-row:hover .sticky-col,
.sticky-row:hover .sticky-col {
    background: #f9fafb;
}

th[aria-sort="ascending"]::after {
    content: ' ↑';
    opacity: 1;
}

th[aria-sort="descending"]::after {
    content: ' ↓';
    opacity: 1;
}

tbody tr:hover {
    background: rgba(var(--c-purple-rgb), 0.06);
}

/* Top header: slightly more "product" feel */
.app-header {
    background-color: rgba(250, 249, 248, 0.74);
    background-image: linear-gradient(
        90deg,
        rgba(var(--c-purple-rgb), 0.07) 0%,
        rgba(var(--c-purple-rgb), 0.05) 40%,
        rgba(var(--c-purple-rgb), 0.06) 100%
    );
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: visible;
}

/* Second-level navigation bar */
.app-subnav {
    background-color: rgba(250, 249, 248, 0.80);
    background-image: linear-gradient(
        90deg,
        rgba(var(--c-purple-rgb), 0.05) 0%,
        rgba(var(--c-purple-rgb), 0.04) 40%,
        rgba(var(--c-purple-rgb), 0.05) 100%
    );
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.app-subnav .nav-item {
    position: relative;
    background: transparent;
    border-radius: 0;
}

.app-subnav .nav-item:hover,
.app-subnav .nav-item.active {
    background: transparent;
}

.app-subnav .nav-item.active {
    color: #4c3ba8;
    border-bottom-color: #6d5bd0;
}

/* Sidebar: lightweight tech panel */
#sidebar {
    background: var(--c-cloud-petal);
}

/* Archivio Documenti: hover e azioni */
#documentsTable tbody tr:hover {
    background: rgba(var(--c-purple-rgb), 0.08);
}

#documentsTable thead th:hover {
    background: rgba(var(--c-purple-rgb), 0.08);
}

#documentsTable .action-btn {
    color: #9ca3af;
    transition: color 150ms ease;
}

#documentsTable .action-btn:hover {
    color: var(--c-indigo-bloom);
}

/* Common Widget Typography */
.widget-title {
    font-weight: 500;
    color: var(--c-ink);
    font-size: 13px;
    margin-bottom: 12px;
}

.widget-text {
    font-size: 12px;
    line-height: 1.6;
    color: var(--c-ink);
    font-weight: 400;
}

.widget-metric-large {
    font-size: 22px;
    font-weight: 600;
    color: var(--c-ink);
}

.widget-metric-medium {
    font-size: 16px;
    font-weight: 600;
    color: var(--c-ink);
}

.widget-metric-small {
    font-size: 13px;
    font-weight: 500;
    color: var(--c-ink);
}

/* Responsive metric sizes */
@media (min-width: 640px) {
    .widget-metric-large {
        font-size: 28px;
    }
    .widget-metric-medium {
        font-size: 18px;
    }
    .widget-metric-small {
        font-size: 14px;
    }
}

.widget-label {
    font-size: 10px;
    color: var(--c-ink);
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.08em;
}

.widget-label-medium {
    font-size: 11px;
    color: var(--c-ink);
    font-weight: 500;
}

.state-message {
    font-size: 12px;
    color: var(--c-muted);
    font-weight: 400;
    font-style: italic;
    line-height: 1.5;
}

.widget-status-badge {
    font-size: 10px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 0 !important;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.widget-change-positive {
    color: #22c55e;
    font-weight: 500;
    font-size: 10px;
}

.widget-change-negative {
    color: #ef4444;
    font-weight: 500;
    font-size: 10px;
}

.widget-change-neutral {
    color: var(--c-muted);
    font-weight: 500;
    font-size: 10px;
}

/* Detail Widgets */
.widget-detail-label {
    font-size: 12px;
    color: var(--c-ink);
    font-weight: 400;
}

.widget-detail-value {
    font-size: 12px;
    color: var(--c-ink);
    font-weight: 500;
}

.widget-detail-header {
    font-size: 11px;
    font-weight: 500;
    color: var(--c-ink);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 16px;
}

.widget-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #d1d5db;
}

.widget-detail-row:last-child {
    border-bottom: none;
}

.widget-detail-note {
    font-size: 11px;
    color: var(--c-ink);
    line-height: 1.6;
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(var(--c-purple-rgb), 0.10);
    border: 1px dashed rgba(var(--c-purple-rgb), 0.5);
    border-radius: 0;
    transition: all 200ms ease;
}

.widget-detail-note:hover {
    border-color: var(--c-ultrasonic-blue);
    box-shadow: 0 4px 12px rgba(var(--c-purple-rgb), 0.22);
}

/* AI Insight inline widgets */
.ai-insight-box {
    margin-top: 16px;
    padding: 16px;
    background: rgba(var(--c-purple-rgb), 0.12);
    border: 1px dashed rgba(var(--c-purple-rgb), 0.5);
    font-size: 12px;
    color: var(--c-ink);
    transition: all 200ms ease;
}

.ai-insight-box:hover {
    border-color: var(--c-ultrasonic-blue);
    box-shadow: 0 4px 12px rgba(var(--c-purple-rgb), 0.22);
}

/* Mobile responsive adjustments */
@media (max-width: 639px) {
    .ai-insight-box {
        padding: 12px;
        font-size: 11px;
    }

    .widget-title {
        font-size: 12px;
    }

    .widget-text {
        font-size: 11px;
    }

    .tooltip-content {
        width: 180px;
        font-size: 10px;
        padding: 8px 10px;
    }

    .widget-detail-row {
        padding: 8px 0;
    }

    .widget-detail-label,
    .widget-detail-value {
        font-size: 11px;
    }

    /* Better touch targets */
    .nav-item {
        padding: 10px 0;
    }

    tbody tr {
        min-height: 44px;
    }
}

/* Tooltip visibility safeguard */
.tooltip-content {
    color: #fff;
    z-index: 999;
}

.tooltip-container:hover .tooltip-content {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Debt Bar Widths - Data-driven from JSON */
.debt-bar-short {
    width: 53%;
}

.debt-bar-long-2023 {
    width: 47%;
}

.debt-bar-short-2024 {
    width: 68%;
}

.debt-bar-long-2024 {
    width: 32%;
}

.debt-bar-short-2025 {
    width: 54%;
}

.debt-bar-long-2025 {
    width: 46%;
}

/* Dynamic width class for debt bars from JSON */
.debt-bar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    font-weight: 500;
}

.debt-bar.short {
    background: var(--c-indigo-bloom);
}

.debt-bar.long {
    background: var(--c-muted);
}

/* Button Reset Styles */
.btn-reset {
    outline: none;
    -webkit-tap-highlight-color: transparent;
    border-radius: var(--radius);
    border: none;
}

/* View Navigation */
.view {
    opacity: 1;
    transition: opacity 0.3s ease;
}

.view.hidden {
    display: none !important;
}

/* Disabled Items */
.item-disabled {
    color: #cbd5e1;
    opacity: 0.6;
    cursor: not-allowed;
}

.item-disabled i {
    color: #cbd5e1;
}

/* Fix scrollbar orizzontale tabelle */
.overflow-x-auto {
    overflow-x: auto;
    overflow-y: visible;
}

/* Nasconde scrollbar se non necessaria */
@media (min-width: 768px) {
    .overflow-x-auto {
        overflow-x: visible;
    }
}

/* Su mobile mostra scrollbar solo se necessaria */
@media (max-width: 767px) {
    .overflow-x-auto::-webkit-scrollbar {
        height: 6px;
    }
    .overflow-x-auto::-webkit-scrollbar-track {
        background: #f1f1f1;
    }
    .overflow-x-auto::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 3px;
    }
    .overflow-x-auto::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
}
