html {
    /* Mengganti font yang lebih modern dan umum */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    text-align: center;
    background-color: #f7f9fc; /* Warna latar belakang ringan */
}

body {
    margin: 0;
    padding: 0; /* Hapus padding default di body */
}

/* Variable Warna untuk Konsistensi */
:root {
    --primary-color: #049faa; /* Biru Primer */
    --accent-color: #059e8a; /* Hijau Aksen */
    --text-dark: #212529;
    --border-light: #e0e0e0;
    --primary-red: #dc3545;
    --primary-green: #28a745;
}

/* TOP NAV */
.topnav {
    background: var(--primary-color);
    color: white;
    padding: 15px 0; /* Padding yang lebih besar */
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.topnav h1 {
    margin: 0;
}

/* AUTH BAR */
#authentication-bar {
    background: #eef4f9; /* Warna yang lebih soft */
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

#authentication-bar a {
    margin-left: 10px;
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

#authentication-bar a:hover {
    opacity: 0.8;
}

/* FORM ELEMENTS (Login) */
.form-elements-container {
    width: 90%; /* Responsif di mobile */
    max-width: 350px; /* Batasan lebar di desktop */
    margin: 40px auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    text-align: left;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.form-elements-container label {
    font-weight: 600;
    color: var(--text-dark);
}

.form-elements-container input {
    padding: 12px; /* Padding yang lebih besar */
    border: 1px solid #c9c9c9;
    border-radius: 6px;
    transition: border-color 0.2s;
}

.form-elements-container input:focus {
    border-color: var(--primary-color);
    outline: none;
}

#login-button {
    padding: 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
}

#login-button:hover {
    background-color: #048a7a;
}

/* DEVICE SELECTOR */
#selector {
    margin: 25px auto;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-dark);
}

#deviceSelect {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    
    background: #ffffff;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    padding: 10px 14px;
    width: 200px; /* Sedikit dilebarkan */
    font-size: 16px;
    font-family: inherit;
    color: var(--text-dark);

    /* Menggunakan warna primary-color di SVG */
    background-image: url("data:image/svg+xml;utf8,<svg fill='%23049faa' height='18' viewBox='0 0 24 24' width='18' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 18px;
    cursor: pointer;
    transition: .25s ease;
}

#deviceSelect:hover {
    border-color: #037d87;
}

#deviceSelect:focus {
    outline: none;
    box-shadow: 0 0 8px rgba(4,159,170,0.3);
}

/* CARDS (Sensor Readings) */
.cards {
    max-width: 1000px; /* Lebar lebih besar */
    margin: 25px auto;
    display: grid;
    gap: 25px;
    /* Grid yang responsif */
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    padding: 0 20px;
}

.card {
    padding: 25px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    border: 2px solid #55c1d3; /* Warna border lebih soft */
    transition: transform 0.2s;
    font-size: 1.1rem;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}

.card p {
    margin: 5px 0;
}

/* Reading value style */
.reading { 
    color: var(--text-dark);
    font-size: 1.8rem;
    font-weight: 700;
    margin-top: 10px !important;
}

/* SENSOR STATUS */
#suhu-status, #amonia-status, #ph-status {
    display: inline-block;
    margin-top: 15px;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.9rem;
} 

