:root {
    /* Light Mode */
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-main: #2c3e50;
    --text-sub: #7f8c8d;
    --chart-grid: #e0e0e0;
    --btn-bg: #e0e0e0;
    --btn-active-bg: #2c3e50;
    --btn-active-text: #ffffff;
    --alert-bg: #ffeaa7;
    --alert-text: #d35400;
    --radius: 16px;
    
    /* Sensor Colors */
    --color-temp: #ff6b6b;
    --color-hum: #48dbfb;
    --color-co2: #1dd1a1;
    --color-noise: #c8d6e5;
    --color-press: #ff9f43;
    --color-light: #feca57;
    --color-etvoc: #5f27cd;

    /* Tooltip Theme */
    --tooltip-bg: rgba(255, 255, 255, 0.95);
    --tooltip-text: #333;
    --tooltip-border: 1px solid rgba(0,0,0,0.1);
    --tooltip-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}
[data-theme="dark"] {
    /* Dark Mode */
    --bg-color: #18191a;
    --card-bg: #242526;
    --text-main: #e4e6eb;
    --text-sub: #b0b3b8;
    --chart-grid: #3a3b3c;
    --btn-bg: #3a3b3c;
    --btn-active-bg: #e4e6eb;
    --btn-active-text: #18191a;
    --alert-bg: #634d1b;
    --alert-text: #ffca28;
    --tooltip-bg: rgba(40, 40, 40, 0.95);
    --tooltip-text: #fff;
    --tooltip-border: 1px solid rgba(255,255,255,0.1);
    --tooltip-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0; padding: 20px;
    background-color: var(--bg-color); color: var(--text-main);
    transition: background-color 0.3s, color 0.3s;
    cursor: default;
}

/* Tooltip */
#custom-tooltip {
    position: fixed; visibility: hidden; opacity: 0;
    background: var(--tooltip-bg); color: var(--tooltip-text);
    border: var(--tooltip-border); box-shadow: var(--tooltip-shadow);
    padding: 15px 20px; border-radius: 12px; font-size: 0.95rem; line-height: 1.6;
    z-index: 1000; pointer-events: none; transition: 0.15s; max-width: 320px; backdrop-filter: blur(8px);
}
#custom-tooltip strong { display: block; margin-bottom: 5px; font-size: 1.05rem; border-bottom: 2px solid var(--btn-bg); padding-bottom: 5px; }

/* Header */
.header { 
    max-width: 1000px; margin: 0 auto 15px auto; 
    display: flex; justify-content: space-between; align-items: center; 
    flex-wrap: wrap; gap: 10px; 
}
.header-left { 
    display: flex; align-items: center; gap: 12px; 
}

/* タイトル */
h1 { 
    font-size: 1.5rem; margin: 0; color: var(--text-sub); font-weight: 700; line-height: 1; 
}

/* インフォアイコン (位置微調整) */
.info-icon {
    display: inline-flex; justify-content: center; align-items: center; width: 24px; height: 24px; border-radius: 50%;
    background: var(--text-sub); color: var(--bg-color); font-size: 14px; font-weight: bold; cursor: help; transition: transform 0.2s;
    margin-top: 2px;
}
.info-icon:hover { transform: scale(1.1); }

/* DIコンテナ (ここを修正: 垂直中央揃えとフォントサイズ統一) */
.di-container { 
    display: flex; align-items: center; 
    gap: 8px; 
    margin-left: 10px;
    color: var(--text-sub);
    cursor: help; padding: 4px 8px; border-radius: 8px; transition: background-color 0.2s;
}
.di-container:hover { background-color: var(--btn-bg); }
.di-label { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.di-val { font-size: 1.5rem; font-weight: 700; line-height: 1; }

/* DI Status Text (Badge style) */
#val-di-status { 
    font-size: 0.9rem; font-weight: bold;
    padding: 3px 8px; border-radius: 4px; color: #fff; 
    display: inline-block; vertical-align: middle;
    margin-left: 2px;
}

.controls { display: flex; align-items: center; gap: 15px; }
.theme-btn { background: var(--btn-bg); border: none; padding: 8px 12px; border-radius: 20px; cursor: pointer; font-size: 1.2rem; color: var(--text-main); }

/* Alert */
#alert-area { max-width: 1000px; margin: 0 auto 15px auto; display: flex; flex-direction: column; gap: 10px; }
.alert-banner {
    background-color: var(--alert-bg); color: var(--alert-text); padding: 10px 15px; border-radius: 8px;
    display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); animation: fadeIn 0.5s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* Dashboard */
