/**
 * style.css - Main Stylesheet
 * DC Tools ngành điện - Thông tin sét & cột điện
 * Phát triển bởi Đào Thành Công
 * 
 * MODULAR CSS ARCHITECTURE
 * Tổ chức theo module để dễ bảo trì, mỗi file ~300-800 dòng
 */

/* ==================== CSS Modules ==================== */

/* 1. Variables - CSS Custom Properties */
@import url('./modules/variables.css');

/* 2. Base Styles - Reset & Typography */
@import url('./modules/base.css');

/* 3. Layout - Header, Sidebar, Footer, Navigation */
@import url('./modules/layout.css?v=5.1');

/* 4. Components - Buttons, Forms, Modals, Cards */
@import url('./modules/components.css');

/* 5. Pages - Page-specific Styles */
@import url('./modules/pages.css');

/* 6. Admin - Admin Panel Styles */
@import url('./modules/admin.css');

/* ==================== Remaining Specialized Styles ==================== */
/* Những style đặc biệt chưa được module hóa */

/* Leaflet Draw Controls - Đặt ở giữa cạnh phải màn hình */
.leaflet-draw-toolbar a {
    background-color: white;
    border: 1px solid var(--gray-300);
}

.leaflet-draw-toolbar a:hover {
    background-color: var(--primary-light);
}

