/* Vogelhaus Dashboard – Dark Theme */

:root {
    --bg: #0f172a;
    --card: #1e293b;
    --border: #334155;
    --text: #e2e8f0;
    --muted: #7a8fa8;
    --accent: #22c55e;
    --warn: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
}

/* Override Pico defaults */
[data-theme="dark"] {
    --pico-background-color: var(--bg);
    --pico-card-background-color: var(--card);
    --pico-card-border-color: var(--border);
    --pico-color: var(--text);
    --pico-muted-color: var(--muted);
    --pico-primary: var(--accent);
}

body {
    padding-bottom: 70px; /* Space for bottom nav */
}

/* ============ NAV ============ */

.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem;
}

.top-nav .nav-links {
    gap: 0;
}

.top-nav .nav-links a {
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-size: 0.85rem;
    text-decoration: none;
    white-space: nowrap;
}

.top-nav .nav-links a.active {
    background: var(--accent);
    color: #000;
}

.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 0.3rem 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
}
.bottom-nav::-webkit-scrollbar { display: none; }

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.2rem 0.3rem;
    font-size: 1.1rem;
    text-decoration: none;
    color: var(--muted);
    min-width: 44px;
    flex-shrink: 0;
}

.bottom-nav a span {
    font-size: 0.55rem;
    margin-top: 1px;
    white-space: nowrap;
}

.bottom-nav a.active {
    color: var(--accent);
}

@media (max-width: 768px) {
    .top-nav .nav-links { display: none; }
    .bottom-nav { display: flex; }
    body { padding-bottom: 65px; }
}

@media (min-width: 769px) {
    .bottom-nav { display: none; }
}

/* ============ COMPONENTS ============ */

.big-num {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}

.big-num.warn { color: var(--warn); }

.muted { color: var(--muted); }

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge.ok { background: rgba(34,197,94,0.2); color: var(--accent); }
.badge.warn { background: rgba(245,158,11,0.2); color: var(--warn); }
.badge.error { background: rgba(239,68,68,0.2); color: var(--error); }

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
}

.dot.green { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot.red { background: var(--error); box-shadow: 0 0 6px var(--error); }

.flash {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: rgba(34,197,94,0.15);
    color: var(--accent);
    border: 1px solid rgba(34,197,94,0.3);
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

.flash.error {
    background: rgba(239,68,68,0.15);
    color: var(--error);
    border-color: rgba(239,68,68,0.3);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============ SWITCHES ============ */

.switch-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

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

.switch-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.switch-info small { color: var(--muted); }

/* ============ SERVICES ============ */

.svc-status {
    display: flex;
    align-items: center;
    padding: 0.25rem 0;
}

.devmode-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

button.small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    min-height: 44px;
    min-width: 44px;
}

button.danger {
    border-color: var(--error);
    color: var(--error);
}

/* ============ TUNING ============ */

.tuning-param {
    margin-bottom: 1.5rem;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

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

.slider-row output {
    min-width: 50px;
    text-align: center;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--accent);
}

/* Range slider: größer und touch-freundlich */
[data-theme="dark"] input[type="range"],
input[type="range"] {
    -webkit-appearance: none !important;
    appearance: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 44px !important;
    height: 44px !important;
    background: transparent !important;
    cursor: pointer !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    display: block !important;
}

[data-theme="dark"] input[type="range"]::-webkit-slider-runnable-track,
input[type="range"]::-webkit-slider-runnable-track {
    height: 24px !important;
    border-radius: 12px !important;
    background: var(--border) !important;
    border: none !important;
}

[data-theme="dark"] input[type="range"]::-webkit-slider-thumb,
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none !important;
    appearance: none !important;
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    background: var(--accent) !important;
    margin-top: -6px !important;
    border: 3px solid var(--bg) !important;
    box-shadow: 0 0 6px rgba(0,0,0,0.5) !important;
}

[data-theme="dark"] input[type="range"]::-moz-range-track,
input[type="range"]::-moz-range-track {
    height: 24px !important;
    border-radius: 12px !important;
    background: var(--border) !important;
    border: none !important;
}

[data-theme="dark"] input[type="range"]::-moz-range-thumb,
input[type="range"]::-moz-range-thumb {
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    background: var(--accent) !important;
    border: 3px solid var(--bg) !important;
    box-shadow: 0 0 6px rgba(0,0,0,0.5) !important;
}

/* ============ MEDIA ============ */

.snapshot-wrap {
    text-align: center;
}

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

.detection-img {
    max-width: 100%;
    border-radius: 8px;
}

.video-full {
    width: 100%;
    border-radius: 8px;
    background: #000;
}

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

.photo-card {
    text-align: center;
}

.photo-card img {
    width: 100%;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s;
}

.photo-card img.zoomed {
    transform: scale(2);
    position: relative;
    z-index: 50;
}

.photo-card small { color: var(--muted); }

/* ============ GRIDS ============ */

.sensor-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    text-align: center;
}

.sensor-grid div small {
    display: block;
    color: var(--muted);
    font-size: 0.75rem;
}

.day-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.segment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.segment-btn {
    font-size: 0.75rem !important;
}

/* ============ LOG VIEWER ============ */

.log-view {
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.75rem;
    line-height: 1.5;
    background: #0a0f1a;
    padding: 0.75rem;
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============ TABLE ============ */

.table-wrap {
    overflow-x: auto;
}

table {
    font-size: 0.85rem;
}

/* ============ PROGRESS ============ */

progress.warn::-webkit-progress-value {
    background: var(--warn);
}

/* ============ STATUS CARD ============ */

.status-card {
    min-height: 120px;
}

/* ============ PWA ============ */

@media (display-mode: standalone) {
    .top-nav { padding-top: env(safe-area-inset-top, 0); }
    .bottom-nav { padding-bottom: env(safe-area-inset-bottom, 0); }
    body { padding-bottom: calc(65px + env(safe-area-inset-bottom, 0)); }
}

/* ============ FLOATING PREVIEW ============ */

#float-preview {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 320px;
    z-index: 200;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
    overflow: hidden;
    transition: width 0.2s ease;
    touch-action: none;
}

#float-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.6rem;
    background: var(--border);
    font-size: 0.72rem;
    cursor: grab;
    user-select: none;
    white-space: nowrap;
    gap: 0.5rem;
}

#float-preview-header:active { cursor: grabbing; }

#pv-vals { color: var(--accent); font-weight: 600; }

#float-preview img,
#float-preview video {
    width: 100%;
    display: block;
    aspect-ratio: 16/9;
    object-fit: cover;
    background: #000;
}

#float-preview-resize {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, var(--muted) 50%);
    border-radius: 0 0 10px 0;
    opacity: 0.5;
}

#float-preview-resize:hover { opacity: 1; }

/* Größen-Varianten (Doppelklick) */
#float-preview.fp-large { width: 520px; }
#float-preview.fp-small { width: 180px; }

/* Mobile: etwas kleiner */
@media (max-width: 768px) {
    #float-preview {
        width: 240px;
        bottom: calc(72px + env(safe-area-inset-bottom, 0));
        right: 8px;
    }
    #float-preview.fp-large { width: 360px; }
    #float-preview.fp-small { width: 140px; }
}

/* ============ TUNING GRID ============ */

.tuning-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
}

@media (max-width: 600px) {
    .tuning-grid-2col { grid-template-columns: 1fr; }
}
