/* Custom styles for HES (Head-End System) */

/* Smart Seals Co Brand Colors */
:root {
    --hes-primary: #0388a3;
    --hes-primary-hover: #026d85;
    --hes-success: #2e7d32;
    --hes-warning: #f57c00;
    --hes-danger: #c62828;
}

/* Override Pico primary colors */
[data-theme="light"],
:root:not([data-theme="dark"]) {
    --pico-primary: var(--hes-primary);
    --pico-primary-hover: var(--hes-primary-hover);
    --pico-primary-background: var(--hes-primary);
    --pico-primary-border: var(--hes-primary);
    --pico-primary-underline: var(--hes-primary);
    --pico-primary-hover-background: var(--hes-primary-hover);
    --pico-primary-hover-border: var(--hes-primary-hover);
    --pico-primary-focus: #04a1c4;
}

/* Sticky Navigation */
nav.main-nav {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--pico-background-color);
    border-bottom: 1px solid var(--pico-muted-border-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    min-height: 60px;
}

.nav-brand {
    text-decoration: none;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.nav-brand img {
    height: 60px;
    width: auto;
    object-fit: contain;
    max-width: 100%;
}

/* Mobile Menu */
.mobile-menu-toggle {
    display: none;
}

.mobile-menu-button {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

.mobile-menu {
    display: none;
}

.desktop-nav {
    display: block;
}

.desktop-nav ul, .mobile-menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    gap: 1rem;
}

.desktop-nav li, .mobile-menu li {
    margin: 0;
}

/* Mobile Navigation - Tablet & Mobile */
@media (max-width: 1024px) {
    .nav-brand img {
        height: 50px;
    }

    .mobile-menu-button {
        display: block;
    }

    .desktop-nav {
        display: none;
    }

    .mobile-menu {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--pico-background-color);
        border-bottom: 1px solid var(--pico-muted-border-color);
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        z-index: 9999;
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-menu ul {
        flex-direction: column;
    }

    .mobile-menu ul li a {
        display: block;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--pico-muted-border-color);
    }

    .mobile-menu-toggle:checked ~ .mobile-menu {
        display: block;
    }
}

/* Mobile - Smaller screens */
@media (max-width: 768px) {
    .nav-brand img {
        height: 45px;
    }

    nav.main-nav {
        padding: 0.5rem 0.75rem;
        min-height: 50px;
    }

    main.container {
        padding: 1rem 0.75rem;
    }

    /* Make form grids stack on mobile */
    .grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    /* Better button sizing on mobile */
    button, [role="button"] {
        min-height: 44px;
        font-size: 1rem;
        padding: 0.75rem 1rem;
    }

    /* Smaller headers on mobile */
    article header h2 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }

    h1 {
        font-size: 1.5rem;
    }
}

/* Extra small mobile */
@media (max-width: 480px) {
    .nav-brand img {
        height: 40px;
    }

    .stat-value {
        font-size: 2rem;
    }

    .stat-label {
        font-size: 0.8rem;
    }
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    padding: 1.5rem;
    text-align: center;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--hes-primary);
    margin: 0.5rem 0;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--pico-muted-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-card.success .stat-value {
    color: var(--hes-success);
}

.stat-card.warning .stat-value {
    color: var(--hes-warning);
}

.stat-card.danger .stat-value {
    color: var(--hes-danger);
}

