/* ========================================
 * Hardware Platform - Dashboard Styles
 * Modern, clean dashboard that coordinates
 * with the homepage (shawn2686.com)
 * ======================================== */

:root {
    --hw-primary: #2c3e50;
    --hw-accent: #3498db;
    --hw-text: #333333;
    --hw-text-light: #666666;
    --hw-bg: #f5f6fa;
    --hw-card-bg: #ffffff;
    --hw-border: #e0e0e0;
    --hw-online: #27ae60;
    --hw-offline: #95a5a6;
    --hw-error: #e74c3c;
    --hw-warning: #f39c12;
    --hw-radius: 8px;
    --hw-shadow: 0 2px 8px rgba(0,0,0,0.06);
    --hw-shadow-hover: 0 6px 20px rgba(0,0,0,0.1);
    --hw-font: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --hw-mono: 'Courier New', monospace;
}

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

body {
    font-family: var(--hw-font);
    background: var(--hw-bg);
    color: var(--hw-text);
    line-height: 1.6;
    font-size: 15px;
}

/* --- Layout --- */
.hw-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.hw-header {
    background: var(--hw-card-bg);
    border-bottom: 1px solid var(--hw-border);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--hw-shadow);
}

.hw-header h1 {
    font-size: 1.3rem;
    color: var(--hw-primary);
    font-weight: 700;
}

.hw-header a {
    color: var(--hw-accent);
    text-decoration: none;
    font-size: 0.9rem;
}

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

/* --- Cards --- */
.hw-card {
    background: var(--hw-card-bg);
    border: 1px solid var(--hw-border);
    border-radius: var(--hw-radius);
    padding: 20px;
    box-shadow: var(--hw-shadow);
    transition: box-shadow 0.2s, transform 0.2s;
}

.hw-card:hover {
    box-shadow: var(--hw-shadow-hover);
}

.hw-card-title {
    font-size: 1.1rem;
    color: var(--hw-primary);
    margin-bottom: 15px;
    font-weight: 700;
    border-bottom: 2px solid var(--hw-primary);
    padding-bottom: 8px;
}

/* --- Stats Grid --- */
.hw-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.hw-stat-card {
    background: var(--hw-card-bg);
    border: 1px solid var(--hw-border);
    border-radius: var(--hw-radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--hw-shadow);
}

.hw-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--hw-primary);
    margin: 5px 0;
}

.hw-stat-label {
    font-size: 0.85rem;
    color: var(--hw-text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hw-stat-online { color: var(--hw-online); }
.hw-stat-offline { color: var(--hw-offline); }
.hw-stat-tasks { color: var(--hw-accent); }
.hw-stat-photos { color: var(--hw-warning); }

/* --- Device Grid --- */
.hw-device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.hw-device-card {
    background: var(--hw-card-bg);
    border: 1px solid var(--hw-border);
    border-radius: var(--hw-radius);
    overflow: hidden;
    box-shadow: var(--hw-shadow);
    transition: all 0.2s;
}

.hw-device-card:hover {
    box-shadow: var(--hw-shadow-hover);
    transform: translateY(-2px);
}

.hw-device-card-preview {
    width: 100%;
    aspect-ratio: 4/3;
    background: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.hw-device-card-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hw-device-card-preview .no-preview {
    color: #555;
    font-size: 0.85rem;
}

.hw-device-card-body {
    padding: 15px;
}

.hw-device-card-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--hw-primary);
    margin-bottom: 5px;
}

.hw-device-card-info {
    font-size: 0.85rem;
    color: var(--hw-text-light);
    margin-bottom: 3px;
}

.hw-status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.hw-status-online {
    background: #e8f5e9;
    color: var(--hw-online);
}

.hw-status-offline {
    background: #f0f0f0;
    color: var(--hw-offline);
}

.hw-status-running {
    background: #e3f2fd;
    color: var(--hw-accent);
}

/* --- Device Detail Page --- */
.hw-device-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: 20px;
}

.hw-device-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}

.hw-info-item {
    background: var(--hw-card-bg);
    border: 1px solid var(--hw-border);
    border-radius: 6px;
    padding: 12px;
}

.hw-info-label {
    font-size: 0.75rem;
    color: var(--hw-text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 3px;
}

.hw-info-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--hw-text);
    font-family: var(--hw-mono);
}

/* --- 24-hour Device State Timeline --- */
.hw-state-timeline-card {
    overflow: hidden;
}

.hw-state-timeline-title {
    border-bottom: 0;
    margin: 0;
    padding: 0;
}

.hw-timeline-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 10px;
    margin: 18px 0 14px;
}

.hw-timeline-metric {
    background: #f7f8f9;
    border: 1px solid var(--hw-border);
    border-radius: 6px;
    padding: 9px 11px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--hw-text-light);
}

.hw-timeline-metric strong {
    color: var(--hw-text);
    font-family: var(--hw-mono);
    font-size: 0.9rem;
    white-space: nowrap;
}

