/* CSS Design System - Smart Valve */
:root {
    --bg-primary: #0a0f1d;
    --bg-secondary: #121829;
    --accent-blue: #3b82f6;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-hover: rgba(255, 255, 255, 0.07);
    --font-sans: 'Outfit', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-x: hidden;
}

/* アプリレイアウト */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* サイドバー */
.sidebar {
    width: 260px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--glass-border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
}

.logo-icon {
    font-size: 1.75rem;
}

.logo h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #f8fafc 0%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.menu a {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.menu a:hover, .menu a.active {
    background-color: var(--glass-hover);
    color: var(--text-primary);
}

.menu a.active {
    border-left: 3px solid var(--accent-blue);
    background-color: rgba(59, 130, 246, 0.08);
}

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.pulse-indicator {
    width: 8px;
    height: 8px;
    background-color: var(--accent-green);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-green);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* メインコンテンツ */
.main-content {
    flex-grow: 1;
    padding: 2.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 3rem;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

/* ボタン */
.btn {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.65rem 1.25rem;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-blue) 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.35);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background-color: var(--glass-hover);
    transform: translateY(-2px);
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

/* グリッドレイアウト */
.rooms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 2rem;
    margin-bottom: 4rem;
}

/* 部屋カード (Glassmorphism) */
.room-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 1.75rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow-premium);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.room-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.9);
}

.room-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.room-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.facility-badge {
    display: inline-block;
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}

/* 不在ステータスバッジ */
.presence-badge {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.presence-badge.present {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--accent-green);
    border-color: rgba(16, 185, 129, 0.2);
}

.presence-badge.absent {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--accent-red);
    border-color: rgba(239, 68, 68, 0.2);
}

.badge-dot {
    width: 6px;
    height: 6px;
    background-color: var(--accent-green);
    border-radius: 50%;
}

.badge-dot-absent {
    width: 6px;
    height: 6px;
    background-color: var(--accent-red);
    border-radius: 50%;
}

/* センサーメトリクス */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-item {
    background-color: rgba(255, 255, 255, 0.015);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1rem;
    text-align: center;
}

.metric-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 0.35rem;
}

.metric-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.metric-value .unit {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-left: 0.15rem;
}

/* エアコン操作パネル */
.aircon-control-panel {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    transition: all 0.3s ease;
}

.aircon-control-panel.active {
    background-color: rgba(59, 130, 246, 0.03);
    border-color: rgba(59, 130, 246, 0.25);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.panel-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

/* 温度調節ボタン */
.temp-control {
    display: inline-flex;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.25rem;
}

.temp-control button {
    background: none;
    border: none;
    color: var(--text-primary);
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.temp-control button:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.temp-setting {
    padding: 0 0.75rem;
    font-weight: 700;
    font-size: 1.1rem;
    min-width: 60px;
    text-align: center;
}

/* セレクトボックス */
.select-mode, .table-select {
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.3s;
}

.select-mode:focus, .table-select:focus {
    border-color: var(--accent-blue);
}

/* トグルスイッチ */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-blue);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

/* デバイスリスト */
.room-devices {
    border-top: 1px solid var(--glass-border);
    padding-top: 1rem;
}

.room-devices h4 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.room-devices ul {
    list-style: none;
}

.room-devices li {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

.device-role {
    color: var(--text-secondary);
    font-size: 0.75rem;
    background-color: rgba(255, 255, 255, 0.05);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.no-device, .no-aircon {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

/* デバイス管理セクション */
.devices-management-section {
    margin-top: 2rem;
}

.devices-management-section h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

.card.glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: var(--shadow-premium);
}

.card h3 {
    font-size: 1.1rem;
    margin-bottom: 1.25rem;
    color: var(--text-secondary);
}

/* テーブルデザイン */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.device-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.device-table th, .device-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.device-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.device-table td {
    font-size: 0.9rem;
}

.device-table code {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-family: monospace;
}

.action-cell {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.table-select {
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(10, 15, 29, 0.8);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
}

.modal.open {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 2.5rem;
    width: 90%;
    max-width: 480px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.close-btn {
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal h2 {
    font-size: 1.35rem;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input, .form-group select {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.3s;
}

.form-group input:focus, .form-group select:focus {
    border-color: var(--accent-blue);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 2rem;
}

/* グラフ表示領域のスタイリング */
.chart-wrapper {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    padding: 0.75rem;
    margin-top: 1.25rem;
    width: 100%;
}

.toggle-chart-btn {
    width: 100%;
    margin-top: 1rem;
    justify-content: center;
}

/* ==========================================
   レスポンシブデザイン (Mobile Optimization)
   ========================================== */

/* タブレット・スマートフォン共通 (画面幅768px以下) */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
        padding: 1rem 1.25rem;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        z-index: 100;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }
    
    .logo {
        margin-bottom: 0;
    }
    
    .logo h2 {
        font-size: 1.1rem;
    }
    
    .menu {
        flex-direction: row;
        gap: 0.25rem;
        flex-grow: 0;
    }
    
    .menu a {
        padding: 0.4rem 0.65rem;
        font-size: 0.8rem;
        gap: 0.5rem;
    }
    
    .menu a.active {
        border-left: none;
        border-bottom: 2px solid var(--accent-blue);
        border-radius: 8px;
    }
    
    .sidebar-footer {
        display: none;
    }
    
    .main-content {
        padding: 1.5rem 1rem;
        width: 100%;
    }
    
    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 1.25rem;
        margin-bottom: 2rem;
    }
    
    .header-actions {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        width: 100%;
    }
    
    .header-actions .btn {
        font-size: 0.75rem;
        padding: 0.6rem 0.5rem;
        border-radius: 10px;
    }
    
    .rooms-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 1.25rem;
        margin-bottom: 2.5rem;
    }
    
    .device-table th, .device-table td {
        white-space: nowrap;
        padding: 0.75rem;
        font-size: 0.8rem;
    }
}

/* スマートフォン縦持ち (画面幅480px以下) */
@media (max-width: 480px) {
    .sidebar {
        padding: 0.75rem 1rem;
    }
    
    .logo {
        gap: 0.4rem;
    }
    
    .logo h2 {
        font-size: 0.95rem;
    }
    
    .menu a {
        padding: 0.4rem 0.5rem;
        font-size: 0.75rem;
        gap: 0.35rem;
    }
    
    .header h1 {
        font-size: 1.6rem;
    }
    
    .rooms-grid {
        grid-template-columns: 1fr;
    }
    
    .room-card {
        padding: 1.25rem;
    }
    
    .metric-value {
        font-size: 1.5rem;
    }
    
    .control-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .temp-control {
        justify-content: space-between;
        width: 100%;
    }
    
    .select-mode {
        width: 100%;
        text-align: center;
    }
    
    .modal-content {
        padding: 1.5rem;
        width: 95%;
    }
    
    .modal h2 {
        font-size: 1.2rem;
    }
}
