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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #0f1117;
    color: #e0e0e0;
    line-height: 1.6;
}

header {
    background: linear-gradient(135deg, #1a1d29 0%, #2d1f3d 100%);
    border-bottom: 3px solid #f59e0b;
    padding: 1.5rem 2rem;
    text-align: center;
}

header h1 {
    font-size: 1.8rem;
    color: #f59e0b;
    margin-bottom: 0.3rem;
}

header .subtitle {
    color: #9ca3af;
    font-size: 1rem;
}

header .dest {
    color: #6b7280;
    font-size: 0.85rem;
    margin-top: 0.3rem;
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

.card {
    background: #1a1d29;
    border: 1px solid #2d3348;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card h2 {
    color: #f59e0b;
    font-size: 1.3rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #2d3348;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.card h3 {
    color: #d1d5db;
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

/* Top row: webcam + current status side by side */
.top-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.top-row .card {
    margin-bottom: 0;
}

/* Webcam live */
.webcam-live select {
    background: #232738;
    border: 1px solid #2d3348;
    color: #e0e0e0;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

.webcam-img {
    width: 100%;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.webcam-img.expanded {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
    z-index: 1000;
    border-radius: 12px;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.8);
}

.webcam-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #9ca3af;
}

/* Readings Grid */
.readings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.reading-card {
    background: #232738;
    border: 1px solid #2d3348;
    border-radius: 8px;
    padding: 0.8rem;
    transition: border-color 0.2s;
}

.reading-card:hover {
    border-color: #f59e0b;
}

.reading-card.offpeak-alert {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

.offpeak-warn {
    color: #f87171;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.3rem;
}

.reading-card .label {
    font-weight: 600;
    color: #f59e0b;
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
}

.reading-card .address {
    color: #6b7280;
    font-size: 0.75rem;
    margin-bottom: 0.4rem;
}

.reading-card .time-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: #34d399;
}

.reading-card .time-value.slow {
    color: #f87171;
}

.reading-card .time-value.moderate {
    color: #fbbf24;
}

.reading-card .normal-time {
    color: #6b7280;
    font-size: 0.8rem;
}

.reading-card .meta {
    color: #4b5563;
    font-size: 0.7rem;
    margin-top: 0.2rem;
}

/* Section toggle (details/summary) */
.section-toggle {
    color: #f59e0b;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    padding: 0.3rem 0;
}

.section-toggle::-webkit-details-marker {
    display: none;
}

.section-toggle::before {
    content: '▸ ';
    display: inline;
}

details[open] .section-toggle::before {
    content: '▾ ';
}

/* Form */
.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 150px;
}

.form-group.flex-2 {
    flex: 2;
}

/* Autocomplete dropdown */
.autocomplete-wrap {
    position: relative;
}

.autocomplete-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #232738;
    border: 1px solid #3b4260;
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: 100;
    max-height: 260px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.autocomplete-dropdown.open {
    display: block;
}

.autocomplete-item {
    padding: 0.6rem 0.8rem;
    cursor: pointer;
    border-bottom: 1px solid #1f2335;
    transition: background 0.15s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: #2d3348;
}

.autocomplete-item .main-text {
    color: #e0e0e0;
    font-size: 0.95rem;
    font-weight: 500;
}

.autocomplete-item .secondary-text {
    color: #6b7280;
    font-size: 0.8rem;
    margin-top: 0.1rem;
}

.form-group label {
    color: #9ca3af;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}

.form-group input {
    background: #232738;
    border: 1px solid #2d3348;
    color: #e0e0e0;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    font-size: 0.95rem;
}

.form-group input:focus {
    outline: none;
    border-color: #f59e0b;
}

/* After-hours panel */
.afterhours-card {
    border-color: #7c3aed;
}

.afterhours-card h2 {
    color: #a78bfa;
}

.afterhours-explainer {
    color: #9ca3af;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.badge-info {
    font-size: 0.75rem;
    background: rgba(139, 92, 246, 0.2);
    color: #a78bfa;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

.afterhours-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.afterhours-item {
    background: #232738;
    border: 1px solid #2d3348;
    border-radius: 8px;
    padding: 1rem;
}

.afterhours-item .ah-label {
    font-weight: 600;
    color: #e0e0e0;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

.afterhours-item .ah-avg {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.afterhours-item .ah-avg.good { color: #34d399; }
.afterhours-item .ah-avg.warning { color: #fbbf24; }
.afterhours-item .ah-avg.bad { color: #f87171; }

.ah-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.ah-badge.bad { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.ah-badge.warning { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
.ah-badge.good { background: rgba(52, 211, 153, 0.2); color: #34d399; }

.ah-detail {
    color: #6b7280;
    font-size: 0.8rem;
    margin-top: 0.3rem;
}

.ah-breakdown {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #1f2335;
    font-size: 0.8rem;
    color: #9ca3af;
}

.ah-breakdown span {
    display: block;
    margin-top: 0.15rem;
}

/* Tab bar */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #2d3348;
    margin-bottom: 1rem;
}

.tab {
    background: none;
    border: none;
    color: #6b7280;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
    color: #9ca3af;
}

.tab.active {
    color: #f59e0b;
    border-bottom-color: #f59e0b;
}

.tab-content {
    display: none;
}

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

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.85;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-success {
    background: #10b981;
    color: white;
    white-space: nowrap;
}

.btn-danger {
    background: #ef4444;
    color: white;
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
}

.btn-sm {
    padding: 0.3rem 0.8rem;
    font-size: 0.8rem;
}

/* Controls */
.controls-row {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.controls-row label {
    color: #9ca3af;
    font-size: 0.9rem;
}

.controls-row select,
select {
    background: #232738;
    border: 1px solid #2d3348;
    color: #e0e0e0;
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

/* Charts */
.chart-container {
    position: relative;
    height: 350px;
    width: 100%;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    background: #232738;
    color: #f59e0b;
    padding: 0.6rem 0.8rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #2d3348;
}

td {
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid #1f2335;
}

tr:hover td {
    background: #1f2335;
}

/* Address list */
.address-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem;
    border-bottom: 1px solid #232738;
}

.address-item:last-child {
    border-bottom: none;
}

.address-info .addr-label {
    font-weight: 600;
    color: #e0e0e0;
}

.address-info .addr-address {
    color: #6b7280;
    font-size: 0.85rem;
}

.address-info .addr-since {
    color: #4b5563;
    font-size: 0.75rem;
}

/* Webcam History */
.webcam-timeline {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 1rem 0;
}

.webcam-timeline .snap-thumb {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid #2d3348;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s;
}

.webcam-timeline .snap-thumb:hover,
.webcam-timeline .snap-thumb.active {
    border-color: #f59e0b;
    transform: scale(1.05);
}

.snap-label {
    text-align: center;
    font-size: 0.7rem;
    color: #6b7280;
    margin-top: 0.2rem;
}

.webcam-viewer {
    text-align: center;
    min-height: 200px;
}

.webcam-viewer img {
    max-width: 100%;
    border-radius: 8px;
    cursor: pointer;
}

.webcam-viewer img.expanded {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
    z-index: 1000;
    border-radius: 12px;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.8);
}

.webcam-viewer .snap-time {
    color: #9ca3af;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Loading */
.loading {
    color: #6b7280;
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: #4b5563;
    font-size: 0.85rem;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: #232738;
    border: 1px solid #2d3348;
    border-radius: 8px;
    padding: 0.8rem 1.2rem;
    color: #e0e0e0;
    font-size: 0.9rem;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
}

.toast.success { border-color: #10b981; }
.toast.error { border-color: #ef4444; }

@keyframes slideIn {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.3rem;
    }

    .top-row {
        grid-template-columns: 1fr;
    }

    .form-row {
        flex-direction: column;
    }

    .controls-row {
        flex-direction: column;
        align-items: stretch;
    }

    .readings-grid {
        grid-template-columns: 1fr;
    }

    .chart-container {
        height: 250px;
    }

    table {
        font-size: 0.8rem;
    }

    .webcam-timeline .snap-thumb {
        width: 60px;
        height: 45px;
    }
}