.hw-state-timeline {
    display: flex;
    width: 100%;
    height: 34px;
    overflow: hidden;
    background: #9aa1a8;
    border: 1px solid #7f878e;
    border-radius: 7px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.18);
}

.hw-timeline-segment {
    flex: 0 0 auto;
    height: 100%;
    min-width: 1px;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.hw-timeline-segment:hover {
    filter: brightness(1.08);
    outline: 2px solid rgba(255, 255, 255, 0.85);
    outline-offset: -2px;
}

.hw-timeline-offline { background: #9aa1a8; }
.hw-timeline-standby { background: #2eae60; }
.hw-timeline-camera { background: #e04444; }

.hw-timeline-axis {
    position: relative;
    height: 25px;
    margin: 5px 0 4px;
    color: var(--hw-text-light);
    font-family: var(--hw-mono);
    font-size: 0.72rem;
}

.hw-timeline-tick {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    white-space: nowrap;
}

.hw-timeline-tick::before {
    content: '';
    display: block;
    width: 1px;
    height: 5px;
    margin: 0 auto 2px;
    background: var(--hw-border);
}

.hw-timeline-tick:first-child { transform: none; }
.hw-timeline-tick:first-child::before { margin-left: 0; }
.hw-timeline-tick:last-child { transform: translateX(-100%); }
.hw-timeline-tick:last-child::before { margin-right: 0; }

.hw-timeline-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    color: var(--hw-text-light);
    font-size: 0.78rem;
}

.hw-timeline-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.hw-timeline-swatch {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

@media (max-width: 720px) {
    .hw-timeline-metrics {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .hw-timeline-legend {
        flex-direction: column;
        gap: 6px;
    }
}

/* --- Preview Section --- */
.hw-preview-container {
    background: #1a1a1a;
    border-radius: var(--hw-radius);
    overflow: hidden;
    position: relative;
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hw-preview-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.hw-preview-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: var(--hw-mono);
}

.hw-preview-loading {
    color: #888;
    font-size: 0.9rem;
}

.hw-preview-controls {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

/* --- Forms --- */
.hw-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hw-device-name-input {
    width: min(220px, 36vw);
    padding: 6px 9px;
    border: 1px solid var(--hw-border);
    border-radius: 4px;
    font: inherit;
}

.hw-device-name-input:focus {
    outline: none;
    border-color: var(--hw-accent);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}

.hw-form-group {
    margin-bottom: 15px;
}

.hw-form-group label {
    display: block;
    font-size: 0.9rem;
    color: var(--hw-text);
    margin-bottom: 5px;
    font-weight: 600;
}

.hw-form-group input,
.hw-form-group select,
.hw-form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--hw-border);
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: var(--hw-font);
    background: #fff;
    color: var(--hw-text);
    transition: border-color 0.2s;
}

.hw-form-group input:focus,
.hw-form-group select:focus,
.hw-form-group textarea:focus {
    outline: none;
    border-color: var(--hw-accent);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}

.hw-form-group input:disabled,
.hw-form-group select:disabled {
    background: #f0f0f0;
    color: var(--hw-text-light);
    cursor: not-allowed;
}

.hw-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* --- Buttons --- */
.hw-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--hw-font);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    min-width: 80px;
}

.hw-btn-primary {
    background: var(--hw-accent);
    color: #fff;
}

.hw-btn-primary:hover {
    background: #2980b9;
}

.hw-btn-primary:disabled {
    background: #b0d4e8;
    cursor: not-allowed;
}

.hw-btn-secondary {
    background: #ecf0f1;
    color: var(--hw-text);
}

.hw-btn-secondary:hover {
    background: #d5dbdb;
}

.hw-btn-danger {
    background: var(--hw-error);
    color: #fff;
}

.hw-btn-danger:hover {
    background: #c0392b;
}

.hw-btn-danger:disabled {
    background: #f5b7b1;
    cursor: not-allowed;
}

.hw-btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* --- Slider --- */
.hw-slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.hw-slider-row label {
    flex: 0 0 100px;
    font-size: 0.85rem;
}

.hw-slider-row input[type="range"] {
    flex: 1;
}

.hw-slider-row .hw-slider-value {
    flex: 0 0 60px;
    text-align: right;
    font-family: var(--hw-mono);
    font-size: 0.85rem;
}

.hw-toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.hw-toggle-row .hw-toggle-label {
    flex: 0 0 100px;
    font-size: 0.85rem;
    cursor: pointer; /* whole text label is clickable too */
}

.hw-toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    cursor: pointer;
    /* Larger hit area: the label itself spans the switch; padding extends it */
    padding: 4px 6px;
    margin: -4px -6px;
}

.hw-toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    /* kept focusable for keyboard access (NOT display:none) */
}

.hw-toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ccc;
    border-radius: 22px;
    transition: 0.2s;
}

.hw-toggle-slider:before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}

.hw-toggle-switch input:checked + .hw-toggle-slider {
    background: var(--hw-accent);
}

.hw-toggle-switch input:focus-visible + .hw-toggle-slider {
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.35);
    outline: 1px solid var(--hw-accent);
}

