/* ============================================================
   SOMA Next — Custom Styles
   Supplements Tailwind CSS with animations, transitions,
   scrollbar theming, and component-specific styles.
   ============================================================ */

/* ----- HTMX Swap Transitions ----- */

.htmx-swapping {
    opacity: 0;
    transition: opacity 150ms ease-out;
}

.htmx-settling {
    opacity: 1;
    transition: opacity 200ms ease-in;
}

.htmx-added {
    opacity: 0;
}

.htmx-added.htmx-settling {
    opacity: 1;
    transition: opacity 300ms ease-in;
}

/* Indicator shown while HTMX request is in flight */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-flex;
}

/* ----- Loading Spinner ----- */

@keyframes soma-spin {
    to { transform: rotate(360deg); }
}

.soma-spinner {
    width: 2rem;
    height: 2rem;
    border: 2px solid #3A3A4A;
    border-top-color: #4ECDC4;
    border-radius: 50%;
    animation: soma-spin 0.7s linear infinite;
}

/* Pulse animation for skeleton loaders */
@keyframes soma-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.7; }
}

.soma-skeleton {
    background-color: #252535;
    animation: soma-pulse 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
}

/* ----- Chart Containers ----- */

.chart-container {
    position: relative;
    width: 100%;
    height: 250px;
}

.chart-container-lg {
    position: relative;
    width: 100%;
    height: 350px;
}

.chart-container-sm {
    position: relative;
    width: 100%;
    height: 180px;
}

@media (min-width: 768px) {
    .chart-container {
        height: 300px;
    }
    .chart-container-lg {
        height: 420px;
    }
}

/* ----- Dark Theme Scrollbar ----- */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #0D0D12;
}

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

::-webkit-scrollbar-thumb:hover {
    background: #4ECDC4;
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: #3A3A4A #0D0D12;
}

/* ----- Interaction Matrix Grid ----- */

.interaction-matrix {
    display: grid;
    gap: 2px;
}

.interaction-cell {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.625rem;
    font-weight: 600;
    cursor: default;
    transition: transform 100ms ease, box-shadow 100ms ease;
}

.interaction-cell:hover {
    transform: scale(1.15);
    box-shadow: 0 0 8px rgba(78, 205, 196, 0.3);
    z-index: 10;
}

.interaction-synergy   { background-color: rgba(78, 205, 196, 0.25); color: #4ECDC4; }
.interaction-caution   { background-color: rgba(255, 217, 61, 0.25); color: #FFD93D; }
.interaction-warning   { background-color: rgba(255, 140, 66, 0.25); color: #FF8C42; }
.interaction-danger    { background-color: rgba(255, 107, 107, 0.25); color: #FF6B6B; }
.interaction-neutral   { background-color: rgba(204, 204, 216, 0.1); color: #CCCCD8; }
.interaction-none      { background-color: rgba(58, 58, 74, 0.3); color: #3A3A4A; }

/* Matrix header labels */
.interaction-matrix-label {
    font-size: 0.625rem;
    color: #CCCCD8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 5rem;
}

/* ----- Glucose Zone Backgrounds ----- */

.glucose-zone-optimal { background-color: rgba(78, 205, 196, 0.08); }
.glucose-zone-elevated { background-color: rgba(255, 217, 61, 0.08); }
.glucose-zone-high { background-color: rgba(255, 140, 66, 0.08); }
.glucose-zone-critical { background-color: rgba(255, 107, 107, 0.08); }

/* ----- Form Inputs (dark-themed) ----- */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="date"],
input[type="time"],
textarea,
select {
    background-color: #1A1A24;
    border: 1px solid #3A3A4A;
    color: #E8E8F0;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    transition: border-color 150ms ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #4ECDC4;
    box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.15);
}

input::placeholder,
textarea::placeholder {
    color: #6B6B7B;
}

/* ----- Mobile Bottom Bar Spacer ----- */

@media (max-width: 767px) {
    main {
        padding-bottom: 4rem;
    }
}

/* ----- Fade-in Utility ----- */

@keyframes soma-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.soma-fade-in {
    animation: soma-fade-in 300ms ease-out;
}

/* ----- Status Chip Colors ----- */

.status-pending   { background-color: rgba(255, 217, 61, 0.15); color: #FFD93D; }
.status-running   { background-color: rgba(78, 205, 196, 0.15); color: #4ECDC4; }
.status-completed { background-color: rgba(78, 205, 196, 0.25); color: #4ECDC4; }
.status-failed    { background-color: rgba(255, 107, 107, 0.15); color: #FF6B6B; }
.status-cancelled { background-color: rgba(204, 204, 216, 0.1);  color: #CCCCD8; }

/* ----- Tooltip ----- */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: #252535;
    color: #E8E8F0;
    font-size: 0.6875rem;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 150ms ease;
}

[data-tooltip]:hover::after {
    opacity: 1;
}
