/* ===================================
   Panda Tractive Dashboard - Styles
   Ispirato all'interfaccia Tractive
   =================================== */

:root {
    /* Colori Palette Viola */
    --primary: #ab4fd3;
    --primary-dark: #9b41c1;
    --secondary: #b86bff;
    --danger: #ff3860;
    --warning: #ffdd57;
    --success: #23d160;

    /* Neutri - Tema Viola */
    --bg-dark: #3a2562;
    --bg-card: #473078;
    --bg-light: #5c3b95;
    --text-primary: #ffffff;
    --text-secondary: #c0b0d0;
    --border-color: #5a4a7a;

    /* Layout */
    --header-height: 60px;
    --sidebar-width: 320px;
    --panel-width: 380px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    /* Prevent pinch zoom on iOS */
    touch-action: pan-x pan-y;
}

/* === HEADER === */
.header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
}

.header h1 .app-icon {
    margin-right: 6px;
}

.header-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.header-subtitle .short-text {
    display: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

#last-update {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* === BUTTONS === */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: var(--bg-dark);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-secondary {
    background: var(--bg-light);
    color: var(--text-primary);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.btn-close:hover {
    color: var(--text-primary);
}

/* === BADGE === */
.badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-warning {
    background: var(--warning);
    color: var(--bg-dark);
}

.badge-success {
    background: var(--success);
    color: white;
}

/* === MAIN LAYOUT === */
.main-container {
    display: flex;
    height: calc(100vh - var(--header-height));
    margin-top: var(--header-height);
}

/* === SIDEBAR === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-dark);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 15px;
}

.pet-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* === PET CARD === */
.pet-card {
    background: var(--bg-light);
    border-radius: 12px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.pet-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.pet-card.active {
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(171, 79, 211, 0.3);
}

.pet-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.pet-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.pet-info h3 {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.pet-info .breed {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.pet-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    background: var(--bg-card);
    padding: 10px;
    border-radius: 8px;
    text-align: center;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.battery-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px;
    background: var(--bg-card);
    border-radius: 8px;
}

.battery-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-dark);
    border-radius: 4px;
    overflow: hidden;
}

.battery-fill {
    height: 100%;
    background: var(--success);
    transition: width 0.3s;
}

.battery-fill.low {
    background: var(--danger);
}

.battery-fill.medium {
    background: var(--warning);
}

/* === TRACKER STATUS === */
.tracker-status {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: 8px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.status-row:first-child {
    padding-top: 0;
}

.status-row:last-child {
    padding-bottom: 0;
}

.status-row + .status-row {
    border-top: 1px solid var(--border-color);
    margin-top: 8px;
    padding-top: 10px;
}

.status-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-value {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
}

.battery-row .battery-indicator {
    margin-top: 0;
    padding: 0;
    background: transparent;
    gap: 6px;
}

.battery-row .battery-bar {
    width: 60px;
    flex: none;
}

/* === MAP === */
.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

.map-controls {
    position: absolute;
    bottom: 30px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 500;
}

.map-btn {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.map-btn:hover {
    background: var(--primary);
    color: var(--bg-dark);
}

.map-btn.active {
    background: var(--primary);
    color: var(--bg-dark);
}

/* === DETAIL PANEL === */
.detail-panel {
    width: var(--panel-width);
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.detail-panel.open {
    transform: translateX(0);
}

.panel-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.panel-header h2 {
    font-size: 1.2rem;
}

.panel-content {
    padding: 20px;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}

.error-state {
    text-align: center;
    color: var(--text-primary);
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.error-state .error-icon {
    font-size: 2.5rem;
}

.error-state p {
    color: var(--text-secondary);
    max-width: 300px;
}

.error-state .error-details {
    font-size: 0.85rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Loading State */
.loading-state {
    text-align: center;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.loading-state .loading-message {
    color: var(--text-primary);
    font-weight: 500;
}

.loading-state .loading-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Refresh button loading state */
.btn.loading {
    opacity: 0.6;
    pointer-events: none;
}

.btn.loading svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* === ACTIVITY SECTION === */
.activity-section {
    margin-bottom: 25px;
}

.activity-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 15px;
}

.activity-chart {
    background: var(--bg-light);
    border-radius: 12px;
    padding: 15px;
    height: 200px;
    overflow: hidden;
    position: relative;
}

.activity-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 15px;
}

.activity-stat {
    text-align: center;
    padding: 15px 10px;
    background: var(--bg-light);
    border-radius: 10px;
}

.activity-stat .value {
    font-size: 1.5rem;
    font-weight: 600;
}

.activity-stat .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.activity-stat.active .value {
    color: var(--success);
}

.activity-stat.rest .value {
    color: var(--secondary);
}

.activity-stat.goal .value {
    color: var(--warning);
}

/* === CONTROLS SECTION === */
.controls-section {
    margin-top: 25px;
}

.controls-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 15px;
}

.control-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.control-btn {
    padding: 15px;
    border-radius: 10px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.control-btn:hover {
    border-color: var(--primary);
}

.control-btn.active {
    background: var(--primary);
    color: var(--bg-dark);
}

.control-btn svg {
    width: 24px;
    height: 24px;
}

/* === POSITION INFO === */
.position-info {
    background: var(--bg-light);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
}

.position-info .coords {
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--primary);
    margin-bottom: 10px;
}

.position-info .meta {
    display: flex;
    gap: 15px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* === LOADING === */
.loading-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

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

/* === CUSTOM MARKER === */
.custom-marker {
    background: var(--primary);
    border: 3px solid white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--bg-dark);
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

/* === LEAFLET OVERRIDES === */
.leaflet-container {
    background: var(--bg-dark);
}

.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 10px;
}

.leaflet-popup-tip {
    background: var(--bg-card);
}

.leaflet-control-zoom {
    border: none !important;
    margin-top: 10px !important;
    margin-left: 10px !important;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--primary) !important;
    color: var(--bg-dark) !important;
}

/* === RESPONSIVE === */
@media (max-width: 1200px) {
    .detail-panel {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 600;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        max-height: 40%;
        z-index: 500;
        border-right: none;
        border-top: 1px solid var(--border-color);
        transition: transform 0.3s ease, bottom 0.3s ease;
        transform: translateY(100%);
    }

    /* Show sidebar when toggle is active */
    .sidebar.visible {
        transform: translateY(0);
    }

    /* When timeline is active, move sidebar above it */
    .sidebar.timeline-pushed {
        bottom: 130px;
    }

    .pet-list {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 10px;
    }

    .pet-card {
        min-width: 280px;
    }

    .detail-panel {
        width: 100%;
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 700;
        transform: translateX(100%);
    }

    .detail-panel.open {
        transform: translateX(0);
    }

    .detail-panel .panel-header {
        padding: 16px;
        background: var(--bg-card);
        border-bottom: 2px solid var(--primary);
    }

    .detail-panel .btn-close {
        width: 44px;
        height: 44px;
        font-size: 2rem;
        background: var(--bg-light);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .detail-panel .panel-content {
        padding: 16px;
        padding-bottom: 100px;
    }

    /* Better spacing for activity sections on mobile */
    .detail-panel .activity-section {
        margin-bottom: 20px;
    }

    .detail-panel .activity-section h3 {
        font-size: 0.8rem;
        margin-bottom: 12px;
    }

    .detail-panel .activity-stats {
        gap: 8px;
        margin-top: 12px;
    }

    .detail-panel .activity-stat {
        padding: 12px 8px;
    }

    .detail-panel .activity-stat .value {
        font-size: 1.3rem;
    }

    .detail-panel .activity-stat .label {
        font-size: 0.7rem;
    }

    .detail-panel .activity-chart {
        height: 180px;
        padding: 12px;
        margin-bottom: 12px;
    }

    .detail-panel .position-info {
        padding: 12px;
        margin-bottom: 16px;
    }

    .detail-panel .position-info .coords {
        font-size: 0.85rem;
        margin-bottom: 8px;
    }

    .detail-panel .position-info .meta {
        font-size: 0.8rem;
        gap: 12px;
    }

    .detail-panel .controls-section {
        margin-top: 20px;
    }

    .detail-panel .controls-section h3 {
        font-size: 0.8rem;
        margin-bottom: 12px;
    }

    .detail-panel .control-buttons {
        gap: 10px;
    }

    .detail-panel .control-btn {
        padding: 14px 10px;
    }

    /* Hide map controls when detail panel is open */
    .detail-panel.open ~ .map-container .leaflet-control-zoom,
    body:has(.detail-panel.open) .leaflet-control-zoom {
        display: none;
    }

    /* Hide last-update on mobile to save space */
    #last-update {
        display: none;
    }

    /* Shorter subtitle on mobile */
    .header-subtitle {
        font-size: 0.65rem;
    }

    .header-subtitle .full-text {
        display: none;
    }

    .header-subtitle .short-text {
        display: inline;
    }

    .header {
        padding: 0 12px;
    }

    .header h1 {
        font-size: 1.2rem;
    }
}

/* === MAP NOTIFICATION === */
.map-notification {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--primary);
    animation: fadeInOut 2s ease-in-out;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    15% { opacity: 1; transform: translateX(-50%) translateY(0); }
    85% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* === TIMELINE BAR === */
.timeline-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 15px;
    z-index: 600;
}

.timeline-date-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.timeline-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.timeline-input {
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
}

.timeline-input:focus {
    outline: none;
    border-color: var(--primary);
}

.timeline-input::-webkit-calendar-picker-indicator {
    filter: invert(1);
    cursor: pointer;
}

.timeline-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;  /* Allow shrinking */
}

.timeline-current-time {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    min-width: 140px;
    box-shadow: 0 2px 8px rgba(171, 79, 211, 0.3);
}

.timeline-current-time .current-datetime {
    white-space: nowrap;
}

.timeline-slider-container {
    width: 100%;  /* Full width of parent */
    position: relative;
    height: 8px;
    background: var(--bg-dark);
    border-radius: 4px;
    overflow: visible;
}

.timeline-slider {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    width: 100%;
    height: 20px;
    background: transparent;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    z-index: 2;
}

.timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 2px solid white;
}

