:root {
    --bg-gradient: linear-gradient(180deg, #b3e5fc 0%, #e1f5fe 100%);
    --card-bg: rgba(255, 255, 255, 0.6);
    --card-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
    --primary-text: #1a4a6e;
    --secondary-text: #5a7d9a;
    --accent-blue: #4fc3f7;
    --white: #ffffff;
    --success: #66bb6a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
    color: var(--primary-text);
}

.dashboard-container {
    width: 100%;
    max-width: 1200px;
    /* Full dashboard view */
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 40px;
    padding: 40px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    gap: 25px;
    /* Reduced from 35px */
    height: fit-content;
}

/* Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    padding-bottom: 5px;
    /* Reduced from 20px */
}

.header-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.header-info h2 {
    font-size: 1.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-meta {
    display: flex;
    gap: 30px;
    align-items: center;
    font-size: 1rem;
    color: var(--secondary-text);
}

.header-meta p {
    white-space: nowrap;
}

#last-updated {
    opacity: 0.7;
    font-size: 0.9rem;
}

/* Parameter Switcher (Pill Toggle) */
.switcher-container {
    display: flex;
    justify-content: center;
    width: 100%;
}

.switcher-pill {
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 6px;
    display: flex;
    gap: 5px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.switcher-btn {
    background: none;
    border: none;
    padding: 10px 25px;
    border-radius: 15px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--secondary-text);
    cursor: pointer;
    transition: all 0.1s ease;
    white-space: nowrap;
}

.switcher-btn:hover {
    color: var(--primary-text);
    background: rgba(255, 255, 255, 0.3);
}

.switcher-btn.active {
    background: var(--white);
    color: var(--primary-text);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    transform: scale(1.02);
}

/* Sensor Grid */
.sensor-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* 3 columns for desktop */
    gap: 25px;
}

.sensor-card {
    background: var(--card-bg);
    border-radius: 30px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

.sensor-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 25px rgba(31, 38, 135, 0.15);
}

.sensor-card.secondary {
    background: var(--white);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.card-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    opacity: 0.8;
}

.status-dot {
    width: 12px;
    height: 12px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--success);
}

.card-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
}

.reading {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.reading-icon {
    font-size: 1.5rem;
    min-width: 45px;
    height: 45px;
    background: var(--white);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.reading-info {
    display: flex;
    flex-direction: column;
}

.reading-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
}

.reading-grid .reading-icon {
    min-width: 46px;
    height: 46px;
    font-size: 1.5rem;
    border-radius: 10px;
}

.reading-grid .reading .val {
    font-size: 1.8rem;
}

.reading-grid .reading .label {
    font-size: 0.8rem;
}

.reading .val {
    font-size: 1.9rem;
    font-weight: 600;
    line-height: 1.1;
}

.reading .label {
    font-size: 0.75rem;
    color: var(--secondary-text);
    text-transform: none; /* Removed uppercase to prevent µ turning into M */
    letter-spacing: 0.5px;
}

.card-footer {
    margin-top: auto;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--secondary-text);
}

/* Top Nav */
.top-nav {
    /* margin-bottom removed to reduce gap */
    background: var(--white);
    border-radius: 30px;
    padding: 10px 30px;
    /* Reduced padding to decrease height */
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
}

.logo-img {
    max-height: 50px;
    width: auto;
    object-fit: contain;
    display: block;
    margin-right: 15px;
    /* Add some spacing if needed */
}

.nav-item {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.3s, transform 0.2s;
    text-decoration: none;
    /* Ensure no underline for links */
    outline: none;
    /* Remove focus outline */
}

.nav-item:hover {
    transform: scale(1.1);
}

.nav-item.active {
    opacity: 1;
    color: var(--accent-blue);
}

/* Alert Badge */
.nav-item {
    position: relative;
}

.alert-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #f44336;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Alert Modal Specific Styles */
.alert-modal-content {
    max-width: 700px;
}

.alert-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 60vh;
    overflow-y: auto;
}

.alert-item {
    background: #fff3cd;
    border-left: 4px solid #ff9800;
    padding: 15px;
    border-radius: 8px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.alert-item.critical {
    background: #f8d7da;
    border-left-color: #f44336;
}

.alert-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 5px;
    color: var(--primary-text);
}

