@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg-base: #080b11;
    --bg-surface: rgba(15, 20, 32, 0.82);
    --bg-surface-hover: rgba(26, 33, 50, 0.9);
    --bg-darker: rgba(7, 10, 17, 0.95);
    
    --border-color: rgba(255, 255, 255, 0.07);
    --border-accent: rgba(0, 112, 243, 0.25);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #475569;
    
    --accent: #0070f3; /* Indigo */
    --accent-hover: #4f46e5;
    --accent-glow: rgba(0, 112, 243, 0.2);
    
    /* Category colors */
    --color-olt: #ef4444;       
    --color-manga: #f59e0b;     
    --color-nap: #10b981;       
    --color-proposed: #06b6d4;  
    --color-cable: #3b82f6;     
    --color-odf: #38bdf8;       
    --color-pole: #cbd5e1;      
    
    --shadow-sm: 0 2px 8px -2px rgba(0,0,0,0.5);
    --shadow-md: 0 8px 24px -4px rgba(0,0,0,0.6);
    --shadow-lg: 0 16px 40px -8px rgba(0,0,0,0.8);
    
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-primary);
    overflow-x: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header styled with gradients and glassmorphism */
header {
    background: linear-gradient(to right, rgba(8, 11, 17, 0.9), rgba(15, 20, 32, 0.9));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), #38bdf8);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(0, 112, 243, 0.3);
}

.brand-icon svg {
    width: 20px;
    height: 20px;
    color: white;
}

.brand-info h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-info p {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

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

.btn-action {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.78rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-action:hover {
    background: rgba(255, 255, 255, 0.09);
    border-color: var(--text-secondary);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    border: none;
    box-shadow: 0 4px 10px rgba(0, 112, 243, 0.2);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0, 112, 243, 0.3);
}

/* File Actions (Import/Export) */
.file-actions {
    display: flex;
    gap: 6px;
}

/* Main Layout */
.app-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Map area */
#map {
    flex: 1;
    height: 100%;
    background-color: #0b0e14;
    z-index: 1;
}

/* Drawing Floating Toolbar */
.drawing-toolbar {
    position: absolute;
    top: 80px;
    left: 20px;
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 999;
    box-shadow: var(--shadow-lg);
}

.tool-btn {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    padding: 0;
    flex-shrink: 0;
}

.tool-btn svg {
    width: 22px;
    height: 22px;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.tool-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 10px rgba(0, 112, 243, 0.4);
}

