/* Smart Home IoT - Stylesheet - Dark Theme */

:root {
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --secondary: #9ca3af;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
    --radius: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Navbar */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
}

.nav-brand a {
    color: inherit;
    text-decoration: none;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-user span {
    color: var(--text-secondary);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.875rem;
    font-weight: 600;
}

.back-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    display: inline-block;
}

.back-link:hover {
    text-decoration: underline;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg-hover);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Auth Pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    text-align: center;
    margin-bottom: 0.5rem;
}

.auth-card h2 {
    text-align: center;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    color: var(--text-secondary);
}

.auth-link a {
    color: var(--primary);
    text-decoration: none;
}

.auth-link a:hover {
    text-decoration: underline;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.2s;
    background: var(--bg);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-error {
    background: rgba(248, 113, 113, 0.1);
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.alert-success {
    background: rgba(52, 211, 153, 0.1);
    color: var(--success);
    border: 1px solid rgba(52, 211, 153, 0.3);
}

/* Device Grid */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

/* Device Card */
.device-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    transition: box-shadow 0.2s;
}

.device-card:hover {
    box-shadow: var(--shadow-lg);
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.device-info {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.device-icon {
    font-size: 2rem;
}

.device-name {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.device-type {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.device-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-weight: 500;
}

.device-status.online {
    background: #ecfdf5;
    color: var(--success);
}

.device-status.offline {
    background: #f3f4f6;
    color: var(--secondary);
}

.device-controls {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: var(--radius);
}

.device-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Power Button */
.power-control {
    margin-bottom: 1rem;
}

.power-btn {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid;
    transition: all 0.2s;
}

.power-btn.on {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.power-btn.off {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text-secondary);
}

.power-btn:hover {
    transform: scale(1.02);
}

.power-icon {
    margin-right: 0.5rem;
}

/* Range Controls */
.range-control {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.range-control input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    appearance: none;
    cursor: pointer;
}

.range-control input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

.range-value {
    min-width: 60px;
    text-align: right;
    font-weight: 500;
    color: var(--text);
}

.temperature-control label,
.brightness-control label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.temp-value,
.brightness-value {
    color: var(--primary);
    font-weight: 600;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    margin: 2rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close:hover {
    color: var(--text);
}

.modal-content form {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    grid-column: 1 / -1;
}

/* Device Detail Page */
.device-detail {
    display: grid;
    gap: 1.5rem;
    /* grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); */
}

.detail-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.detail-card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.detail-header h2 {
    margin-bottom: 0;
}

.detail-list {
    display: grid;
    gap: 1rem;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.detail-item dt {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.detail-item dd {
    font-weight: 500;
    text-transform: capitalize;
}

.control-panel {
    display: grid;
    gap: 1.5rem;
}

.control-section h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

/* HTMX loading indicator */
.htmx-request {
    opacity: 0.7;
    pointer-events: none;
}

.htmx-request::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 0.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        padding: 1rem;
    }

    .container {
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .device-grid {
        grid-template-columns: 1fr;
    }

    .device-detail {
        grid-template-columns: 1fr;
    }

    .sensors-grid {
        grid-template-columns: 1fr;
    }
}

/* Thermostat Sensor Styles */
.sensors-section {
    margin-top: 1.5rem;
}

.sensors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.sensor-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.sensor-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.sensor-icon {
    font-size: 1.25rem;
}

.sensor-id {
    font-weight: 600;
    flex: 1;
}

.heater-indicator {
    font-size: 1rem;
}

.heater-indicator.on {
    color: var(--danger);
}

.heater-indicator.off {
    color: var(--secondary);
}

.sensor-readings {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.reading {
    display: flex;
    flex-direction: column;
}

.reading-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.reading-value {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.reading-value.low {
    color: var(--warning);
}

.sensor-footer {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.last-updated {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.no-sensors {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.no-sensors .hint {
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

.thermostat-status {
    margin-bottom: 1rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.status-badge.online {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.status-badge.offline {
    background: rgba(107, 114, 128, 0.1);
    color: var(--secondary);
}

.thermostat-target {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.target-label {
    font-size: 0.875rem;
    opacity: 0.9;
}

.target-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.reading-value.target {
    color: var(--primary);
}

/* Temperature Control Slider */
.temperature-control {
    margin-top: 0.5rem;
}

.temperature-control label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.temperature-control .range-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.temperature-control .range-min,
.temperature-control .range-max {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.temperature-control input[type="range"] {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #3b82f6, #ef4444);
    appearance: none;
    cursor: pointer;
}

.temperature-control input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 3px solid var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.temperature-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.temperature-control input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 3px solid var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.temperature-control .temp-display {
    text-align: center;
    margin-top: 0.75rem;
}

.temperature-control .temp-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.temp-control {
    padding: 0.5rem 0;
}

/* Heater Status Control */
.heater-status-control {
    margin-bottom: 1rem;
}

.heater-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-weight: 600;
    transition: all 0.3s ease;
}

.heater-indicator.heating {
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    color: white;
    animation: pulse-heating 2s ease-in-out infinite;
}

.heater-indicator.idle {
    background: linear-gradient(135deg, #74b9ff, #0984e3);
    color: white;
}

.heater-indicator.unknown {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.heater-icon {
    font-size: 1.25rem;
}

.heater-text {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

@keyframes pulse-heating {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(238, 90, 36, 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(238, 90, 36, 0);
    }
}

/* Card Sensors Display */
.card-sensors {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 1rem;
}

.card-sensor-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.card-sensor-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.card-sensor-item:first-child {
    padding-top: 0;
}

.sensor-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.sensor-temp {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.sensor-humidity {
    font-size: 0.875rem;
    color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
}

/* Delete Sensor Button */
.btn-delete-sensor {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.2s;
    margin-left: auto;
}

.btn-delete-sensor:hover {
    opacity: 1;
    transform: scale(1.1);
}

.sensor-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Graphs Section */
.graphs-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.graphs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.graphs-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.graph-controls select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
}

.graph-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.reset-zoom-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.reset-zoom-btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}

.graph-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-style: italic;
}

.reset-graph-btn {
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    margin-left: 0.5rem;
    transition: all 0.2s;
}

.reset-graph-btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
    color: var(--primary);
}

.graphs-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.graph-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.graph-card-wide {
    grid-column: 1 / -1;
}

.graph-card-wide .graph-svg {
    min-height: 250px;
}

.graph-card h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.graph-svg {
    width: 100%;
    min-height: 200px;
}

.graph-svg svg {
    width: 100%;
    height: auto;
}

.axis text {
    font-size: 10px;
    fill: var(--text-secondary);
}

.axis path,
.axis line {
    stroke: var(--border);
}

.graph-line {
    fill: none;
    stroke-width: 2;
}

.target-line {
    stroke-dasharray: 5, 3;
}

.no-graph-data {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.graph-tooltip {
    position: absolute;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.75rem;
    pointer-events: none;
    z-index: 1000;
    line-height: 1.4;
    box-shadow: var(--shadow-lg);
}

.legend text {
    fill: var(--text-secondary);
}

@media (max-width: 768px) {
    .graphs-container {
        grid-template-columns: 1fr;
    }
    
    .graphs-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
}