/* Device Status Badge */
.device-status {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.device-status.online {
    background-color: rgba(46, 125, 50, 0.15);
    color: var(--hes-success);
}

.device-status.offline {
    background-color: rgba(198, 40, 40, 0.15);
    color: var(--hes-danger);
}

/* Table Enhancements + Sortable Headers */
table {
    width: 100%;
}

table tbody tr:hover {
    background-color: var(--pico-card-sectionning-background-color);
}

.sortable-header a {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    display: block;
    transition: background-color 0.2s;
    padding: 0.5rem;
    margin: -0.5rem;
    border-radius: 4px;
}

.sortable-header a:hover {
    background-color: rgba(25, 118, 210, 0.1);
    color: var(--hes-primary);
}

.sort-indicator {
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

/* Date Range Filter */
.date-filter {
    display: grid;
    grid-template-columns: auto auto auto auto;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--pico-card-sectionning-background-color);
    border-radius: var(--pico-border-radius);
}

.date-filter input[type="date"] {
    margin-bottom: 0;
}

.date-filter button {
    margin-bottom: 0;
}

/* Global Notifications */
.global-notification {
    padding: 1rem;
    margin-bottom: 1rem;
    border-left-width: 4px;
    border-left-style: solid;
    border-radius: var(--pico-border-radius);
    opacity: 1;
    transition: opacity 0.6s;
}

.notification-info {
    background-color: rgba(25, 118, 210, 0.15);
    border-left-color: var(--hes-primary);
}

.notification-success {
    background-color: rgba(46, 125, 50, 0.15);
    border-left-color: var(--hes-success);
}

.notification-warning {
    background-color: rgba(245, 124, 0, 0.15);
    border-left-color: var(--hes-warning);
}

.notification-error {
    background-color: rgba(198, 40, 40, 0.15);
    border-left-color: var(--hes-danger);
}

/* HTMX Loading States */
.htmx-swapping {
    opacity: 0;
    transition: opacity 200ms ease-out;
}

.htmx-settling {
    opacity: 1;
}

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

.htmx-indicator {
    display: none;
}

/* Loading Spinner */
.spinner {
    border: 2px solid var(--pico-muted-border-color);
    border-top: 2px solid var(--hes-primary);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-left: 0.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Definition Lists (dl/dt/dd) - PTM Pattern */
article > dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: calc(var(--pico-spacing) * 0.35) var(--pico-spacing);
    align-items: baseline;
    margin-top: var(--pico-spacing);
}

article > dl dt {
    font-weight: 600;
    color: var(--pico-h5-color);
    padding-right: var(--pico-spacing);
}

article > dl dd {
    margin-left: 0;
    padding-bottom: calc(var(--pico-spacing) * 0.5);
    border-bottom: 1px dotted var(--pico-muted-border-color);
    overflow-wrap: break-word;
    word-break: break-word;
}

article > dl dd:last-of-type {
    border-bottom: none;
}

/* Responsive Tables for Mobile */
@media (max-width: 768px) {
    /* Stats grid: 1 columna en móvil */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Date filter: stack en móvil */
    .date-filter {
        grid-template-columns: 1fr;
    }

    /* Tablas: scroll horizontal en móvil */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
}

/* Mejoras para desktop grande */
@media (min-width: 1440px) {
    .container {
        max-width: 1280px;
    }

    .stats-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Pagination Controls */
.pagination-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding: 1rem;
    background: var(--pico-card-sectionning-background-color);
    border-radius: var(--pico-border-radius);
}

.pagination-controls button {
    margin-bottom: 0;
    min-width: 120px;
}

.pagination-controls span {
    font-size: 0.9rem;
    color: var(--pico-muted-color);
}

@media (max-width: 768px) {
    .pagination-controls {
        flex-direction: column;
        gap: 0.75rem;
    }

    .pagination-controls button {
        width: 100%;
    }
}

/* ========== ALARMS TABLE (FASE 1.1 - Simplified) ========== */
/* Row highlighting by status */
table tbody tr:hover {
    background-color: var(--pico-card-sectionning-background-color);
}

/* Compact buttons in table */
table a[role="button"] {
    margin-bottom: 0;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* Table cell sizing */
table td, table th {
    white-space: nowrap;
}

table td:nth-child(4) {
    white-space: normal;
    max-width: 300px;
}

/* Alarm counter buttons (small, minimal) */
.alarm-counter-btn {
    margin-bottom: 0;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    margin-left: 0.25rem;
}

/* ========== ALARM DETAIL HEADER ========== */
.alarm-header {
    margin-bottom: 1.5rem;
    padding: 1.5rem;
    background: var(--pico-card-background-color);
    border-radius: var(--pico-border-radius);
}

.alarm-header.status-new {
    border-left: 4px solid var(--hes-warning);
}

.alarm-header.status-review {
    border-left: 4px solid var(--hes-primary);
}

.alarm-header.status-resolved {
    border-left: 4px solid var(--hes-success);
}

.alarm-header-title {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.alarm-status-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.alarm-status-dot.status-new {
    background-color: var(--hes-warning);
}

.alarm-status-dot.status-review {
    background-color: var(--hes-primary);
}

.alarm-status-dot.status-resolved {
    background-color: var(--hes-success);
}

.alarm-header-title h1 {
    margin: 0;
}

.alarm-header-info {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1rem;
    font-size: 0.95rem;
}

.alarm-header-info strong {
    color: var(--pico-h5-color);
}

/* ========== TIMELINE (FASE 1.1 - REDESIGNED) ========== */
.timeline {
    position: relative;
    padding: 1rem 0;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 20px;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--pico-muted-border-color);
}

.timeline-item {
    position: relative;
    padding-left: 60px;
    margin-bottom: 2rem;
}

.timeline-marker {
    position: absolute;
    left: 11px;
    top: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--pico-background-color);
    border: 4px solid;
    z-index: 1;
}

.timeline-created .timeline-marker {
    border-color: var(--hes-warning);
    background-color: rgba(245, 124, 0, 0.1);
}

.timeline-status_change .timeline-marker {
    border-color: var(--hes-primary);
    background-color: rgba(3, 136, 163, 0.1);
}

.timeline-comment .timeline-marker {
    border-color: #757575;
    background-color: rgba(117, 117, 117, 0.1);
}

.timeline-resolved .timeline-marker {
    border-color: var(--hes-success);
    background-color: rgba(46, 125, 50, 0.1);
}

.timeline-content {
    background: var(--pico-card-background-color);
    padding: 1.25rem;
    border-radius: var(--pico-border-radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--pico-muted-border-color);
}

.timeline-created .timeline-content {
    border-left: 3px solid var(--hes-warning);
}

.timeline-status_change .timeline-content {
    border-left: 3px solid var(--hes-primary);
}

.timeline-comment .timeline-content {
    border-left: 3px solid #757575;
}

.timeline-resolved .timeline-content {
    border-left: 3px solid var(--hes-success);
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.timeline-event-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--pico-color);
}

