/**
 * CARD LAYOUT STYLING - INTEGRATED WITH DATA-CARD
 * Modern CSS Grid with dynamic resizable cards
 * 
 * Features:
 * - Desktop: Max 2 columns, resizable cards (traffic, events, stories)
 * - Mobile: Single column, locked heights
 * - Smooth transitions and visual feedback
 * - Card borders responsive to alert status
 * - Status indicator dots with animations
 */

/* ============================================================
   MAIN CONTAINER - GRID SYSTEM
   ============================================================ */

.main-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--spacing, 16px);
    grid-auto-flow: dense;
    grid-auto-rows: auto;
    width: 100%;
    height: auto;
    padding: var(--spacing, 16px);
}

/* ============================================================
   CARD CONTAINER - BASE STYLES (Integrated)
   ============================================================ */

.data-card {
    position: relative;
    background: var(--secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius, 8px);
    padding: var(--spacing, 16px);
    overflow: hidden;
    overflow-y: auto;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: var(--card-min-height, 280px);
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.data-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    border-color: var(--highlight);
    transform: translateY(-2px);
}

.data-card.resizing {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    border-color: var(--highlight);
    z-index: 100;
    opacity: 0.95;
}

/* Card status borders - CRITICAL for visual feedback */
.data-card.alert-status {
    border: 2px solid var(--error) !important;
    animation: pulse-border-alert 2s infinite;
    box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.1), 0 4px 16px rgba(244, 67, 54, 0.2);
}

.data-card.warning-status {
    border: 2px solid var(--warning) !important;
    animation: pulse-border-warning 2.5s infinite;
    box-shadow: 0 0 0 3px rgba(245, 124, 0, 0.1), 0 4px 16px rgba(245, 124, 0, 0.15);
}

.data-card.success-status {
    border: 2px solid var(--success) !important;
    box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.1);
}

@keyframes pulse-border-alert {
    0%, 100% { border-color: var(--error); box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.1), 0 4px 16px rgba(244, 67, 54, 0.2); }
    50% { border-color: var(--error); box-shadow: 0 0 0 6px rgba(244, 67, 54, 0.2), 0 4px 16px rgba(244, 67, 54, 0.3); }
}

@keyframes pulse-border-warning {
    0%, 100% { border-color: var(--warning); box-shadow: 0 0 0 3px rgba(245, 124, 0, 0.1), 0 4px 16px rgba(245, 124, 0, 0.15); }
    50% { border-color: var(--warning); box-shadow: 0 0 0 6px rgba(245, 124, 0, 0.15), 0 4px 16px rgba(245, 124, 0, 0.2); }
}

/* ============================================================
   RESIZABLE CARDS - DESKTOP ONLY
   ============================================================ */

[data-resizable="true"] {
    cursor: grab;
    user-select: none;
}

[data-resizable="true"]:active {
    cursor: grabbing;
}

/* ============================================================
   RESIZE HANDLE
   ============================================================ */

.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, transparent 50%, var(--highlight) 50%);
    cursor: nwse-resize;
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius, 8px);
}

.resize-indicator {
    color: white;
    font-size: 10px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s;
}

[data-resizable="true"]:hover .resize-handle {
    opacity: 0.7;
}

[data-resizable="true"]:hover .resize-indicator {
    opacity: 1;
}

.resize-handle:hover {
    opacity: 1 !important;
}

.resize-handle:hover .resize-indicator {
    opacity: 1 !important;
}

/* ============================================================
   CARD TITLES & CONTENT
   ============================================================ */

.data-card h1,
.data-card h2,
.data-card h3 {
    margin: 0 0 var(--spacing, 16px) 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 40px; /* Space for resize handle */
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    color: var(--highlight);
}

.data-card .card-link {
    color: inherit;
    text-decoration: none;
    transition: color 0.3s ease;
    flex: 1;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.data-card .card-link:hover {
    color: var(--highlight);
    text-decoration: underline;
}

/* Status indicator dots - MAJOR FEATURE */
.status-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
    flex-shrink: 0;
    box-shadow: 0 0 8px rgba(46, 125, 50, 0.5);
}

.status-indicator.alert {
    background: var(--error);
    animation: pulse-alert 1.5s infinite;
    box-shadow: 0 0 12px rgba(244, 67, 54, 0.8);
}

.status-indicator.warning {
    background: var(--warning);
    animation: pulse-warning 1.8s infinite;
    box-shadow: 0 0 10px rgba(245, 124, 0, 0.6);
}

