body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Arial', sans-serif;
    background-color: #1a1a1a;
    color: #e0e0e0;
}

.sidebar {
    width: 220px;
    height: 100vh;
    box-sizing: border-box;
    overflow-y: auto;
    background: linear-gradient(45deg, #0f2027, #203a43, #2c5364);
    padding: 15px;
    position: fixed;
    box-shadow: 3px 0 15px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sidebar h2 {
    text-align: center;
    color: #00d4ff;
    margin-bottom: 20px;
    font-size: 18px;
}

.sidebar h3 {
    text-align: center;
    color: #00d4ff;
    margin-bottom: 20px;
    font-size: 18px;
}

.sidebar a {
    display: block;
    padding: 10px;
    margin: 12px 0;
    color: #00d4ff;
    background: #2a2a2a;
    border-radius: 10px;
    text-align: center;
    text-decoration: none;
    font-size: 16px;
    transition: background 0.3s ease, color 0.3s ease;
}

.sidebar a:hover,
.sidebar a.active {
    background: #00d4ff;
    color: #1a1a1a;
}

.sidebar a {
    width: 100%;
    box-sizing: border-box;
}

.main-content {
  padding: 40px;
  margin-left: 220px;             /* sidebar width */
  width: calc(100% - 220px);
  background: #121212;
  color: #fff;
  min-height: 100vh;
  box-sizing: border-box;
}

.graph-container {
  width: 100%;
  max-width: 1100px;
  height: 60vh;
  margin: 20px auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* SCADA Controls Section */
.scada-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}

.threshold-control {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #1e1e1e;
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid #333;
}

.threshold-control label {
    color: #888;
    font-size: 14px;
}

.threshold-control input[type="number"] {
    width: 100px;
    padding: 8px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 5px;
    color: #e0e0e0;
    font-size: 14px;
}

.threshold-control input[type="number"]:focus {
    outline: none;
    border-color: #00d4ff;
}

.threshold-control button {
    padding: 8px 20px;
    background: #00d4ff;
    color: #1a1a1a;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s ease;
}

.threshold-control button:hover {
    background: #00a8cc;
}

/* SCADA Current Readings Section */
.scada-readings {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 20px auto 30px;
    max-width: 800px;
}

.scada-reading-card {
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 20px 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    min-width: 280px;
    text-align: center;
}

.scada-reading-title {
    font-size: 14px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.scada-reading-value {
    font-size: 36px;
    font-weight: bold;
    margin: 10px 0;
}

.scada-reading-value.beatrice-color {
    color: rgba(0, 212, 255, 1);
}

.scada-reading-value.garden-city-color {
    color: rgba(255, 99, 132, 1);
}

.scada-reading-unit {
    font-size: 20px;
    font-weight: normal;
    color: #888;
}

.scada-reading-time {
    font-size: 12px;
    color: #666;
    margin-top: 8px;
}

/* === Real-time updates layout improvements === */

/* Outer container centered and proportional to viewport */
.rt-container{
  width: clamp(720px, 85vw, 1200px);   /* scales with screen, capped */
  margin: 16px auto 24px;
  padding: 0 8px;                      /* slight breathing room */
}

/* "Area behind the table" – a card that also scales by height */
.rt-surface{
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  padding: 16px;
  min-height: clamp(360px, 62vh, 780px);  /* proportional height */
  display: flex;
  flex-direction: column;
}

/* Scrollable table region sized relative to rt-surface height */
.rt-table-wrapper{
  flex: 1 1 auto;                        /* take remaining space */
  overflow: auto;
  border-radius: 10px;
  border: 1px solid #2b2b2b;
  background: #202020;
  max-height: none;                       /* flex drives height now */
}

/* Table sizing & readability */
.rt-table{
  width: 100%;
  min-width: 880px;                       /* readable columns on desktop */
  border-collapse: collapse;
  color: #e0e0e0;
}

.rt-table th,
.rt-table td{
  padding: 10px 12px;
  border-bottom: 1px solid #2f2f2f;
  text-align: left;
  font-size: 14px;
}

.rt-table thead th{
  position: sticky;
  top: 0;
  background: #171717;
  color: #dfe7eb;
  z-index: 1;
}

.rt-table tbody tr:nth-child(odd){ background: rgba(255,255,255,0.02); }
.rt-table tbody tr:hover{ background: rgba(0,212,255,0.08); }

canvas { width: 100% !important; height: 100% !important; }

.selector-container {
  position: fixed; top: 20px; right: 20px;
  background: #1f1f1f; color: #fff;
  padding: 10px 12px; border-radius: 8px; border: 1px solid #333;
  display: inline-flex; align-items: center; gap: 10px; z-index: 1000;
}

.with-sidebar {
    margin-left: 240px;
    width: calc(100% - 240px);
}

.filter-btn {
    margin-bottom: 0;
}

.data-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    background-color: #1e1e1e;
    border: 1px solid #333;
    padding: 20px;
    margin-bottom: 15px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.1);
}

.data-card .label {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 5px;
    color: #00d4ff;
}

.data-card .value {
    font-size: 18px;
    color: #ffffff;
    word-wrap: break-word;
}

.page-title {
    font-size: 32px;
    color: #00d4ff;
    margin-bottom: 30px;
    text-align: center;
}

/* === Shared form styles (CSV download pages, Query, Charts filters) === */
.form-container {
    max-width: 1100px;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 20px 24px;
    margin: 20px 0;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.form-label {
    display: inline-block;
    min-width: 150px;
    color: #00d4ff;
    font-weight: 600;
}

.main-content input[type="datetime-local"],
.main-content input[type="date"],
.main-content input[type="number"],
.main-content select {
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 5px;
    padding: 6px 8px;
    color-scheme: dark;
}

.main-content button,
.main-content .btn {
    padding: 8px 18px;
    background: #00d4ff;
    color: #1a1a1a;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-family: inherit;
}

.main-content button:hover,
.main-content .btn:hover {
    background: #00a8cc;
}

.sections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin: 16px 0;
}

.section.boxed {
    border: 1px solid #333;
    border-radius: 8px;
    padding: 12px 16px;
    background: #181818;
}

.columns-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}