.timeline-user {
    font-size: 0.875rem;
    color: var(--pico-muted-color);
    margin-left: 0.5rem;
}

.timeline-timestamp {
    color: var(--pico-muted-color);
    font-size: 0.8rem;
    white-space: nowrap;
}

.timeline-content p {
    margin: 0.75rem 0 0 0;
    line-height: 1.6;
}

.timeline-content details {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--pico-card-sectionning-background-color);
    border-radius: 4px;
}

.timeline-content details summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--hes-primary);
    font-weight: 600;
}

.timeline-content details[open] summary {
    margin-bottom: 0.5rem;
}

/* Timeline Responsive */
@media (max-width: 768px) {
    .timeline::before {
        left: 12px;
    }

    .timeline-item {
        padding-left: 45px;
    }

    .timeline-marker {
        left: 5px;
        width: 16px;
        height: 16px;
        border-width: 3px;
    }

    .timeline-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .timeline-timestamp {
        font-size: 0.75rem;
    }
}

/* ========== BADGES (FASE 1.1) ========== */
.badge, .badge-new, .badge-review, .badge-resolved {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.badge-new {
    background-color: rgba(245, 124, 0, 0.15);
    color: var(--hes-warning);
    border: 1px solid var(--hes-warning);
}

.badge-review {
    background-color: rgba(25, 118, 210, 0.15);
    color: var(--hes-primary);
    border: 1px solid var(--hes-primary);
}

.badge-resolved {
    background-color: rgba(46, 125, 50, 0.15);
    color: var(--hes-success);
    border: 1px solid var(--hes-success);
}

/* ========== ALARM STAT CARDS (Customer Overview) ========== */
.alarm-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.alarm-stat-card {
    text-align: center;
    padding: 1rem;
    border-radius: 8px;
    border: 2px solid;
}

.alarm-stat-card.danger {
    border-color: var(--hes-danger);
}

.alarm-stat-card.warning {
    border-color: var(--hes-warning);
}

.alarm-stat-card.success {
    border-color: var(--hes-success);
}

.alarm-stat-label {
    color: #666;
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.alarm-stat-value {
    font-size: 2rem;
    font-weight: bold;
}

.alarm-stat-card.danger .alarm-stat-value {
    color: var(--hes-danger);
}

.alarm-stat-card.warning .alarm-stat-value {
    color: var(--hes-warning);
}

.alarm-stat-card.success .alarm-stat-value {
    color: var(--hes-success);
}