.alert-message {
    font-size: 0.9rem;
    color: var(--secondary-text);
    line-height: 1.4;
}

.no-alerts {
    text-align: center;
    padding: 40px 20px;
    color: var(--secondary-text);
    font-size: 1.1rem;
}

.no-alerts .icon {
    font-size: 3rem;
    margin-bottom: 10px;
    opacity: 0.5;
}

/* Card Warning State */
.sensor-card.warning {
    border: 2px solid #f44336;
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.2);
}

.sensor-card.critical {
    border: 2px solid #f44336;
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.2);
}

.sensor-card.warning .status-dot {
    background: #f44336;
    box-shadow: 0 0 10px #f44336;
}

.sensor-card.critical .status-dot {
    background: #f44336;
    box-shadow: 0 0 10px #f44336;
}

/* Responsive adjustments */
@media (max-width: 900px) {
    .sensor-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .sensor-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .header-meta {
        text-align: left;
    }

    .dashboard-container {
        padding: 20px;
    }

    .reading .val {
        font-size: 1.8rem;
    }
}

/* Modal Overlay */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity 0.3s ease;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 35px;
    width: 95%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
    transform: translateY(-20px);
    transition: transform 0.3s ease;
}

.modal.show .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.modal-title-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.interval-selector {
    display: flex;
    gap: 8px;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px;
    border-radius: 12px;
    width: fit-content;
}

.interval-btn {
    background: none;
    border: none;
    padding: 6px 15px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--secondary-text);
    transition: all 0.2s;
}

.interval-btn:hover {
    background: rgba(255, 255, 255, 0.5);
}

.interval-btn.active {
    background: var(--white);
    color: var(--primary-text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

.modal-header h2 {
    font-size: 1.5rem;
    color: var(--primary-text);
}

.close-modal {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--secondary-text);
    transition: color 0.2s;
}

.close-modal:hover {
    color: #f44336;
}

.modal-body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 25px;
}

.chart-box {
    background: #f8f9fa;
    border-radius: 20px;
    padding: 20px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chart-box:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.chart-box h3 {
    font-size: 1rem;
    margin-bottom: 15px;
    color: var(--secondary-text);
    font-weight: 500;
}

.canvas-wrapper {
    position: relative;
    height: 250px;
    width: 100%;
}

/* Fullscreen Mode for Sensor Modal */
.modal-content.fullscreen-mode {
    max-width: 98vw;
    max-height: 98vh;
    width: 98vw;
    height: 98vh;
}

.modal-content.fullscreen-mode .modal-body {
    display: block;
    max-height: calc(98vh - 120px);
}

.modal-content.fullscreen-mode .chart-box {
    display: none;
}

.modal-content.fullscreen-mode .chart-box.active-fullscreen {
    display: block;
    height: 100%;
}

.modal-content.fullscreen-mode .canvas-wrapper {
    height: calc(98vh - 200px);
}

@media (min-width: 800px) {
    .modal-body {
        grid-template-columns: 1fr 1fr;
    }
}

/* Settings Specific Styles */
#settings-view {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.settings-grid {
    width: 100%;
}

.settings-container {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

.sensor-settings-group {
    width: 100%;
}

.settings-tab-content {
    display: none;
    grid-template-columns: repeat(2, 1fr);
    gap: 25px;
    width: 100%;
}

.sensor-settings-card {
    background: var(--card-bg);
    border-radius: 30px;
    padding: 25px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: var(--card-shadow);
    transition: transform 0.2s ease;
}

.setting-title {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--primary-text);
}

.input-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--secondary-text);
}

.field input {
    width: 100%;
    border-radius: 12px;
    padding: 10px;
    background: var(--white);
    border: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
    /* Ensure padding doesn't add to width */
}

.field input:focus {
    border-color: var(--accent-blue);
}

.settings-actions {
    margin-top: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.btn-primary {
    background: var(--primary-text);
    color: var(--white);
    border: none;
    padding: 14px 40px;
    border-radius: 20px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    opacity: 0.9;
}

#settings-status {
    font-size: 0.95rem;
    font-weight: 500;
    height: 20px;
}