.filter-section {
    margin-bottom: 10px;
}

/* === Login page === */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
    box-sizing: border-box;
}

.login-box {
    width: 100%;
    max-width: 360px;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 24px;
    box-sizing: border-box;
}

.login-box h2 {
    color: #00d4ff;
    margin-top: 0;
}

.login-box label {
    display: block;
    margin: 12px 0 6px;
}

.login-box input[type="text"],
.login-box input[type="password"] {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    font-size: 16px;
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 6px;
}

.password-container {
    position: relative;
}

.toggle-password {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
}

.login-box button {
    width: 100%;
    margin-top: 20px;
    padding: 12px;
    font-size: 16px;
    font-weight: bold;
    background: #00d4ff;
    color: #1a1a1a;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.error-message {
    color: #ff6384;
}

/* === Secondary buttons & SCADA action row === */
.main-content button.btn-secondary,
.main-content .btn-secondary {
    background: transparent;
    color: #00d4ff;
    border: 1px solid #00d4ff;
}

.main-content button.btn-secondary:hover {
    background: rgba(0, 212, 255, 0.12);
}

.scada-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.scada-actions button {
    min-width: 150px;
}

/* === Download dialog === */
.dl-dialog {
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    padding: 0;
    border: 1px solid #333;
    border-radius: 12px;
    background: #1e1e1e;
    color: #e0e0e0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.dl-dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

.dl-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 20px 20px;
}

.dl-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dl-header h2 {
    margin: 0;
    font-size: 20px;
    color: #00d4ff;
}

.dl-dialog .dl-close {
    background: none;
    border: none;
    padding: 0;
    color: #aaa;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
}

.dl-dialog .dl-close:hover {
    background: none;
    color: #fff;
}

.dl-section {
    border: 1px solid #333;
    border-radius: 8px;
    margin: 0;
    padding: 10px 14px 14px;
    min-width: 0;
}

.dl-section legend {
    padding: 0 6px;
    font-weight: 600;
    color: #00d4ff;
}

.dl-hint {
    font-weight: normal;
    color: #888;
    font-size: 13px;
}

.dl-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.dl-dialog .chip {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid #444;
    background: #2a2a2a;
    color: #e0e0e0;
    font-size: 13px;
    cursor: pointer;
}

.dl-dialog .chip:hover {
    border-color: #00d4ff;
}

.dl-dialog .chip.is-active {
    background: #00d4ff;
    border-color: #00d4ff;
    color: #1a1a1a;
    font-weight: bold;
}

.dl-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.dl-dates label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: #aaa;
}

.dl-dialog input[type="date"],
.dl-dialog input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 15px;
    color-scheme: dark;
}

.dl-dialog input:focus {
    outline: none;
    border-color: #00d4ff;
}

