/* ========================================
   FTTH Schematic Topology - Mobile-First Stylesheet
   ======================================== */

/* Palet warna selaras dengan logo: pin merah, peta hijau, aksen biru/teal, outline abu gelap */
:root {
    /* Primary: merah (location pin) */
    --primary-color: #c62828;
    --primary-dark: #b71c1c;
    --primary-light: #ef5350;
    /* Secondary: teal/biru (map & server lights) */
    --secondary-color: #00838f;
    --secondary-light: #26a69a;
    /* Success: hijau (peta) */
    --success-color: #2e7d32;
    --success-light: #43a047;
    /* Warning: kuning/emas (garis jalan) */
    --warning-color: #f9a825;
    --danger-color: #c62828;
    /* Teks & struktur: abu gelap/hitam (outline logo) */
    --text-primary: #212121;
    --text-secondary: #546e7a;
    --text-muted: #78909c;
    --bg-primary: #ffffff;
    --bg-secondary: #eceff1;
    --bg-dark: #37474f;
    --border-color: #cfd8dc;
    --shadow: 0 2px 8px rgba(0,0,0,0.12);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.18);
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-secondary);
    overflow: hidden;
}

/* ========================================
   LAYOUT
   ======================================== */

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

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow);
    z-index: 100;
}

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

.app-title {
    font-size: 18px;
    font-weight: 600;
}

/* Main Content */
.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.view-container.active {
    opacity: 1;
    visibility: visible;
    z-index: 1;
}

/* ========================================
   BOTTOM NAVIGATION
   ======================================== */

.bottom-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: white;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    padding: 8px 0;
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.nav-item i {
    font-size: 20px;
}

.nav-item span {
    font-size: 11px;
    font-weight: 500;
}

.nav-item.active {
    color: var(--primary-color);
}

.nav-item:active {
    background: var(--bg-secondary);
}

/* FAB (Floating Action Button) */
.fab-container {
    flex: 0;
    padding: 0;
}

.fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: var(--transition);
    margin-top: -28px;
}

.fab:active {
    transform: scale(0.95);
    background: var(--primary-dark);
}

/* ========================================
   BUTTONS
   ======================================== */

.icon-btn,
.icon-btn-sm {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
}

.icon-btn-sm {
    width: 32px;
    height: 32px;
    font-size: 16px;
}

.icon-btn:active,
.icon-btn-sm:active {
    background: rgba(255,255,255,0.2);
}

.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    width: 100%;
    justify-content: center;
}

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

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

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

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

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

.btn-danger:active {
    background: #d32f2f;
}

/* ========================================
   SEARCH PANEL
   ======================================== */

.search-panel {
    background: white;
    padding: 16px;
    box-shadow: var(--shadow);
    transition: var(--transition);
    max-height: 200px;
    overflow: hidden;
}

.search-panel.hidden {
    max-height: 0;
    padding: 0 16px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 24px;
    margin-bottom: 12px;
}

.search-box i {
    color: var(--text-secondary);
}

.search-box input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 14px;
}

.filter-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.filter-chips::-webkit-scrollbar {
    height: 4px;
}

.filter-chips::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.chip {
    padding: 6px 16px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--transition);
}

.chip.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ========================================
   SIDE MENU
   ======================================== */

.side-menu {
    position: fixed;
    top: 0;
    left: -100%;
    width: 280px;
    height: 100vh;
    background: white;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

.side-menu.active {
    left: 0;
}

.menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--primary-color);
    color: white;
}

.menu-header h2 {
    font-size: 20px;
}

.menu-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    cursor: pointer;
    transition: var(--transition);
}

.menu-item:active {
    background: var(--bg-secondary);
}

.menu-item i {
    width: 24px;
    font-size: 20px;
    color: var(--text-secondary);
}

.menu-item span {
    font-size: 15px;
}

.menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0;
}

.menu-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-footer small {
    font-size: 12px;
    color: var(--text-muted);
}

.menu-footer .menu-credit {
    display: block;
    margin-top: 8px;
    font-weight: 600;
    color: var(--primary-color);
}

/* ========================================
   MAP VIEW
   ======================================== */

#map {
    width: 100%;
    height: 100%;
}

.gps-info {
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 16px;
    z-index: 1000;
    transition: var(--transition);
}

.gps-info.hidden {
    transform: translateY(calc(100% + 32px));
}

.gps-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.gps-header i {
    color: var(--primary-color);
    font-size: 20px;
}

.gps-header span {
    flex: 1;
    font-weight: 600;
}

.gps-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.gps-item {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.gps-item .label {
    color: var(--text-secondary);
}

/* ========================================
   TOPOLOGY VIEW
   ======================================== */

#topology {
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
}

.topology-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.topology-controls .icon-btn {
    background: white;
    box-shadow: var(--shadow);
}

/* ========================================
   LIST VIEW
   ======================================== */

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

.list-header h3 {
    font-size: 18px;
}

.badge {
    background: var(--primary-color);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.asset-list {
    height: calc(100% - 60px);
    overflow-y: auto;
    padding: 8px;
}

.asset-item {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
}

.asset-item:active {
    transform: scale(0.98);
}

.asset-item-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.asset-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
}