.status-indicator.success {
    background: var(--success);
    animation: pulse 2s infinite;
    box-shadow: 0 0 8px rgba(46, 125, 50, 0.5);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes pulse-alert {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.2); }
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.15); }
}

/* ============================================================
   WIDE CARD (Full Width - Maps)
   ============================================================ */

.wide-card,
[data-card-type="traffic"] {
    grid-column: 1 / -1;
    width: 100%;
}

.map-traffic {
    width: 100%;
    height: 420px;
    margin-top: var(--spacing, 16px);
    border-radius: calc(var(--radius, 8px) - 2px);
    overflow: hidden;
}

.map-traffic iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ============================================================
   SPECIAL CARDS - SIZING PREFERENCES
   ============================================================ */

[data-card-type="stories"],
[data-card-type="events"],
[data-card-type="civic"] {
    min-height: 300px;
}

[data-card-type="alerts"],
[data-card-type="rail"] {
    min-height: 200px;
}

/* ============================================================
   IFRAME HANDLING IN CARDS
   ============================================================ */

[data-card-id] iframe {
    width: 100%;
    display: block;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius, 8px) - 2px);
}

/* ============================================================
   MOBILE RESPONSIVE LAYOUT
   ============================================================ */

@media (max-width: 768px) {
    .main-container {
        grid-template-columns: 1fr;
        grid-auto-flow: row;
    }

    .wide-card,
    [data-card-type="traffic"] {
        grid-column: 1;
    }

    [data-resizable="true"] {
        cursor: auto;
    }

    .resize-handle {
        display: none !important;
    }

    [data-card-id] {
        min-height: auto;
        max-height: none;
    }

    [data-card-id] h1,
    [data-card-id] h2,
    [data-card-id] h3 {
        padding-right: var(--spacing, 16px);
    }

    .map-traffic {
        height: 300px;
    }
}

/* ============================================================
   TABLET RESPONSIVE LAYOUT
   ============================================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    .main-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .wide-card,
    [data-card-type="traffic"] {
        grid-column: 1 / -1;
    }
}

/* ============================================================
   DESKTOP OPTIMIZED LAYOUT
   ============================================================ */

@media (min-width: 1025px) {
    .main-container {
        grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    }

    [data-card-id]:focus-within {
        box-shadow: var(--card-shadow-hover);
    }
}

/* ============================================================
   ACCESSIBILITY & FOCUS STATES
   ============================================================ */

[data-card-id]:focus-visible {
    outline: 2px solid var(--highlight);
    outline-offset: 2px;
}

[data-card-id] a:focus-visible {
    outline: 2px solid var(--highlight);
    outline-offset: 2px;
}

/* ============================================================
   LOADING & EMPTY STATES
   ============================================================ */

[data-card-id][data-loading="true"] {
    opacity: 0.6;
    pointer-events: none;
}

[data-card-id]:empty::after {
    content: 'Loading...';
    color: var(--text-secondary);
    font-style: italic;
    display: block;
    padding: var(--spacing, 16px);
    text-align: center;
}

/* ============================================================
   DRAG & DROP SUPPORT
   ============================================================ */

[data-card-id][draggable="true"] {
    cursor: move;
}

[data-card-id].drag-over {
    opacity: 0.5;
    border: 2px dashed var(--highlight);
}

.drag-over-active [data-card-id] {
    background: rgba(211, 47, 47, 0.05);
}

/* ============================================================
   PRINT STYLES
   ============================================================ */

@media print {
    [data-resizable="true"] {
        cursor: auto;
    }

    .resize-handle {
        display: none;
    }

    [data-card-id] {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .main-container {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   DARK MODE ENHANCEMENTS
   ============================================================ */

@media (prefers-color-scheme: dark) {
    [data-card-id]:hover {
        background: rgba(255, 255, 255, 0.05);
    }

    .resize-handle {
        background: linear-gradient(135deg, transparent 50%, rgba(255, 107, 107, 0.3) 50%);
    }

    .resize-handle:hover {
        background: linear-gradient(135deg, transparent 50%, rgba(255, 107, 107, 0.6) 50%);
    }
}

/* ============================================================
   REDUCED MOTION SUPPORT
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    [data-card-id],
    .resize-handle,
    .status-indicator,
    [data-card-id] .card-link {
        transition: none;
        animation: none;
    }

    .status-indicator {
        animation: none;
    }
}