.dl-locations {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dl-check {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    cursor: pointer;
}

.dl-check input {
    width: 18px;
    height: 18px;
    accent-color: #00d4ff;
}

.dl-summary {
    margin: 0;
    min-height: 1.4em;
    font-size: 14px;
    color: #aaa;
}

.dl-summary-total,
.dl-summary-line {
    display: block;
}

.dl-summary-total {
    font-weight: bold;
}

.dl-summary-line {
    padding-left: 12px;
}

.dl-summary.is-ok { color: #4ade80; }
.dl-summary.is-error { color: #ff6384; }

.dl-note {
    margin: 0 0 10px;
    font-size: 12px;
    color: #888;
}

.dl-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.dl-dialog button[type="submit"],
.dl-dialog .dl-buttons button {
    padding: 10px 18px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    min-height: 44px;
}

.dl-dialog button[type="submit"] {
    background: #00d4ff;
    color: #1a1a1a;
    border: none;
}

.dl-dialog button[type="submit"]:disabled {
    background: #2f4b52;
    color: #789;
    cursor: not-allowed;
}

.dl-dialog .btn-secondary {
    background: transparent;
    color: #00d4ff;
    border: 1px solid #00d4ff;
}

/* Phone-only elements are hidden on desktop */
.mobile-topbar,
.nav-backdrop {
    display: none;
}

/* =====================================================================
   Phones & small tablets
   ===================================================================== */
@media (max-width: 768px) {
    /* --- Navigation: sidebar becomes a slide-out menu --- */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 8px;
        position: sticky;
        top: 0;
        z-index: 1100;
        height: 52px;
        padding: 0 8px;
        background: linear-gradient(45deg, #0f2027, #203a43, #2c5364);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    }

    .nav-toggle {
        min-width: 44px;
        min-height: 44px;
        font-size: 24px;
        line-height: 1;
        background: none;
        border: none;
        color: #00d4ff;
        cursor: pointer;
    }

    .mobile-title {
        color: #00d4ff;
        font-weight: bold;
        font-size: 17px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Pin to the *visible* screen (top+bottom) rather than 100vh, which on
       phones is taller than what's visible behind the browser toolbars. */
    .sidebar {
        top: 0;
        bottom: 0;
        left: 0;
        height: auto;
        max-height: 100dvh;
        width: 260px;
        z-index: 1200;
        align-items: stretch;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(15px + env(safe-area-inset-bottom));
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar h3 {
        margin: 4px 0 10px;
    }

    .sidebar a {
        flex-shrink: 0;
        margin: 4px 0;
        padding: 9px 10px;
    }

    body.nav-open .sidebar {
        transform: none;
    }

    body.nav-open .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1150;
        background: rgba(0, 0, 0, 0.55);
    }

    body.nav-open {
        overflow: hidden;
    }

    /* --- Page frame --- */
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 16px;
        min-height: calc(100vh - 52px);
    }

    .main-content h1 { font-size: 24px; }
    .main-content h2 { font-size: 20px; }

    .page-title {
        font-size: 24px;
        margin-bottom: 16px;
    }

    /* Controls that float top-right on desktop sit in the flow instead */
    .selector-container {
        position: static;
        display: flex;
        flex-wrap: wrap;
        width: 100%;
        box-sizing: border-box;
        margin-bottom: 12px;
    }

    .selector-container select {
        flex: 1 1 100%;
    }

    .selector-container > button,
    .selector-container > .btn {
        flex: 1 1 0;
        align-self: stretch;
        box-sizing: border-box;
    }

    /* --- Charts --- */
    .graph-container {
        height: 55vh;
        min-height: 320px;
        margin: 12px 0;
    }

    /* --- Forms (16px inputs stop iOS from zooming in on focus) --- */
    .form-container {
        padding: 14px;
        margin: 12px 0;
    }

    .form-label {
        min-width: 0;
    }

    .form-row > input,
    .form-row > select,
    .main-content input[type="datetime-local"],
    .main-content input[type="date"],
    .main-content input[type="number"],
    .main-content select {
        font-size: 16px;
        max-width: 100%;
        box-sizing: border-box;
    }

    .form-row > input,
    .form-row > select {
        flex: 1 1 100%;
    }

    .main-content button,
    .main-content .btn {
        min-height: 44px;
    }

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

    /* Query page: stack label above each picker, one checkbox per line */
    .form-group {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .form-group .form-label {
        margin-top: 8px;
    }

    .section.boxed > label {
        display: block;
        padding: 4px 0;
    }

    .data-card {
        padding: 15px;
    }

    .data-card .value {
        font-size: 16px;
    }

    /* --- SCADA --- */
    .scada-controls {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .scada-controls .filter-btn button {
        width: 100% !important;
    }

    .threshold-control {
        flex-wrap: wrap;
        justify-content: center;
    }

    .threshold-control input[type="number"] {
        flex: 1 1 100px;
    }

    .scada-readings {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin: 12px 0;
    }

    .scada-reading-card {
        min-width: 0;
        padding: 14px;
    }

    .scada-reading-value {
        font-size: 28px;
    }

    /* --- Real-time table: scrolls sideways inside its card --- */
    .rt-container {
        width: 100%;
        margin: 8px 0;
        padding: 0;
    }

    .rt-surface {
        padding: 12px;
        min-height: clamp(300px, 55vh, 640px);
    }

    .rt-table {
        min-width: 640px;
    }

    .rt-table th,
    .rt-table td {
        font-size: 13px;
        padding: 8px 10px;
    }

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

    /* --- Download dialog --- */
    .scada-actions button {
        flex: 1 1 0;
        min-width: 0;
    }

    .dl-form {
        padding: 14px;
    }

    .dl-dates {
        grid-template-columns: 1fr;
    }

    .dl-dialog input[type="date"],
    .dl-dialog input[type="text"] {
        font-size: 16px;
    }

    .dl-buttons button {
        flex: 1 1 0;
    }
}