/* Popup buttons - Chỉ đường và Street View */
.btn-popup {
    padding: 6px 10px;
    font-size: 11px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-popup:hover {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.btn-popup.btn-360 {
    background: #10b981;
    color: white;
    border-color: #10b981;
}

.btn-popup.btn-360:hover {
    background: #059669;
    border-color: #059669;
}

.btn-popup.btn-share {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.btn-popup.btn-share:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.btn-popup.btn-gmap {
    background: #1a73e8;
    color: white;
    border-color: #1a73e8;
}

.btn-popup.btn-gmap:hover {
    background: #1557b0;
    border-color: #1557b0;
}

.directions-popup {
    min-width: 200px;
}


/* Fix vị trí Leaflet draw control: góc PHẢI, cao hơn */
.leaflet-top.leaflet-right {
    top: 70px !important;
    bottom: auto !important;
    right: 10px !important;
    left: auto !important;
    transform: none;
}

/* Đảm bảo zoom control ở góc trái trên */
.leaflet-top.leaflet-left {
    top: 10px !important;
    transform: none;
}

/* Lightning Icons */
.lightning-icon {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.lightning-cluster {
    background: linear-gradient(135deg, #9333ea, #7c3aed);
    color: white;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 11px;
    box-shadow: 0 2px 8px rgba(147, 51, 234, 0.4);
}

/* Pole icons with voltage-specific colors */
.pole-icon-110kv {
    color: var(--voltage-110kv);
}

.pole-icon-35kv {
    color: var(--voltage-35kv);
}

.pole-icon-22kv {
    color: var(--voltage-22kv);
}

.pole-icon-10kv {
    color: var(--voltage-10kv);
}

/* Map Controls */
.leaflet-control {
    box-shadow: var(--shadow-md);
    border-radius: var(--border-radius);
}

.leaflet-bar a {
    border-radius: var(--border-radius-sm);
}

/* Custom Leaflet Popup - 80% Transparent */
.leaflet-popup-content-wrapper {
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    background: rgba(255, 255, 255, 0.2) !important;
    /* 80% trong suốt */
}

.leaflet-popup-content {
    margin: 15px;
    font-size: 0.875rem;
    line-height: 1.5;
}

.leaflet-popup-tip {
    background: rgba(255, 255, 255, 0.2) !important;
    /* 80% trong suốt */
}

/* ==================== CAD Tooltip Styles (V8) ==================== */
/* Dimension labels - Yellow with measurement */
.cad-dim-tooltip {
    background: #f59e0b !important;
    border: none !important;
    border-radius: 4px !important;
    padding: 3px 6px !important;
    font-size: 11px !important;
    font-weight: bold !important;
    color: #000 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

.cad-dim-tooltip::before {
    display: none !important;
}

/* Block tooltips - Yellow marker style */
.cad-block-tooltip {
    background: #fbbf24 !important;
    border: 1px solid #d97706 !important;
    border-radius: 4px !important;
    padding: 3px 6px !important;
    font-size: 10px !important;
    font-weight: bold !important;
    color: #000 !important;
}

/* Distance labels - Yellow inline style (defined in JS) */
.cad-distance-label {
    background: transparent !important;
    border: none !important;
}

/* Text tooltips - White with shadow + collision avoidance */
.cad-text-tooltip {
    background: rgba(255, 255, 255, 0.95) !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 3px !important;
    padding: 2px 5px !important;
    font-size: 10px !important;
    color: #374151 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) !important;
    white-space: nowrap !important;
    z-index: 500 !important;
}

/* Distance labels - high z-index to be on top */
.cad-distance-label span {
    z-index: 600 !important;
    position: relative !important;
}

/* Prevent marker overlap - make clickable but not block other labels */
.leaflet-marker-icon.cad-distance-label {
    pointer-events: none !important;
}

/* ==================== Responsive Design ==================== */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 340px;
    }

    .sidebar-tabs {
        font-size: 11px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-tab {
        padding: 10px 8px;
        min-width: 70px;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 100vw;
    }

    /* Mobile: Floating sidebar box - ở TRÊN để tránh bàn phím Samsung */
    .sidebar {
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        top: 55px;
        /* Ngay dưới header */
        bottom: auto;
        width: calc(100% - 20px);
        max-width: 380px;
        /* FIX: Dùng height cố định thay vì 50vh để không bị co khi bàn phím mở */
        height: auto;
        max-height: 300px;
        border-radius: 16px;
        z-index: 1001;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
        background: white;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        transition: transform 0.3s ease, opacity 0.3s ease;
        /* Mặc định ẩn - trượt LÊN */
        transform: translateX(-50%) translateY(-120%);
        opacity: 0;
        pointer-events: none;
    }

    /* Khi mở */
    .sidebar.show {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
        pointer-events: auto;
    }

    /* Handle bar - thanh kéo bên trên */
    .sidebar::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        z-index: 60;
        cursor: pointer;
    }

    /* Container cho tabs - ĐẶT Ở TRÊN CÙNG */
    .sidebar .sidebar-tabs {
        order: 0;
        flex-shrink: 0;
        background: white;
        padding: 20px 8px 8px;
        border-bottom: 1px solid #e5e7eb;
        display: flex;
        justify-content: space-around;
        gap: 4px;
    }

    .sidebar .sidebar-tabs .tab-btn {
        flex-direction: column;
        font-size: 10px;
        padding: 6px 8px;
        gap: 3px;
        min-width: 55px;
        border-radius: 8px;
        background: #f9fafb;
        border: 1px solid transparent;
    }

    .sidebar .sidebar-tabs .tab-btn:hover,
    .sidebar .sidebar-tabs .tab-btn.active {
        background: #eff6ff;
        border-color: #3b82f6;
        color: #1d4ed8;
    }

    .sidebar .sidebar-tabs .tab-btn i {
        font-size: 14px;
    }

    /* Content area - scroll trong sidebar 50vh */
    .sidebar .sidebar-content {
        order: 1;
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .sidebar .sidebar-tab-content {
        padding: 8px 12px 20px;
    }

    /* Fix input focus */
    .sidebar input,
    .sidebar select,
    .sidebar textarea {
        font-size: 16px;
    }

    /* Close button - ẩn trên mobile */
    .sidebar-close {
        display: none;
    }

    .sidebar-toggle {
        display: none;
    }

    /* Bottom navigation bar - fixed ở dưới cùng màn hình */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 50px;
        background: white;
        border-top: 1px solid #e5e7eb;
        justify-content: space-around;
        align-items: center;
        z-index: 1002;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }

    .mobile-bottom-nav .nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        padding: 6px 4px;
        font-size: 10px;
        color: #6b7280;
        text-decoration: none;
        cursor: pointer;
    }

    .mobile-bottom-nav .nav-item:hover,
    .mobile-bottom-nav .nav-item.active {
        color: #3b82f6;
    }

    .mobile-bottom-nav .nav-item i {
        font-size: 18px;
        margin-bottom: 2px;
    }
}


/* main-nav styles được định nghĩa trong index.html inline CSS để tránh xung đột */
/* Desktop: horizontal inline, Mobile: hidden (dùng quick-menu-grid thay thế) */

/* Mobile specific overrides */
@media (max-width: 768px) {
    .mobile-menu-icon {
        display: inline-block !important;
    }

    #map {
        width: 100% !important;
        left: 0 !important;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .tools-grid,
    .links-grid,
    .contact-grid {
        grid-template-columns: 1fr;
    }

    .modal-dialog {
        margin: 0 10px;
        max-width: calc(100vw - 20px);
    }

    #adminModal .modal-dialog {
        max-width: 100%;
        width: 95vw;
        height: 85vh;
    }
}

@media (max-width: 480px) {
    :root {
        --sidebar-width: 90vw;
    }

    .sidebar {
        width: 90vw;
        max-width: 320px;
    }

    .top-header {
        padding: 0 10px;
        height: 50px;
    }

    .site-name {
        font-size: 0.9rem;
    }

    .auth-buttons {
        flex-direction: row;
        gap: 6px;
    }

    .btn-sm {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .page-container {
        padding: 15px 10px;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .sidebar-section-header h3 {
        font-size: 0.9rem;
    }

    .sidebar-section-content {
        font-size: 0.85rem;
    }
}

/* ==================== Print Styles ==================== */
@media print {

    .top-header,
    .sidebar,
    .sidebar-toggle,
    .map-legend,
    .modal,
    .btn {
        display: none !important;
    }

    .main-content {
        margin-top: 0;
    }

    body {
        background: white;
    }
}

/* ==================== Utilities ==================== */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.mt-0 {
    margin-top: 0;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mt-4 {
    margin-top: 2rem;
}

.mb-0 {
    margin-bottom: 0;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.mb-4 {
    margin-bottom: 2rem;
}

.d-none {
    display: none !important;
}

.d-block {
    display: block !important;
}

.d-flex {
    display: flex !important;
}

.flex-column {
    flex-direction: column;
}

.flex-wrap {
    flex-wrap: wrap;
}

.justify-between {
    justify-content: space-between;
}

.align-center {
    align-items: center;
}

.gap-1 {
    gap: 0.5rem;
}

.gap-2 {
    gap: 1rem;
}

.text-primary {
    color: var(--primary);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.text-warning {
    color: var(--warning);
}

.text-muted {
    color: var(--gray-500);
}

.bg-primary {
    background-color: var(--primary);
}

.bg-success {
    background-color: var(--success);
}

.bg-danger {
    background-color: var(--danger);
}

.bg-warning {
    background-color: var(--warning);
}

.bg-gray-50 {
    background-color: var(--gray-50);
}

.bg-gray-100 {
    background-color: var(--gray-100);
}

.font-bold {
    font-weight: 700;
}

.font-semibold {
    font-weight: 600;
}

.font-normal {
    font-weight: 400;
}

.text-sm {
    font-size: 0.875rem;
}

.text-base {
    font-size: 1rem;
}

.text-lg {
    font-size: 1.125rem;
}

.text-xl {
    font-size: 1.25rem;
}

.shadow {
    box-shadow: var(--shadow);
}

.shadow-md {
    box-shadow: var(--shadow-md);
}

.shadow-lg {
    box-shadow: var(--shadow-lg);
}

.rounded {
    border-radius: var(--border-radius);
}

.rounded-sm {
    border-radius: var(--border-radius-sm);
}

.rounded-lg {
    border-radius: var(--border-radius-lg);
}

.rounded-full {
    border-radius: var(--border-radius-full);
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

/* ==================== Icon Grid Picker ==================== */
.icon-grid-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    font-size: 1.5em;
    border: 2px solid transparent;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Lucide icons - need to set size and color */
.icon-grid-item svg {
    width: 24px;
    height: 24px;
    stroke: #374151;
    stroke-width: 2;
}

/* Font Awesome icons */
.icon-grid-item i {
    font-size: 18px;
    color: #374151;
}

.icon-grid-item:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    transform: scale(1.1);
}

.icon-grid-item:hover svg {
    stroke: var(--primary);
}

.icon-grid-item:hover i {
    color: var(--primary);
}

.icon-grid-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.icon-grid-item.selected svg {
    stroke: var(--primary);
}

.icon-grid-item.selected i {
    color: var(--primary);
}

/* ==================== Chat Widget ==================== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 400px;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    background: white;
    margin-top: 1rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    word-wrap: break-word;
}

.chat-message.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.admin {
    align-self: flex-start;
    background: var(--gray-100);
    color: var(--gray-800);
    border-bottom-left-radius: 4px;
}

.chat-message .time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
}

.chat-message img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    margin-top: 8px;
}

.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.chat-input-area input[type="text"] {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 20px;
    font-size: 0.9rem;
}

.chat-input-area input[type="file"] {
    display: none;
}

.chat-attach-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
}

.chat-send-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-send-btn:hover {
    background: var(--primary-dark);
}

/* ==================== Report Modal Tabs ==================== */
.report-tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.report-tab-content.active {
    display: block;
}

/* ==================== End of Main Stylesheet ==================== */