@media (max-width: 1100px) {
    .sensor-settings-group {
        grid-template-columns: 1fr;
    }

    .settings-container {
        max-width: 600px;
    }
}

/* Water Tank Visualization */
.tank-visual-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    padding: 10px 0;
}

.tank-shell {
    width: 80px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border: 4px solid #fff;
    border-radius: 12px 12px 40px 40px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.tank-liquid {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(180deg, #4facfe 0%, #00f2fe 100%);
    box-shadow: 0 -5px 15px rgba(79, 172, 254, 0.4);
    transition: height 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Subtle wave gloss */
.tank-liquid::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 15px;
    background: rgba(255, 255, 255, 0.3);
    filter: blur(4px);
}

.tank-percentage {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary-text);
    font-family: 'Inter', sans-serif;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Historical Data Page Styles */
.history-controls {
    display: flex;
    flex-direction: column;
    gap: 25px;
    margin-bottom: 30px;
}

.control-group {
    background: var(--card-bg);
    border-radius: 25px;
    padding: 25px;
    box-shadow: var(--card-shadow);
}

.control-group h3 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--primary-text);
}

.control-group h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary-text);
}

.datetime-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 15px;
}

.datetime-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.datetime-field label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--secondary-text);
}

.datetime-field input {
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: var(--white);
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}

.datetime-field input:focus {
    border-color: var(--accent-blue);
}

.quick-select {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.quick-btn {
    background: var(--white);
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 8px 18px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--primary-text);
}

.quick-btn:hover {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.parameter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 25px;
    margin-bottom: 20px;
    align-items: flex-start;
    /* Keeps headers aligned even with varying content heights */
}

.param-section {
    display: flex;
    flex-direction: column;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--primary-text);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.checkbox-group label:hover {
    background: rgba(0, 0, 0, 0.03);
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.control-actions {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.btn-secondary {
    background: var(--white);
    color: var(--primary-text);
    border: 2px solid var(--primary-text);
    padding: 14px 40px;
    border-radius: 20px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

.btn-secondary:hover {
    transform: translateY(-2px);
    opacity: 0.9;
}

.history-chart-container {
    background: var(--card-bg);
    border-radius: 25px;
    padding: 30px;
    box-shadow: var(--card-shadow);
    min-height: 500px;
}

#chart-wrapper {
    position: relative;
    height: 500px;
    width: 100%;
}

@media (max-width: 768px) {
    .datetime-inputs {
        grid-template-columns: 1fr;
    }

    .parameter-grid {
        grid-template-columns: 1fr;
    }

    .control-actions {
        flex-direction: column;
    }

    .control-actions button {
        width: 100%;
    }
}

/* Logo Styling */
.logo-img {
    max-height: 60px;
    /* Adjusted to be slightly larger than text */
    width: auto;
    object-fit: contain;
    display: block;
    margin-right: 15px;
    /* Add some spacing if needed */
    /* Filter to turn white to Blue (#007bff) */
    filter: invert(34%) sepia(98%) saturate(1914%) hue-rotate(204deg) brightness(103%) contrast(102%);
}

.header-icon-img {
    height: 35px;
    width: auto;
    object-fit: contain;
    margin-right: 10px;
}

@media (max-width: 768px) {
    .logo-img {
        max-height: 40px;
    }

    .top-nav {
        padding: 15px 20px;
    }

    .nav-links {
        gap: 15px;
    }
}

/* Time Interval Select Styles */
.form-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 12px 40px 12px 15px;
    /* Restored height (12px), compact width-wise padding */
    border-radius: 120px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--white);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%231a4a6e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 18px;
    /* Restored icon size */
    font-size: 0.95rem;
    /* Restored regular font size */
    font-weight: 500;
    font-family: 'Outfit', sans-serif;
    outline: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: 180px;
    /* Force it to be "length wise small" */
    cursor: pointer;
    color: var(--primary-text);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.form-select:hover {
    border-color: var(--accent-blue);
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.06);
}

.form-select:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 4px rgba(79, 195, 247, 0.15);
}

.select-group {
    width: 100%;
    display: flex;
    align-items: center;
}

.param-section h4 {
    margin-bottom: 10px;
    /* Tighter spacing */
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}