.dashboard-wrapper { max-width: 1000px; margin: 0 auto 40px auto; display: flex; flex-direction: column; gap: 15px; }
.main-row { display: grid; grid-template-columns: repeat(1, 1fr); gap: 15px; }
@media (min-width: 768px) { .main-row { grid-template-columns: repeat(3, 1fr); } }
.sub-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
@media (min-width: 768px) { .sub-row { grid-template-columns: repeat(4, 1fr); } }

/* Cards */
.card {
    background: var(--card-bg); border-radius: var(--radius); padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); display: flex; flex-direction: column;
    justify-content: center; align-items: center; text-align: center; position: relative;
    transition: transform 0.2s, box-shadow 0.2s, border 0.2s;
    cursor: pointer; border: 3px solid transparent; 
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 15px rgba(0,0,0,0.05); }

/* Selected States */
.card.selected#card-temp { border-color: var(--color-temp); background-color: rgba(255, 107, 107, 0.05); }
.card.selected#card-hum { border-color: var(--color-hum); background-color: rgba(72, 219, 251, 0.05); }
.card.selected#card-co2 { border-color: var(--color-co2); background-color: rgba(29, 209, 161, 0.05); }
.card.selected#card-noise { border-color: var(--color-noise); background-color: rgba(200, 214, 229, 0.1); }
.card.selected#card-press { border-color: var(--color-press); background-color: rgba(255, 159, 67, 0.05); }
.card.selected#card-light { border-color: var(--color-light); background-color: rgba(254, 202, 87, 0.05); }
.card.selected#card-etvoc { border-color: var(--color-etvoc); background-color: rgba(95, 39, 205, 0.05); }

.main-row .card { padding: 25px 20px; height: 180px; justify-content: space-between; }
.main-row .card-label { font-size: 0.9rem; font-weight: bold; color: var(--text-sub); width: 100%; display: flex; justify-content: space-between; }
.main-row .card-value-wrapper { display: flex; align-items: baseline; justify-content: center; width: 100%; }
.main-row .card-value { font-size: 4rem; line-height: 1; font-weight: 800; }
.main-row .card-unit { font-size: 1.2rem; margin-left: 5px; font-weight: 600; color: var(--text-sub); }

.minmax { font-size: 1.0rem; font-weight: 600; color: var(--text-sub); display: flex; gap: 15px; margin-top: 5px; }
.abs-hum { font-size: 1.1rem; font-weight: 700; color: var(--text-sub); margin-top: 5px; display: flex; align-items: baseline; gap: 5px; }
.trend { font-size: 1.5rem; margin-left: 10px; color: var(--text-sub); font-weight: bold; }

.sub-row .card { padding: 15px; height: 100px; }
.sub-row .card-label { font-size: 0.8rem; color: var(--text-sub); margin-bottom: 5px; }
.sub-row .card-value { font-size: 1.8rem; font-weight: 700; }
.sub-row .card-unit { font-size: 0.9rem; color: var(--text-sub); }

.status-cold { color: #48dbfb !important; }
.status-warm { color: #ff6b6b !important; }
.status-ok   { color: #1dd1a1 !important; }
.status-warn { color: #feca57 !important; }
.status-alert{ color: #ff4757 !important; }

/* DI Status Backgrounds */
.bg-cold { background-color: #48dbfb; }
.bg-ok { background-color: #1dd1a1; }
.bg-warn { background-color: #feca57; }
.bg-alert { background-color: #ff4757; }

/* Graph */
.graph-section { max-width: 1000px; margin: 0 auto; }
.range-controls { display: flex; gap: 8px; margin-bottom: 10px; justify-content: flex-end; }
.range-btn {
    background: var(--btn-bg); border: none; padding: 6px 12px; border-radius: 12px;
    font-size: 0.85rem; font-weight: 600; color: var(--text-sub); cursor: pointer; transition: 0.2s;
}
.range-btn:hover { opacity: 0.8; }
.range-btn.active { background: var(--btn-active-bg); color: var(--btn-active-text); }

/* Chart Container Relative for absolute timestamp */
.chart-container { 
    height: 400px; width: 100%; background: var(--card-bg); padding: 20px; border-radius: var(--radius); box-sizing: border-box; 
    position: relative; 
}
.chart-timestamp {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 0.8rem;
    color: var(--text-sub);
    background: var(--bg-color);
    padding: 4px 8px;
    border-radius: 4px;
    z-index: 10;
    cursor: help;
}