.status-normal  { background:#d4edda; color:#155724; }
.status-warning { background:#fff3cd; color:#856404; }
.status-critical{ background:#f8d7da; color:#721c24; }

/* GLOBAL STATUS */
h3 { margin-top: 30px; }

#status-global {
    font-weight: bold;
    font-size: 1.4rem;
}

.global-normal { color: #155724; }
.global-warning { color: #856404; }
.global-critical{ color: #721c24; }

/* THRESHOLD PANEL BUTTON */
#toggle-threshold-btn {
    margin: 30px auto 15px;
    padding: 12px 20px;
    width: 90%;
    max-width: 350px;
    border: none;
    background: var(--accent-color);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#toggle-threshold-btn:hover { background-color: #048a7a; }

/* THRESHOLD CONTAINER */
#threshold-container {
    max-width: 900px;
    margin: 15px auto 30px;
    padding: 20px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    display: none;
}

#threshold-container h3 {
    margin-top: 0;
    margin-bottom: 25px;
    color: var(--text-dark);
}

.threshold-grid {
    display: grid;
    /* 1 kolom di mobile, 3 kolom di desktop */
    grid-template-columns: repeat(1, 1fr); 
    gap: 20px;
    margin-bottom: 25px;
    padding: 0 10px;
}

/* Media query untuk threshold grid di layar lebar */
@media (min-width: 768px) {
    .threshold-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.box {
    background: #fcfdff;
    padding: 20px 15px;
    border-radius: 10px;
    border: 1px solid #e7e7e7;
    text-align: center;
    margin: 0;
}

.box h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.box label {
    font-size: 0.9rem;
    font-weight: 500;
    display: block;
    margin-top: 10px;
    text-align: left;
    padding: 0; /* Menghilangkan padding horizontal agar input rata */
    color: #555;
}

.box input {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
}

/* SAVE / RESET BUTTONS */
#save-thresholds,
#reset-thresholds {
    margin: 10px 15px;
    padding: 12px;
    border: none;
    width: 150px;
    border-radius: 6px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s;
}

#save-thresholds { background: var(--accent-color); }
#save-thresholds:hover { opacity: 0.9; }
#reset-thresholds { background: var(--primary-red); } /* Menggunakan variabel */
#reset-thresholds:hover { opacity: 0.9; }


/* TABLE BUTTONS */
#view-data-button,
#hide-data-button,
#delete-button {
    margin: 15px 8px;
    padding: 10px 18px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-dark);
    font-weight: 600;
    cursor: pointer;
    background: white;
    transition: background-color 0.2s, color 0.2s;
}

#view-data-button:hover,
#hide-data-button:hover { 
    background: #1976d2; 
    color: white; 
    border-color: #1976d2;
}
#delete-button:hover { 
    background: var(--primary-red); 
    color: white; 
    border-color: var(--primary-red);
}

/* TABLE CONTAINER */
#table-container {
    margin: 20px auto;
    width: 95%; /* Lebih responsif */
    max-width: 900px; /* Lebar maksimum yang lebih besar */
    text-align: center;
}

.cardTable {
    margin-top: 15px;
    padding: 20px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0px 4px 15px rgba(0,0,0,0.08);
    width: 100%; /* Memastikan lebar 100% dari container */
    box-sizing: border-box;
    overflow-x: auto; /* Agar tabel tetap responsif */
}

table {
    width: 100%;
    min-width: 500px; /* Lebar minimum agar tidak terlalu sempit di mobile */
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 0.95rem;
}

th, td {
    border: 1px solid #ddd;
    padding: 12px 8px; /* Padding lebih besar */
    text-align: center;
}

th {
    background: #1976d2;
    color: white;
}

tr:nth-child(even) { background: #f8f8f8; }

/* CHARTS SECTION */
#charts-div {
    max-width: 1200px;
    margin: 25px auto;
    padding: 25px;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 4px 15px rgba(0,0,0,.07);
    text-align: center;
}

.container-main {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

/* Header Styles (Title and Buttons) - Menggunakan warna dari variabel */
.header-chart {
    color: var(--text-dark);
}
/* Button Group Styles (menggunakan warna primary) */
.time-button.active {
    color: var(--primary-color);
    border-color: var(--primary-color);
}
.time-button:focus {
    box-shadow: 0 0 0 2px rgba(4,159,170,0.5);
}

/* CHART CARDS (Sudah cukup baik, hanya menambahkan padding untuk mobile) */
.chart-cards {
    padding: 0 10px;
}

.chart-title {
    color: var(--text-dark);
}

/* Chart Value Colors (didefinisikan ulang agar tidak mengandalkan Tailwind CSS) */
.chart-value {
    font-size: 1.5rem; /* text-2xl */
    font-weight: 700; /* font-bold */
}
.value-blue { color: #007bff; }
.value-red { color: var(--primary-red); }
.value-green { color: var(--primary-green); }


/* Global media query untuk mengatur padding body di desktop */
@media (min-width: 1024px) {
    body {
        padding: 20px;
    }
}