:root {
    --primary: #0066cc;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #e0a800;
    --bg-page: #f5f5f7;
    --bg-card: #ffffff;
    --bg-muted: #f8f9fa;
    --border: #dcdcdc;
    --text: #1d1d1f;
    --text-muted: #666666;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text);
    margin: 0;
    padding: 20px;
}

a.control-link,
a.control-link:visited {
    color: var(--primary);
    text-decoration: none;
    font-weight: bold;
}

.container { max-width: 1200px; margin: 0 auto; }
h1 { font-size: 20px; color: var(--primary); margin: 0; }
.status-badge { font-size: 16px; font-weight: bold; margin-left: 15px; }
.device-status { font-size: 14px; color: #555; margin-top: 4px; }

/* Gemeinsame Flex-Muster */
header,
.planer-header,
.tpl-header,
.timeline-day-header,
.timeline-label,
.nav-tabs-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-tabs,
.nav-tabs-left,
.actions,
.timeline-add-box,
.timeline-clone-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

header, .nav-tabs, .nav-tabs-between { margin-bottom: 20px; }
.nav-tabs-between { width: 100%; }
.sync-btn-form { margin: 0; }

.nav-tab {
    padding: 8px 14px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: bold;
    background: #e2e6ea;
    color: #333;
    transition: background-color 0.2s, color 0.2s;
    text-align: center;
}
.nav-tab:hover { background: #d0d5dd; }
.nav-tab.active { background: var(--primary); color: #fff; }

@media (max-width: 768px) {
    .nav-tabs { gap: 6px; }
    .nav-tab { font-size: 13px; padding: 8px 4px; }
    .nav-tab:nth-child(1),
    .nav-tab:nth-child(2),
    .nav-tab:nth-child(3) { flex: 1 1 30%; }
    .nav-tab:nth-child(4),
    .nav-tab:nth-child(5) { flex: 1 1 45%; }
}

/* Grids & Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

@media (max-width: 768px) {
    .grid-3 { grid-template-columns: 1fr; }
}

.card,
.tpl-card,
.timeline-card,
.login-box,
.planer-container {
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.card, .tpl-card, .timeline-card { border: 1px solid var(--border); }
.card { border-radius: 6px; padding: 10px 14px; }
.tpl-card { border-color: #ddd; border-radius: 6px; padding: 15px; margin-bottom: 25px; background: #fafafa; }
.timeline-card { padding: 16px; margin-bottom: 20px; }

.card-title { color: #555; font-size: 11px; font-weight: bold; text-transform: uppercase; margin-bottom: 4px; }
.card-value { color: #000; font-size: 16px; font-weight: bold; }
.card-forecast { background: #f0f7ff; border-color: #cce5ff; }

.section-title { font-size: 14px; text-transform: uppercase; color: #555; margin: 25px 0 10px 0; }
.prognose-info { font-size: 12px; color: var(--text-muted); margin: 0 0 12px 0; }
.link-action { color: var(--primary); text-decoration: none; cursor: pointer; }
.badge-cost { color: var(--primary); font-weight: bold; }
.sub-text { font-size: 13px; color: var(--text-muted); font-weight: normal; }
.footer-text { text-align: right; margin-top: 15px; font-size: 12px; color: #888; }

/* Einheitliche Tabellen */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid #ddd; text-align: left; }
.table th { background: var(--bg-muted); }
.table .col-check { width: 40px; text-align: center; }

.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 15px;
}
.table-card th, .table-card td { padding: 12px 14px; border-bottom-color: #eee; }
.table-card th { font-size: 12px; color: #555; text-transform: uppercase; }
.table-card tr:last-child td { border-bottom: none; }

.table-sticky th, .table-sticky td { font-size: 14px; }
.table-sticky th { background: #f0f0f0; position: sticky; top: 0; }

.table-compact { font-size: 14px; }
.table-compact th, .table-compact td { padding: 6px 0; border-bottom-color: #eee; }
.table-compact th { background: transparent; border-bottom-color: #ccc; }

/* Dialog / Modal */
dialog {
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 20px;
    width: 450px;
    max-width: 90vw;
    margin: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.modal-wrapper { display: flex; flex-direction: column; height: 100%; }
.modal-header { margin-bottom: 15px; }
.modal-content { flex: 1; overflow-y: auto; border: 1px solid #eee; }
.close-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    float: right;
}

/* Login */
.login-body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
.login-box { padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); max-width: 400px; width: 100%; }
.login-box h3 { margin-top: 0; }
.login-input { width: 100%; margin-top: 5px; padding: 8px; }

/* Setup & Planer Layout */
.planer-container { max-width: 1050px; margin: 0 auto; padding: 25px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.planer-header { border-bottom: 2px solid #ddd; padding-bottom: 10px; margin-bottom: 15px; }
.planer-header h2 { margin: 0; }
.msg { background: #d4edda; color: #155724; padding: 10px; border-radius: 4px; margin-bottom: 15px; }

/* Formulare & Buttons */
select,
input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"] {
    padding: 6px;
    border-radius: 4px;
    border: 1px solid #ccc;
}
.input-setting { width: 150px; font-size: 15px; margin-top: 5px; }

.btn { padding: 8px 14px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; }
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-sync { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sec { background: #eef2f6; color: #000; text-decoration: none; }
.btn-comfort { background: #e65100; color: #fff; }
.btn-lg { padding: 10px 18px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-mobile { padding: 18px 12px; font-size: 17px; border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); }

.actions { margin-top: 15px; }
.checkbox-dup { transform: scale(1.2); cursor: pointer; }
.active-week { background-color: #fff3cd; }
.date-range { font-size: 12px; color: var(--text-muted); margin-left: 8px; }
.badge-current { color: #d9534f; font-weight: bold; }

.tpl-header { font-size: 16px; font-weight: bold; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 6px; }
.main-switch-card { border-width: 2px; }
.card-active-border { border-color: var(--success); }
.card-inactive-border { border-color: #ccc; }

/* Energiepreise Split-View */
.split-view { display: flex; gap: 20px; flex-wrap: wrap; }
.split-view-col { flex: 1; min-width: 320px; }
.split-view-col-stack { flex: 1; min-width: 320px; display: flex; flex-direction: column; gap: 20px; }

/* Mobile Quick-Control (app.php) */
.mobile-app-body { background-color: #121214; color: var(--bg-page); padding: 20px 15px; min-height: 100vh; }
.mobile-app-container { max-width: 480px; margin: 0 auto; width: 100%; }
.mobile-header { border-bottom: 1px solid #2a2a2e; padding-bottom: 12px; margin-bottom: 16px; }
.mobile-header h2 { margin: 0; color: #fff; font-size: 20px; font-weight: bold; }

.mobile-status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.mobile-status-grid .card { background: #1e1e22; border-color: #2e2e34; border-radius: 8px; padding: 14px 12px; }
.mobile-status-grid .card-title { color: #888; font-size: 11px; }
.mobile-status-grid .card-value { color: #fff; font-size: 18px; font-weight: bold; }
.mobile-status-grid .card-value.mobile-status-comfort { color: #ff9800; }
.mobile-status-grid .card-value.mobile-status-auto { color: #4caf50; }

.mobile-form { width: 100%; margin-bottom: 25px; }
.mobile-footer { text-align: center; padding-top: 10px; }
.mobile-logout-link { color: #888; text-decoration: none; font-size: 14px; }
.mobile-logout-link:hover { color: #ccc; }

/* 24h Zeitstrahl */
.timeline-day-header { border-bottom: 2px solid #eee; padding-bottom: 8px; margin-bottom: 15px; }
.timeline-day-title { font-size: 16px; font-weight: bold; color: var(--primary); }
.timeline-row { margin-bottom: 16px; }
.timeline-label { font-size: 13px; font-weight: bold; color: #444; margin-bottom: 6px; }

.timeline-track-wrap {
    position: relative;
    height: 34px;
    background: #e9ecef;
    margin-bottom: 6px;
    border: 1px solid #ced4da;
    width: 100%;
}

.timeline-block {
    position: absolute;
    top: 2px;
    bottom: 2px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    z-index: 2;
    transition: transform 0.15s ease, z-index 0.15s ease;
}
.timeline-block:hover { transform: scaleY(1.15); z-index: 10; box-shadow: 0 2px 6px rgba(0,0,0,0.4); }
.timeline-block-hk1 { background: #e65100; }
.timeline-block-dhw { background: #f57c00; }
.timeline-block-circ { background: var(--primary); }

.timeline-scale-wrap { width: 100%; margin: 3px 0 18px 0; user-select: none; }
.timeline-scale-ticks { display: flex; justify-content: space-between; width: 100%; }
.tick-col { position: relative; display: flex; flex-direction: column; align-items: center; width: 0; }
.tick-minor { width: 1px; height: 4px; background: #bbb; }
.tick-major { width: 1.5px; height: 8px; background: #444; }
.tick-lbl {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: #444;
    white-space: nowrap;
    text-align: center;
}

.timeline-add-box { gap: 8px; background: var(--bg-muted); padding: 8px 12px; border-radius: 6px; }
.timeline-clone-box { gap: 8px; }

/* Utilities */
.hidden { display: none; }
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-15 { margin-top: 15px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-15 { margin-bottom: 15px; }
.mb-20 { margin-bottom: 20px; }
.mb-25 { margin-bottom: 25px; }
.ml-10 { margin-left: 10px; }
.input-w-100 { width: 100px; }
.fs-16 { font-size: 16px; }
.fs-18 { font-size: 18px; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }
