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

:root {
    --primary: #1a56db;
    --on-primary: #ffffff;
    --primary-container: #d6e2ff;
    --on-primary-container: #001a41;
    --secondary: #565e71;
    --on-secondary: #ffffff;
    --surface: #ffffff;
    --on-surface: #1b1b1f;
    --on-surface-variant: #44474f;
    --surface-container: #f3f4f6;
    --surface-container-low: #f7f8fa;
    --surface-container-high: #e8e9ed;
    --outline: #74777f;
    --outline-variant: #c4c6d0;
    --error: #ba1a1a;
    --on-error: #ffffff;
    --error-container: #ffdad6;
    --inverse-surface: #303034;
    --inverse-on-surface: #f2f0f4;
    --shadow: rgba(0,0,0,0.15);

    --font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --sidebar-bg: #111827;
    --sidebar-hover: #1f2937;
    --sidebar-width: 240px;
    --success: #059669;
    --warning: #d97706;
}

body {
    font-family: var(--font-family);
    background: var(--surface-container);
    color: var(--on-surface);
    font-size: 14px;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    transition: transform 0.3s;
    z-index: 100;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid #374151;
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 700;
}

.sidebar-header .subtitle {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 4px;
    display: block;
}

.nav-menu {
    list-style: none;
    padding: 8px 0;
}

.nav-item a {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    color: #d1d5db;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
    gap: 10px;
}

.nav-item a:hover,
.nav-item a.active {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-item a.active {
    border-left: 3px solid var(--primary);
}

.nav-icon {
    display: inline-block;
    width: 20px;
    text-align: center;
    font-size: 16px;
    color: #9ca3af;
}

.nav-item a:hover .nav-icon,
.nav-item a.active .nav-icon {
    color: #fff;
}

.nav-divider {
    border-top: 1px solid #374151;
    margin: 8px 16px;
}

/* Main Wrapper */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s;
}

.main-wrapper.expanded {
    margin-left: 0;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--outline-variant);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left h2 {
    font-size: 16px;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    color: var(--on-surface-variant);
    font-size: 13px;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    padding: 8px;
    border-radius: 50%;
    color: var(--on-surface);
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--surface-container);
}

/* Content */
.content {
    flex: 1;
    padding: 24px;
}

/* Footer */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--outline-variant);
    padding: 12px 24px;
    text-align: center;
    color: var(--on-surface-variant);
    font-size: 12px;
}

/* Dashboard Summary */
.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    border-left: 4px solid var(--primary);
    box-shadow: 0 1px 3px var(--shadow);
}

.summary-card.solar { border-left-color: #f59e0b; }
.summary-card.hvac { border-left-color: #3b82f6; }

.summary-card h3 {
    font-size: 13px;
    color: var(--on-surface-variant);
    font-weight: 500;
    margin-bottom: 8px;
}

.summary-value {
    font-size: 28px;
    font-weight: 700;
}

/* Map */
.map-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px var(--shadow);
    margin-bottom: 16px;
}

.map-card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
}

.site-cluster {
    background: transparent;
}

.cluster-icon {
    border-radius: 50%;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    border: 2px solid #fff;
}

.site-label {
    background: var(--surface);
    border: 1px solid var(--outline-variant);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--on-surface);
    box-shadow: 0 1px 3px var(--shadow);
}

/* Leaflet z-index override — 헤더(1000) 아래로 제한 */
.map-card {
    position: relative;
    z-index: 1;
}

/* Chart */
.chart-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 16px;
}

.chart-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px var(--shadow);
}

.chart-card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px var(--shadow);
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--outline-variant);
    font-size: 13px;
}

.data-table th {
    background: var(--surface-container-low);
    font-weight: 600;
    color: var(--on-surface-variant);
    white-space: nowrap;
}

.data-table tr:hover td {
    background: var(--surface-container-low);
}

/* Status Badge */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: var(--error-container); color: var(--error); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: var(--on-primary);
}

.btn-primary:hover {
    box-shadow: 0 1px 3px var(--shadow);
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--surface-container);
    color: var(--on-surface);
    border: 1px solid var(--outline-variant);
}

.btn-secondary:hover {
    background: var(--surface-container-high);
}

.btn-danger {
    background: var(--error);
    color: var(--on-error);
}

.btn-danger:hover {
    filter: brightness(1.1);
}

.btn-tonal {
    background: var(--primary-container);
    color: var(--on-primary-container);
}

.btn-tonal:hover {
    filter: brightness(0.96);
}

.btn-sm {
    padding: 4px 12px;
    font-size: 12px;
}

/* Form */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--on-surface-variant);
    margin-bottom: 4px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--outline-variant);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    color: var(--on-surface);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-bar .form-group {
    margin-bottom: 0;
    flex: 0 0 auto;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.page-header h2 {
    font-size: 20px;
    font-weight: 700;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--outline-variant);
    margin-bottom: 0;
}

.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--on-surface-variant);
    font-family: inherit;
    transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
    color: var(--primary);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Login Page */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a8a 0%, #1a56db 100%);
}

.login-container {
    background: var(--surface);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 22px;
    color: var(--on-primary-container);
    margin-bottom: 4px;
}

.login-header p {
    color: var(--on-surface-variant);
    font-size: 14px;
}

.error-message {
    color: var(--error);
    font-size: 13px;
    margin-bottom: 8px;
    text-align: center;
}

.login-submit {
    margin-top: 8px;
}

.login-btn {
    width: 100%;
    padding: 10px 16px;
    font-size: 15px;
    justify-content: center;
}

/* Tab content */
.tab-content {
    display: block;
}

/* Site selector */
.site-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.site-selector .selected-site {
    padding: 8px 12px;
    border: 1px solid var(--outline-variant);
    border-radius: 6px;
    font-size: 14px;
    min-width: 200px;
    background: var(--surface);
}

/* Help tooltip badge */
.help-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--outline-variant, #c4c6d0);
    color: var(--on-surface-variant, #44474f);
    font-size: 11px;
    font-weight: 700;
    cursor: help;
    margin-left: 6px;
    position: relative;
    vertical-align: middle;
    flex-shrink: 0;
}

.help-badge:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--inverse-surface, #313033);
    color: var(--inverse-on-surface, #f4eff4);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    width: max-content;
    max-width: 260px;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    pointer-events: none;
    white-space: normal;
    word-break: keep-all;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal-box {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-height: 80vh;
    overflow-y: auto;
}

.modal-box h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* Search bar in modals */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: flex-end;
}

.search-results {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}

.search-results li {
    padding: 10px 12px;
    border-bottom: 1px solid var(--outline-variant);
    cursor: pointer;
    font-size: 13px;
}

.search-results li:hover {
    background: var(--surface-container-low);
}

.search-results .site-info {
    color: var(--on-surface-variant);
    font-size: 12px;
    margin-top: 2px;
}

/* Mapping list in modals */
.mapping-list {
    list-style: none;
    padding: 0;
    margin: 0 0 12px 0;
}

.mapping-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid var(--outline-variant);
    font-size: 13px;
}

.mapping-add {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-wrapper {
        margin-left: 0;
    }
    .chart-container {
        grid-template-columns: 1fr;
    }
    .dashboard-summary {
        grid-template-columns: repeat(2, 1fr);
    }
    .help-badge:hover::after {
        left: auto;
        right: 0;
        transform: none;
        max-width: 200px;
    }
}