.hw-toggle-switch input:checked + .hw-toggle-slider:before {
    transform: translateX(22px);
}

/* --- Tabs --- */
.hw-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--hw-border);
    flex-wrap: wrap;
}

.hw-tab {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--hw-text-light);
    border: none;
    background: none;
    font-family: var(--hw-font);
    font-weight: 600;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.hw-tab.active {
    color: var(--hw-primary);
    border-bottom-color: var(--hw-primary);
}

.hw-tab:hover {
    color: var(--hw-primary);
}

.hw-tab-content {
    display: none;
}

.hw-tab-content.active {
    display: block;
}

/* --- Photo Gallery --- */
.hw-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.hw-photo-item {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    aspect-ratio: 4/3;
    background: #1a1a1a;
}

.hw-photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.hw-photo-item:hover img {
    transform: scale(1.05);
}

.hw-photo-item-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 5px 8px;
    font-size: 0.75rem;
    font-family: var(--hw-mono);
}

/* --- Task list --- */
.hw-task-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border: 1px solid var(--hw-border);
    border-radius: 6px;
    margin-bottom: 8px;
    background: #fff;
    transition: box-shadow 0.2s;
}

.hw-task-item:hover {
    box-shadow: var(--hw-shadow);
}

.hw-task-name {
    font-weight: 600;
    color: var(--hw-primary);
}

.hw-task-info {
    font-size: 0.8rem;
    color: var(--hw-text-light);
}

.hw-task-error {
    margin-top: 4px;
    color: #b91c1c;
    font-size: 0.8rem;
    overflow-wrap: anywhere;
}

.hw-task-error-source {
    opacity: 0.7;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.hw-task-completion-source {
    margin-top: 3px;
    color: var(--hw-text-light);
    font-size: 0.75rem;
}

.hw-task-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* --- Toast/Alert --- */
.hw-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 6px;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    max-width: 400px;
    animation: hw-slide-in 0.3s ease;
}

.hw-toast-success { background: var(--hw-online); }
.hw-toast-error { background: var(--hw-error); }
.hw-toast-warning { background: var(--hw-warning); }
.hw-toast-info { background: var(--hw-accent); }

@keyframes hw-slide-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* --- Login Page --- */
.hw-login-container {
    max-width: 400px;
    margin: 80px auto;
    padding: 40px 20px;
}

.hw-login-card {
    background: #fff;
    border: 1px solid var(--hw-border);
    border-radius: var(--hw-radius);
    padding: 30px;
    box-shadow: var(--hw-shadow);
}

.hw-login-card h2 {
    color: var(--hw-primary);
    margin-bottom: 20px;
    text-align: center;
}

.hw-login-error {
    background: #fdf2f2;
    color: var(--hw-error);
    padding: 10px 15px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 0.85rem;
    display: none;
}

.hw-login-error.show {
    display: block;
}

.hw-login-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.85rem;
}

.hw-login-footer a {
    color: var(--hw-accent);
    text-decoration: none;
}

/* --- Spinner --- */
.hw-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top-color: var(--hw-accent);
    border-radius: 50%;
    animation: hw-spin 0.6s linear infinite;
}

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

/* --- Fullscreen preview --- */
.hw-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.hw-fullscreen.show {
    display: flex;
}

.hw-fullscreen img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
}

.hw-fullscreen-close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    background: rgba(0,0,0,0.5);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .hw-container {
        padding: 10px;
    }
    
    .hw-header {
        padding: 10px;
    }
    
    .hw-header h1 {
        font-size: 1.1rem;
    }
    
    .hw-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .hw-device-grid {
        grid-template-columns: 1fr;
    }
    
    .hw-form-row {
        grid-template-columns: 1fr;
    }
    
    .hw-device-info-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .hw-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    
    .hw-tab {
        white-space: nowrap;
    }
    
    .hw-slider-row {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }
    
    .hw-slider-row label {
        flex: none;
    }
    
    .hw-slider-row .hw-slider-value {
        text-align: left;
    }
    
    .hw-toggle-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .hw-login-container {
        margin: 30px 10px;
    }
    
    .hw-photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .hw-preview-controls {
        flex-direction: column;
    }
    
    .hw-preview-controls .hw-btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .hw-stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .hw-stat-value {
        font-size: 1.5rem;
    }
    
    .hw-device-info-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Utility classes --- */
.hw-text-mono { font-family: var(--hw-mono); }
.hw-text-sm { font-size: 0.85rem; }
.hw-text-muted { color: var(--hw-text-light); }
.hw-text-center { text-align: center; }
.hw-mt-1 { margin-top: 10px; }
.hw-mt-2 { margin-top: 20px; }
.hw-mb-1 { margin-bottom: 10px; }
.hw-mb-2 { margin-bottom: 20px; }
.hw-hidden { display: none !important; }
.hw-flex { display: flex; }
.hw-flex-wrap { flex-wrap: wrap; }
.hw-gap-1 { gap: 10px; }
.hw-gap-2 { gap: 20px; }
.hw-align-center { align-items: center; }
.hw-justify-between { justify-content: space-between; }