.timeline-slider::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.timeline-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 2px solid white;
}

.timeline-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    pointer-events: none;
    transition: width 0.1s ease;
}

.timeline-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: var(--bg-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.timeline-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.timeline-btn.playing svg {
    display: none;
}

.timeline-btn.playing::after {
    content: '';
    width: 12px;
    height: 12px;
    background: var(--bg-dark);
    border-radius: 2px;
}

/* Adjust map when timeline is visible */
.map-container.timeline-active #map {
    height: calc(100% - 60px);
}

.map-container.timeline-active .map-controls {
    bottom: 90px;
}

/* === MOBILE TIMELINE IMPROVEMENTS === */
@media (max-width: 768px) {
    .timeline-bar {
        height: auto;
        min-height: 140px;
        flex-wrap: wrap;
        padding: 12px 16px;
        gap: 8px;
        justify-content: center;
    }

    /* Timeline center takes full width on mobile */
    .timeline-center {
        order: 1;
        width: 100%;
        flex: none;
        gap: 8px;
    }

    .timeline-current-time {
        font-size: 0.8rem;
        padding: 3px 10px;
        min-width: 120px;
    }

    .timeline-slider-container {
        width: 100%;
        height: 12px;
    }

    .timeline-date-picker {
        order: 2;
        flex: 1;
        min-width: 120px;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .timeline-btn {
        order: 2;
        width: 50px;
        height: 50px;
    }

    .timeline-label {
        font-size: 0.7rem;
        text-align: center;
    }

    .timeline-input {
        width: 100%;
        padding: 10px 8px;
        font-size: 0.85rem;
        text-align: center;
        min-height: 44px;
    }

    .timeline-slider {
        height: 40px;
    }

    .timeline-slider::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
        border-width: 3px;
    }

    .timeline-slider::-moz-range-thumb {
        width: 28px;
        height: 28px;
        border-width: 3px;
    }

    .timeline-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Adjust map height for taller timeline on mobile */
    .map-container.timeline-active #map {
        height: calc(100% - 140px);
    }

    .map-container.timeline-active .map-controls {
        bottom: 160px;
    }

    /* Move sidebar higher when timeline is active */
    .map-container.timeline-active ~ .sidebar,
    .main-container:has(.timeline-active) .sidebar {
        bottom: 140px;
    }
}

/* === STORAGE INFO SECTION === */
.storage-info {
    background: var(--bg-light);
    border-radius: 12px;
    padding: 15px;
}

.storage-stats {
    display: flex;
    justify-content: space-around;
    gap: 15px;
}

.storage-stats .stat {
    text-align: center;
    flex: 1;
}

.storage-stats .stat .value {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--primary);
    display: block;
    margin-bottom: 4px;
}

.storage-stats .stat .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.storage-stats .stat .value.source-combined {
    color: var(--success);
}

.storage-stats .stat .value.source-storage {
    color: var(--secondary);
}

.storage-stats .stat .value.source-unknown {
    color: var(--text-secondary);
}

/* === MOBILE TOGGLE BUTTON === */
.mobile-only {
    display: none;
}

#toggle-info-btn.active {
    background: var(--primary);
    color: var(--bg-dark);
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex;
    }
}
