/* ============================================
   FTTX Manager - Wantelco
   Estilos principales
   ============================================ */

:root {
    --primary: #0066cc;
    --primary-dark: #004d99;
    --secondary: #6c757d;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #17a2b8;
    --light: #f8f9fa;
    --dark: #343a40;
    --white: #ffffff;
    
    --sidebar-width: 320px;
    --toolbar-height: 50px;
    --border-radius: 8px;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
    
    /* Colores de fibra estándar */
    --fiber-blue: #0000FF;
    --fiber-orange: #FF8C00;
    --fiber-green: #008000;
    --fiber-brown: #8B4513;
    --fiber-gray: #808080;
    --fiber-white: #FFFFFF;
    --fiber-red: #FF0000;
    --fiber-black: #000000;
    --fiber-yellow: #FFFF00;
    --fiber-violet: #EE82EE;
    --fiber-pink: #FFC0CB;
    --fiber-aqua: #00FFFF;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--light);
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--white);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}

.sidebar-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-header .logo {
    height: 40px;
    filter: brightness(0) invert(1);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

/* Tabs */
.sidebar-tabs {
    display: flex;
    background: var(--light);
    border-bottom: 1px solid #dee2e6;
}

.tab-btn {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--secondary);
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.tab-btn:hover {
    background: rgba(0,102,204,0.1);
    color: var(--primary);
}

.tab-btn.active {
    background: var(--white);
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

.tab-btn i {
    font-size: 1.1rem;
}

/* Tab Content */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.tab-content.active {
    display: block;
}

.section {
    margin-bottom: 20px;
}

.section h3 {
    font-size: 0.9rem;
    color: var(--dark);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section h3 i {
    color: var(--primary);
}

/* Layer List */
.layer-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.layer-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: var(--light);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.layer-item:hover {
    background: #e9ecef;
}

.layer-item input[type="checkbox"] {
    margin-right: 10px;
    width: 16px;
    height: 16px;
}

.layer-item .layer-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 10px;
}

.layer-item .layer-name {
    flex: 1;
    font-size: 0.9rem;
}

.layer-item .layer-count {
    font-size: 0.75rem;
    color: var(--secondary);
    background: #dee2e6;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Element Buttons */
.element-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.btn-element {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 10px;
    border: 2px dashed #dee2e6;
    border-radius: var(--border-radius);
    background: var(--white);
    cursor: pointer;
    transition: all 0.3s;
}

.btn-element:hover {
    border-color: var(--primary);
    background: rgba(0,102,204,0.05);
}

.btn-element i {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 5px;
}

.btn-element span {
    font-size: 0.75rem;
    color: var(--dark);
}

/* Element List */
.element-list {
    max-height: 400px;
    overflow-y: auto;
}

.element-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
}

.element-item:hover {
    background: var(--light);
}

.element-item .element-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    color: var(--white);
}

.element-item .element-icon.olt { background: var(--danger); }
.element-item .element-icon.empalme { background: var(--warning); }
.element-item .element-icon.nap { background: var(--success); }
.element-item .element-icon.poste { background: var(--secondary); }
.element-item .element-icon.cliente { background: var(--info); }

.element-item .element-info {
    flex: 1;
}

.element-item .element-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.element-item .element-type {
    font-size: 0.75rem;
    color: var(--secondary);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Toolbar */
#toolbar {
    height: var(--toolbar-height);
    background: var(--white);
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    padding: 0 15px;
    gap: 10px;
    z-index: 500;
}

.toolbar-group {
    display: flex;
    gap: 5px;
    padding: 0 10px;
    border-right: 1px solid #dee2e6;
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--light);
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--dark);
}

.toolbar-btn:hover {
    background: var(--primary);
    color: var(--white);
}

.toolbar-btn.active {
    background: var(--primary);
    color: var(--white);
}

/* Map */
#map {
    flex: 1;
    background: #e5e3df;
}

/* Info Panel */
.info-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    max-height: 300px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 600;
    transition: transform 0.3s;
}

.info-panel.hidden {
    transform: translateY(100%);
}

.info-panel-header {
    padding: 12px 20px;
    background: var(--light);
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-panel-header h4 {
    font-size: 1rem;
    color: var(--dark);
}

.info-panel-content {
    padding: 15px 20px;
    overflow-y: auto;
    flex: 1;
}

/* ============================================
   MODALS
   ============================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    transform: scale(1);
    transition: transform 0.3s;
}

.modal.hidden .modal-content {
    transform: scale(0.9);
}

.modal-content.modal-lg {
    max-width: 700px;
}

.modal-content.modal-xl {
    max-width: 1000px;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-header h3 i {
    color: var(--primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #dee2e6;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #dee2e6;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,102,204,0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.file-input {
    display: none;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--white);
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-success:hover {
    background: #218838;
}

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

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: var(--secondary);
    cursor: pointer;
    padding: 5px;
    transition: color 0.2s;
}

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

/* ============================================
   NAP PORTS
   ============================================ */
.nap-ports-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #dee2e6;
}