.asset-icon.ODP { background: var(--success-color); }
.asset-icon.ODC { background: var(--secondary-color); }
.asset-icon.OLT { background: var(--bg-dark); }
.asset-icon.FAT { background: var(--warning-color); }
.asset-icon.JC { background: #795548; }
.asset-icon.Pole { background: var(--text-secondary); }
.asset-icon.Cable { background: var(--primary-color); }
.asset-icon.Customer { background: var(--secondary-light); }

.asset-info {
    flex: 1;
}

.asset-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.asset-type {
    font-size: 12px;
    color: var(--text-secondary);
}

.asset-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.asset-status.active {
    background: #e8f5e9;
    color: var(--success-color);
}

.asset-status.maintenance {
    background: #fff8e1;
    color: var(--warning-color);
}

.asset-status.inactive {
    background: #ffebee;
    color: var(--danger-color);
}

.asset-details {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state p {
    margin-bottom: 4px;
}

.text-muted {
    color: var(--text-muted);
    font-size: 14px;
}

/* ========================================
   MODAL
   ======================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-end;
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    width: 100%;
    max-height: 90vh;
    background: white;
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.modal.active .modal-content {
    transform: translateY(0);
}

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

.modal-header h2 {
    font-size: 20px;
}

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

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.modal-footer button {
    flex: 1;
}

/* ========================================
   FORM
   ======================================== */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-group small {
    color: var(--text-secondary);
    font-weight: 400;
}

.required {
    color: var(--danger-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input:read-only {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.type-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.type-btn {
    padding: 16px 8px;
    border: 2px solid var(--border-color);
    background: white;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.type-btn i {
    font-size: 24px;
    color: var(--text-secondary);
}

.type-btn span {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
}

.type-btn.active {
    border-color: var(--primary-color);
    background: var(--primary-light);
    color: white;
}

.type-btn.active i {
    color: white;
}

.conditional-fields {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.fields-container.hidden {
    display: none;
}

/* ========================================
   DETAIL VIEW
   ======================================== */

.detail-grid {
    display: grid;
    gap: 16px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
}

.detail-value {
    font-size: 15px;
    color: var(--text-primary);
}

.detail-map {
    width: 100%;
    height: 200px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

/* ========================================
   OVERLAY
   ======================================== */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   LOADING
   ======================================== */

.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    z-index: 400;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-secondary);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* ========================================
   TOAST
   ======================================== */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-dark);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 500;
    transition: var(--transition);
    opacity: 0;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ========================================
   DEBUG PANEL
   ======================================== */

.debug-panel {
    position: fixed;
    top: 60px;
    right: 16px;
    background: rgba(0, 0, 0, 0.9);
    color: #0f0;
    padding: 12px;
    border-radius: 8px;
    font-family: monospace;
    font-size: 11px;
    z-index: 999;
    min-width: 200px;
    box-shadow: var(--shadow-lg);
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #333;
}

.debug-header span {
    font-weight: 600;
}

.debug-header .icon-btn-sm {
    color: #fff;
}

.debug-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.debug-item {
    display: flex;
    gap: 8px;
}

.debug-item strong {
    color: #0ff;
    min-width: 60px;
}

.debug-item span {
    color: #0f0;
}

/* ========================================
   ADD CABLE - SEARCH ASSET TUJUAN
   ======================================== */

.cable-from-to-info {
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 16px;
}

.cable-info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.cable-info-row .label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 60px;
}

.cable-to-list-label {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.cable-to-asset-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 12px;
}

.cable-to-asset-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}

.cable-to-asset-item:last-child {
    border-bottom: none;
}

.cable-to-asset-item:hover {
    background: var(--bg-secondary);
}

.cable-to-asset-item.selected {
    background: var(--primary-light);
    color: white;
}

.cable-to-asset-item .cable-to-asset-name {
    font-weight: 600;
    font-size: 14px;
}

.cable-to-asset-item .cable-to-asset-type {
    font-size: 12px;
    opacity: 0.8;
}

.cable-to-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.cable-to-selected {
    padding: 8px 12px;
    background: #e8f5e9;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
}

.cable-to-selected .label {
    color: var(--text-secondary);
    margin-right: 8px;
}

.cable-to-selected.hidden {
    display: none !important;
}

/* Settings modal (Clear / Load Demo) */
.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.settings-actions .btn-primary,
.settings-actions .btn-danger {
    justify-content: center;
}

/* ========================================
   UTILITIES
   ======================================== */

.hidden {
    display: none !important;
}

/* ========================================
   LEAFLET CUSTOM STYLES
   ======================================== */

.custom-marker {
    transition: var(--transition);
}

.leaflet-popup-content-wrapper {
    border-radius: 12px;
    padding: 0;
}

.leaflet-popup-content {
    margin: 0;
    min-width: 200px;
}

.popup-header {
    padding: 12px 16px;
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    font-size: 15px;
}

.popup-body {
    padding: 12px 16px;
}

.popup-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
}

.popup-item .label {
    color: var(--text-secondary);
}

.popup-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
}

.popup-btn,
.btn-popup-detail,
.btn-popup-add-cable {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    pointer-events: auto;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
}

/* Pastikan tombol popup Leaflet bisa diklik */
.leaflet-popup-content-wrapper .popup-btn,
.leaflet-popup-content-wrapper .btn-popup-add-cable,
.leaflet-popup-content-wrapper .btn-popup-detail {
    cursor: pointer;
    pointer-events: auto;
}

.popup-btn:active {
    transform: scale(0.95);
}

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

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

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

.popup-btn-secondary:hover {
    background: #006064;
}

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

.popup-btn-danger:hover {
    background: #d32f2f;
}

/* ========================================
   RESPONSIVE (Tablet & Desktop)
   ======================================== */

@media (min-width: 768px) {
    .modal-content {
        width: 600px;
        margin: 0 auto;
        max-height: 80vh;
        border-radius: 16px;
        margin-top: auto;
        margin-bottom: auto;
    }
    
    .modal {
        align-items: center;
    }
    
    .type-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .side-menu {
        width: 320px;
    }
}

@media (min-width: 1024px) {
    .bottom-nav {
        display: none;
    }
    
    /* Add desktop navigation here if needed */
}