/* Per-element active state accent colors */
.tool-btn--olt.active    { background: #ef4444; box-shadow: 0 0 12px rgba(239,68,68,0.45); }
.tool-btn--manga.active  { background: #f59e0b; box-shadow: 0 0 12px rgba(245,158,11,0.45); }
.tool-btn--nap8.active   { background: #10b981; box-shadow: 0 0 12px rgba(16,185,129,0.45); }
.tool-btn--nap16.active  { background: #0ea5e9; box-shadow: 0 0 12px rgba(14,165,233,0.45); }
.tool-btn--odf.active    { background: #0284c7; box-shadow: 0 0 12px rgba(139,92,246,0.45); }
.tool-btn--pole.active   { background: #64748b; box-shadow: 0 0 12px rgba(100,116,139,0.45); }

/* Toolbar separator */
.toolbar-sep {
    height: 1px;
    background: var(--border-color);
    margin: 2px 6px;
}

.tool-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 48px;
    background: var(--bg-darker);
    border: 1px solid var(--border-color);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.tool-btn:hover::after {
    opacity: 1;
}

/* Sidebar Dashboard */
.sidebar {
    width: 440px;
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 10;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-box {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 8px;
    color: white;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
}

.search-box:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 16px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.015);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--accent);
}

.stat-card.olt::before { background: var(--color-olt); }
.stat-card.manga::before { background: var(--color-manga); }
.stat-card.nap::before { background: var(--color-nap); }
.stat-card.length::before { background: var(--color-cable); }

.stat-val {
    font-size: 1.3rem;
    font-weight: 800;
    margin-top: 2px;
}

.stat-lbl {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.1);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 10px 4px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(255, 255, 255, 0.01);
}

.tab-content {
    flex: 1;
    display: none;
}

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

.content-section {
    padding: 16px;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Item List */
.item-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 380px;
    overflow-y: auto;
}

.network-item {
    background: rgba(255, 255, 255, 0.015);
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.network-item:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-accent);
}

.item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 75%;
}

.item-name {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-meta {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
}

/* Modals (Editing Panels) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-card {
    background: var(--bg-darker);
    border: 1px solid var(--border-accent);
    border-radius: 16px;
    width: 650px;
    max-width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: zoomIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.3rem;
}

.modal-close:hover {
    color: white;
}

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

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

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

.form-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    color: white;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
}

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

/* Splicing Matrix Table */
.matrix-container {
    width: 100%;
    overflow-x: auto;
    margin-top: 15px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 250px;
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.72rem;
}

.matrix-table th, .matrix-table td {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    text-align: center;
}

.matrix-table th {
    background: rgba(255,255,255,0.02);
    font-weight: 700;
    color: var(--text-secondary);
}

/* Fiber Colors Indicators TIA-598 */
.fiber-dot {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
    border: 1px solid rgba(255,255,255,0.2);
}

.fiber-badge {
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    color: white;
    border: 1px solid rgba(255,255,255,0.1);
}

.fiber-c-1 { background-color: #3b82f6; color: white; }
.fiber-c-2 { background-color: #f97316; color: white; }
.fiber-c-3 { background-color: #22c55e; color: white; }
.fiber-c-4 { background-color: #78350f; color: white; }
.fiber-c-5 { background-color: #64748b; color: white; }
.fiber-c-6 { background-color: #ffffff; color: black; border-color: #ccc; }
.fiber-c-7 { background-color: #ef4444; color: white; }
.fiber-c-8 { background-color: #090d16; color: white; }
.fiber-c-9 { background-color: #eab308; color: black; }
.fiber-c-10 { background-color: #0284c7; color: white; }
.fiber-c-11 { background-color: #ec4899; color: black; }
.fiber-c-12 { background-color: #06b6d4; color: black; }

/* ODF Mapping UI */
.odf-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.odf-port {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.odf-port:hover {
    background: var(--bg-surface-hover);
    border-color: var(--accent);
}

.odf-port.connected {
    border-color: var(--color-nap);
    background: rgba(16, 185, 129, 0.08);
}

.odf-port-num {
    font-size: 0.8rem;
    font-weight: 700;
}

.odf-port-lbl {
    font-size: 0.6rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* BOM Catalog Table Inputs */
.bom-table input {
    width: 60px;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    color: white;
    padding: 3px 6px;
    border-radius: 4px;
    text-align: right;
    font-family: var(--font-sans);
    font-size: 0.75rem;
}

/* Action tooltips on map element select */
.action-box {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    border: none;
    color: white;
}

.btn-danger:hover {
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3);
}

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

.btn-secondary:hover {
    background: rgba(255,255,255,0.1);
}

/* Detail Card custom overlay styling */
.detail-card {
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-accent);
    padding: 16px;
    border-radius: 12px;
    margin: 12px;
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    gap: 10px;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.detail-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.detail-category {
    font-size: 0.65rem;
    text-transform: uppercase;
    font-weight: 700;
    background: var(--accent-glow);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 2px;
}

.detail-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
}

.detail-body {
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

.detail-coordinates {
    font-size: 0.7rem;
    font-family: monospace;
    background: rgba(0, 0, 0, 0.25);
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-muted);
}

/* Leaflet control custom positions */
.leaflet-left .leaflet-control {
    margin-left: 70px !important; /* Move Leaflet zoom bar to make space for drawing toolbar */
}

/* Printable PDF stylesheet rules */
@media print {
    body, html {
        background: white !important;
        color: black !important;
        height: auto !important;
        overflow: visible !important;
    }
    header, .drawing-toolbar, .sidebar, .modal-overlay, .search-box, .tabs {
        display: none !important;
    }
    .app-container {
        display: block !important;
        height: auto !important;
    }
    #map {
        width: 100% !important;
        height: 480px !important;
        border: 1px solid #ccc;
        margin-bottom: 25px;
    }
    .print-report {
        display: block !important;
        color: black !important;
    }
}

.print-report {
    display: none;
}

/* ────────────────────────────────────────────────────────────────
   Custom FiberDeploy Map Marker Icons
   ──────────────────────────────────────────────────────────────── */

/* Wrapper produced by L.divIcon — reset Leaflet default container */
.fd-marker-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.fd-marker-wrap:hover {
    transform: scale(1.22);
    z-index: 999 !important;
}

/* Selected state — extra glow pulse */
.fd-marker-wrap.fd-selected {
    animation: markerPulse 1.8s ease-in-out infinite;
    transform: scale(1.12);
    z-index: 1000 !important;
}

@keyframes markerPulse {
    0%,100% { filter: drop-shadow(0 0 4px rgba(168, 85, 247, 0.5)); }
    50%      { filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.9)); }
}

/* Leaflet sets pointer-events on the icon container — ensure it's clickable */
.leaflet-marker-icon {
    cursor: pointer !important;
}

/* ── 3-Way Map Style Toggle ──────────────────────────────────────── */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,0.04);
    transition: all 0.2s ease;
    user-select: none;
}

.toggle-container:hover {
    background: rgba(255,255,255,0.08);
    border-color: var(--text-secondary);
}

.toggle-switch {
    width: 28px;
    height: 14px;
    border-radius: 7px;
    background: rgba(255,255,255,0.15);
    position: relative;
    transition: background 0.25s;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: white;
    transition: transform 0.25s, background 0.25s;
}

/* Light mode — switch mid position */
.toggle-container.active .toggle-switch {
    background: var(--accent);
}
.toggle-container.active .toggle-switch::after {
    transform: translateX(14px);
}

/* Satellite mode — switch right, amber tint */
.toggle-container.satellite .toggle-switch {
    background: #f59e0b;
}
.toggle-container.satellite .toggle-switch::after {
    transform: translateX(8px);
    background: #fffbeb;
}

.toggle-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: color 0.2s;
}

.toggle-container.active .toggle-label {
    color: var(--text-primary);
}

.toggle-container.satellite .toggle-label {
    color: #f59e0b;
}

/* ODF stat card accent */
.stat-card.odf::before { background: var(--color-odf); }