.nap-ports-section h4 {
    margin-bottom: 15px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nap-ports-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.nap-port {
    padding: 10px;
    border: 2px solid #dee2e6;
    border-radius: var(--border-radius);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.nap-port:hover {
    border-color: var(--primary);
}

.nap-port.occupied {
    border-color: var(--success);
    background: rgba(40, 167, 69, 0.1);
}

.nap-port.selected {
    border-color: var(--primary);
    background: rgba(0, 102, 204, 0.1);
}

.nap-port .port-number {
    font-weight: 600;
    font-size: 1rem;
    color: var(--dark);
}

.nap-port .port-status {
    font-size: 0.7rem;
    color: var(--secondary);
    margin-top: 4px;
}

.nap-port .port-client {
    font-size: 0.75rem;
    color: var(--success);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   FUSION DIAGRAM
   ============================================ */
.empalme-cables-section,
.empalme-fusion-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #dee2e6;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.section-header h4 {
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cables-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cable-card {
    background: var(--light);
    border-radius: var(--border-radius);
    padding: 15px;
    border-left: 4px solid var(--primary);
}

.cable-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.cable-card-header h5 {
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cable-card-body {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    font-size: 0.85rem;
}

.cable-info-item {
    display: flex;
    flex-direction: column;
}

.cable-info-item label {
    font-size: 0.75rem;
    color: var(--secondary);
}

.cable-info-item span {
    font-weight: 500;
}

/* Buffers/Tubos Visual */
.buffers-visual {
    display: flex;
    gap: 5px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.buffer-tube {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--white);
    cursor: pointer;
    transition: transform 0.2s;
    border: 2px solid rgba(0,0,0,0.2);
}

.buffer-tube:hover {
    transform: scale(1.1);
}

/* Colores de buffers estándar */
.buffer-tube.buffer-1 { background: var(--fiber-blue); }
.buffer-tube.buffer-2 { background: var(--fiber-orange); }
.buffer-tube.buffer-3 { background: var(--fiber-green); }
.buffer-tube.buffer-4 { background: var(--fiber-brown); }
.buffer-tube.buffer-5 { background: var(--fiber-gray); }
.buffer-tube.buffer-6 { background: var(--fiber-white); color: var(--dark); }
.buffer-tube.buffer-7 { background: var(--fiber-red); }
.buffer-tube.buffer-8 { background: var(--fiber-black); }

/* Fusion Diagram Canvas */
.fusion-diagram {
    background: #fafafa;
    border: 1px solid #dee2e6;
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 20px;
    min-height: 300px;
    position: relative;
    overflow: auto;
}

#fusionCanvas {
    display: block;
    margin: 0 auto;
}

/* Fusion Table */
.fusion-table-container {
    overflow-x: auto;
}

.fusion-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.fusion-table th,
.fusion-table td {
    padding: 10px;
    text-align: center;
    border: 1px solid #dee2e6;
}

.fusion-table th {
    background: var(--light);
    font-weight: 600;
}

.fusion-table tr:hover {
    background: rgba(0,102,204,0.05);
}

.fusion-table .fiber-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0,0,0,0.2);
}

.fusion-table select,
.fusion-table input {
    width: 100%;
    padding: 5px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.8rem;
}

.fusion-table .btn-delete-fusion {
    background: var(--danger);
    color: var(--white);
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
}

/* Splitter Visual en diagrama */
.splitter-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #fff;
    border: 2px solid var(--primary);
    border-radius: var(--border-radius);
    margin: 20px 0;
}

.splitter-box {
    width: 80px;
    height: 60px;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    position: relative;
}

.splitter-input,
.splitter-outputs {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.splitter-line {
    width: 40px;
    height: 2px;
    background: var(--primary);
}

.splitter-output-line {
    width: 30px;
    height: 2px;
    background: var(--success);
}

/* ============================================
   CONTEXT MENU
   ============================================ */
.context-menu {
    position: fixed;
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    min-width: 160px;
    overflow: hidden;
}

.context-menu.hidden {
    display: none;
}

.context-menu ul {
    list-style: none;
}

.context-menu li {
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.context-menu li:hover {
    background: var(--light);
}

.context-menu li i {
    width: 16px;
    color: var(--secondary);
}

.context-menu .divider {
    height: 1px;
    background: #dee2e6;
    padding: 0;
    margin: 5px 0;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 280px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.info {
    border-left: 4px solid var(--info);
}

.toast i {
    font-size: 1.2rem;
}

.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.warning i { color: var(--warning); }
.toast.info i { color: var(--info); }

/* ============================================
   SEARCH
   ============================================ */
.search-results {
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.search-result-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: var(--light);
}

/* ============================================
   UTILITIES
   ============================================ */
.hidden {
    display: none !important;
}

.text-muted {
    color: var(--secondary);
    font-size: 0.85rem;
}

/* ============================================
   LEAFLET CUSTOMIZATION
   ============================================ */
.leaflet-popup-content-wrapper {
    border-radius: var(--border-radius);
}

.leaflet-popup-content {
    margin: 12px 15px;
}

.popup-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.popup-info {
    font-size: 0.85rem;
    color: var(--secondary);
}

.popup-info p {
    margin: 4px 0;
}

.popup-actions {
    margin-top: 10px;
    display: flex;
    gap: 5px;
}

.popup-actions .btn {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* Custom Markers */
.custom-marker {
    display: flex;
    align-items: center;
    justify-content: center;
}

.marker-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    border: 2px solid white;
}

.marker-icon.olt { background: var(--danger); }
.marker-icon.empalme { background: var(--warning); color: var(--dark); }
.marker-icon.nap { background: var(--success); }
.marker-icon.poste { background: var(--secondary); }
.marker-icon.cliente { background: var(--info); }

/* Cable styles */
.cable-line {
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ============================================
   EMPALME INFO PANEL
   ============================================ */
.empalme-info {
    padding: 15px;
}

.empalme-info h4 {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.empalme-summary {
    background: var(--light);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 15px;
}

.empalme-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.empalme-stat {
    text-align: center;
}

.empalme-stat .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.empalme-stat .label {
    font-size: 0.75rem;
    color: var(--secondary);
}

/* Mini fusion diagram */
.mini-fusion-diagram {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: var(--border-radius);
    padding: 15px;
    overflow-x: auto;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100%;
        transition: left 0.3s;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .nap-ports-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
