/* ========== BASE STYLES ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #0B5A8E;
    --primary-dark: #074267;
    --primary-light: #E8F3F8;
    --primary-gradient: linear-gradient(135deg, #0B5A8E 0%, #1a7fb5 100%);
    --success: #10B981;
    --success-light: #D1FAE5;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --surface: #FFFFFF;
    --surface-dark: #F8FAFC;
    --text: #1E293B;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
}

body, html {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    background: #F1F5F9;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes blink-live {
    0% { opacity: 1; }
    50% { opacity: 0.4; }
    100% { opacity: 1; }
}

.dashboard-wrapper {
    display: flex;
    flex-direction: column;
    min-height: auto;
}

.dashboard {
    display: flex;
    flex: 1;
    padding: 20px;
    gap: 20px;
    min-height: calc(100vh - 80px);
}

.map-panel {
    flex: 0 0 60%;
    position: relative;
    background: #0a0a0a;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    height: calc(100vh - 120px);
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ========== PETA KONTROL VERTIKAL ========== */
.map-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.controls-toggle {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    box-shadow: var(--shadow-lg);
    order: 2;
    font-size: 18px;
    transition: all 0.3s ease;
}

.controls-toggle:hover {
    transform: scale(1.05);
}

.controls-toggle i {
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.map-controls.expanded .controls-toggle i {
    transform: rotate(180deg);
}

.controls-content {
    order: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    padding: 10px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    
    visibility: hidden;
    opacity: 0;
    transform: scale(0.9) translateY(-15px);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.map-controls.expanded .controls-content {
    visibility: visible;
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    opacity: 0;
    transform: translateX(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.map-controls.expanded .control-group {
    opacity: 1;
    transform: translateX(0);
}

.map-controls.expanded .control-group:nth-child(1) {
    transition-delay: 0.05s;
}

.map-controls.expanded .control-group:nth-child(2) {
    transition-delay: 0.12s;
}

.map-controls:not(.expanded) .controls-content {
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.map-controls:not(.expanded) .control-group {
    transition-delay: 0s !important;
}

.layer-buttons, .zoom-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.layer-btn, .zoom-btn {
    width: 24px;
    height: 24px;
    background: var(--surface-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    transition: all 0.2s ease;
}

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

/* ========== PANEL DATA ========== */
.data-panel {
    flex: 0 0 40%;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: calc(100vh - 120px);
}

.stats-header {
    padding: 20px;
    background: var(--primary-gradient);
    color: white;
    flex-shrink: 0;
    position: relative;
}

.stats-header h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
}

.stats-header p {
    font-size: 11px;
    opacity: 0.8;
    margin: 8px 0 0;
    color: #ffffff;
}

.api-status {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0,0,0,0.3);
    padding: 6px 12px;
    border-radius: 40px;
    font-size: 11px;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.api-status i { font-size: 10px; }

.api-status.status-live {
    background: rgba(16,185,129,0.2);
    color: #10B981;
    border: 1px solid rgba(16,185,129,0.5);
}
.api-status.status-live i { animation: blink-live 1s ease-in-out infinite; }

.api-status.status-simulasi {
    background: rgba(245,158,11,0.2);
    color: #F59E0B;
    border: 1px solid rgba(245,158,11,0.5);
}

.api-status.status-offline {
    background: rgba(239,68,68,0.2);
    color: #EF4444;
    border: 1px solid rgba(239,68,68,0.5);
}

.stat-cards {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.stat-card {
    flex: 1;
    background: rgba(255,255,255,0.15);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 800;
}

.stat-card .label {
    font-size: 10px;
    opacity: 0.8;
    margin-top: 4px;
}

.filter-bar {
    padding: 12px 16px;
    background: var(--surface-dark);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.filter-input {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.filter-input i {
    font-size: 12px;
    color: var(--text-muted);
}

.filter-input input, .filter-input select {
    border: none;
    background: none;
    font-size: 12px;
    outline: none;
    width: 100%;
    font-family: inherit;
    cursor: pointer;
}

.interval-group {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
}

.interval-group span { font-size: 11px; color: var(--text-muted); }
.interval-buttons { display: flex; gap: 4px; }

.interval-btn {
    padding: 4px 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}
.interval-btn:hover { background: var(--primary-light); color: var(--primary); }
.interval-btn.active { background: var(--primary); color: white; }

.table-container {
    flex: 1;
    overflow-y: auto;
}

.ships-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.ships-table th {
    background: var(--surface-dark);
    padding: 12px;
    text-align: center;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    position: sticky;
    top: 0;
}

.ships-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
    text-align: center;
}

.ships-table td:nth-child(1),
.ships-table th:nth-child(1) { text-align: left; }

.ships-table tr {
    cursor: pointer;
    transition: all 0.15s ease;
}

.ships-table tr:hover {
    background: var(--surface-dark);
}

.ships-table th:nth-child(1), .ships-table td:nth-child(1) { width: 28%; }
.ships-table th:nth-child(2), .ships-table td:nth-child(2) { width: 10%; }
.ships-table th:nth-child(3), .ships-table td:nth-child(3) { width: 12%; }
.ships-table th:nth-child(4), .ships-table td:nth-child(4) { width: 12%; }
.ships-table th:nth-child(5), .ships-table td:nth-child(5) { width: 15%; }
.ships-table th:nth-child(6), .ships-table td:nth-child(6) { width: 23%; }

.ship-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ship-icon {
    width: 28px;
    height: 28px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ship-icon i { font-size: 12px; color: var(--primary); }

.ship-name-text {
    font-weight: 500;
    color: var(--text);
}

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
}
.status-sailing { background: var(--primary-light); color: var(--primary); }
.status-docked { background: var(--danger-light); color: var(--danger); }

.ship-code {
    font-weight: 600;
    font-size: 12px;
    color: var(--primary);
    font-family: monospace;
    letter-spacing: 0.5px;
}

/* ========== EMPTY STATE CENTER ========== */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}
.empty-state div {
    text-align: center;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    padding: 10px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    transition: transform 0.3s ease;
    border-left: 3px solid var(--primary);
}
.toast.show { transform: translateX(-50%) translateY(0); }

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    display: none;
}
.loading-card {
    background: var(--surface);
    padding: 20px 30px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: var(--shadow-lg);
}
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* MARKER & POPUP */
.arrow-marker-container { position: relative; display: inline-block; }
.arrow-icon-rotated { display: block; transition: transform 0.2s ease-out; }
.ship-code-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.75);
    color: white;
    font-size: 8px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    font-family: monospace;
    letter-spacing: 0.5px;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.dock-marker-custom {
    background: linear-gradient(135deg, #6B7280, #9CA3AF);
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px !important;
    height: 18px !important;
}
.dock-marker-custom i { color: white; font-size: 8px !important; }

.table-container::-webkit-scrollbar { width: 4px; }
.table-container::-webkit-scrollbar-track { background: var(--border); border-radius: 2px; }
.table-container::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 2px; }

.leaflet-popup-content-wrapper {
    border-radius: 6px !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08) !important;
    border: 1px solid #E2E8F0 !important;
    overflow: hidden !important;
    padding: 0 !important;
    background: #FFFFFF !important;
}

.leaflet-popup-content {
    margin: 0 !important;
    width: 280px !important;
    max-width: 90vw !important;
    font-family: 'Inter', -apple-system, sans-serif !important;
    line-height: 1.4 !important;
    font-size: 12px !important;
}

.leaflet-popup-tip-container {
    margin-top: -1px !important;
}

.leaflet-popup-tip {
    box-shadow: 0 2px 6px rgba(0,0,0,0.08) !important;
    background: #FFFFFF !important;
    border: 1px solid #E2E8F0 !important;
}

.leaflet-popup-close-button {
    position: absolute !important;
    top: 6px !important;
    right: 6px !important;
    width: 20px !important;
    height: 20px !important;
    background: rgba(255, 255, 255, 0.2) !important;
    border-radius: 50% !important;
    color: white !important;
    font-size: 14px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 1000 !important;
    transition: all 0.2s ease !important;
}

.leaflet-popup-close-button:hover {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: scale(1.1) !important;
}

/* ========== POPUP KAPAL (SAMA DENGAN AIS-POLBENG) ========== */
/* Header popup kapal */
.ship-popup-header {
    padding: 12px !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #328FDB;
    color: white;
}

.ship-popup-header.docked {
    background: #FF1A1A !important;
}

.ship-popup-header .ship-popup-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
}

.ship-popup-header .ship-popup-title i {
    font-size: 14px;
}

.ship-popup-header .ship-popup-title h4 {
    font-size: 13px;
    font-weight: 700;
    margin: 0;
    color: white;
}

/* Body popup kapal */
.ship-popup-body {
    padding: 12px !important;
    background: #FFFFFF;
}

/* Grid info 2 kolom */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px !important;
    margin-bottom: 12px !important;
}

.info-item {
    background: #F8FAFC;
    padding: 8px !important;
    border-radius: 4px;
    border: 1px solid #E2E8F0;
}

.info-label {
    font-size: 9px !important;
    color: #64748B;
    margin-bottom: 2px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.info-value {
    font-size: 12px !important;
    font-weight: 700;
    color: #0F172A;
}

.info-value.speed-high { color: #10B981; }
.info-value.speed-mid { color: #F59E0B; }

/* Box koordinat */
.coordinates-box {
    background: #F1F5F9;
    padding: 8px !important;
    border-radius: 4px;
    margin-bottom: 12px !important;
    border: 1px solid #E2E8F0;
}

.coordinates-label {
    font-size: 9px !important;
    color: #64748B;
    margin-bottom: 2px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.coordinates-value {
    font-size: 12px !important;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: #1E293B;
    word-break: break-all;
}

/* Box rute - warna dinamis */
.destination-box {
    background: #F1F5F9;
    padding: 8px !important;
    border-radius: 4px;
    margin-bottom: 12px !important;
    border: 1px solid #E2E8F0;
}

.destination-label {
    font-size: 9px !important;
    color: #64748B;
    margin-bottom: 2px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.destination-value {
    font-size: 12px !important;
    font-weight: 600;
    color: #0B5A8E;
}

.destination-value.docked {
    color: #FF1A1A !important;
}

/* Estimasi dermaga */
.docks-estimation {
    background: rgba(59, 130, 246, 0.05);
    padding: 10px !important;
    border-radius: 4px;
    margin-bottom: 10px !important;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.estimation-title {
    font-weight: 600;
    color: #328FDB;
    margin-bottom: 6px;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dock-item {
    background: rgba(255, 255, 255, 0.9);
    padding: 6px !important;
    border-radius: 3px;
    margin-bottom: 4px;
    border: 1px solid #E2E8F0;
    font-size: 10px;
}

.dock-item:last-child {
    margin-bottom: 0;
}

.dock-item.nearest {
    border-color: #3B82F6;
}

.dock-name {
    font-weight: 600;
    font-size: 10px !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
    color: #1E293B;
}

.nearest-badge {
    background: #10B981;
    color: white;
    padding: 2px 4px;
    border-radius: 8px;
    font-size: 6px;
    font-weight: 600;
}

.dock-details {
    display: flex;
    justify-content: space-between;
    font-size: 9px !important;
    color: #64748B;
}

.dock-time {
    font-weight: 600;
    color: #3B82F6;
}

.dock-distance {
    font-weight: 500;
    color: #64748B;
}

/* Info berlabuh */
.at-dock-info {
    background: rgba(239, 68, 68, 0.1);
    padding: 10px !important;
    border-radius: 4px;
    margin-bottom: 10px;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.at-dock-title {
    font-weight: 600;
    font-size: 11px !important;
    color: #FF1A1A;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ========== POPUP DERMAGA ========== */
.dock-popup-header {
    background: linear-gradient(135deg, #6B7280 0%, #9CA3AF 100%);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.dock-popup-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dock-popup-title i {
    font-size: 14px;
}

.dock-popup-title-text {
    display: flex;
    flex-direction: column;
}

.dock-popup-name {
    font-size: 14px;
    font-weight: 700;
}

.dock-popup-body {
    padding: 16px;
    background: #FFFFFF;
}

.dock-popup-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.dock-popup-item {
    background: #F8FAFC;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #E2E8F0;
}

.dock-popup-label {
    font-size: 9px;
    color: #64748B;
    margin-bottom: 4px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.dock-popup-value {
    font-size: 12px;
    font-weight: 700;
    color: #1E293B;
}

.dock-popup-value.available { color: #10B981; }
.dock-popup-value.occupied { color: #F59E0B; }

.dock-popup-coordinates {
    background: #F1F5F9;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 16px;
    border: 1px solid #E2E8F0;
}

.dock-popup-coordinates-label {
    font-size: 9px;
    color: #64748B;
    margin-bottom: 4px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.dock-popup-coordinates-value {
    font-size: 12px;
    font-family: monospace;
    color: #1E293B;
    font-weight: 600;
    word-break: break-all;
}

.dock-popup-ship-info {
    background: rgba(59, 130, 246, 0.05);
    padding: 12px;
    border-radius: 4px;
    border: 1px solid rgba(59, 130, 246, 0.2);
    display: none;
}

.dock-popup-ship-info.visible {
    display: block;
}

.dock-popup-ship-header {
    font-size: 11px;
    font-weight: 600;
    color: #3B82F6;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dock-popup-ship-details {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
    border: 1px solid #E2E8F0;
}

.dock-popup-ship-name {
    font-size: 12px;
    font-weight: 700;
    color: #1E293B;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
}

@media (max-width: 900px) {
    .dashboard {
        flex-direction: column;
        padding: 12px;
        gap: 12px;
        min-height: auto;
    }
    .map-panel, .data-panel {
        flex: none;
        height: 400px;
    }
    .data-panel { height: 500px; }
}