/* ============================================================
   VARIABLES & RESET
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@300;400;500;600;700&display=swap');

:root {
    --bg-dark:        #0f1117;
    --bg-panel:       #1a1d27;
    --bg-panel-2:     #22263a;
    --bg-glass:       rgba(26, 29, 39, 0.92);
    --border:         rgba(255,255,255,0.08);
    --border-hover:   rgba(255,255,255,0.18);

    --accent:         #4f9cf9;
    --accent-hover:   #6aadff;
    --accent-glow:    rgba(79,156,249,0.3);

    --text-primary:   #e8ecf4;
    --text-secondary: #8892a4;
    --text-dim:       #5a6378;

    --success:        #34d399;
    --warning:        #fbbf24;
    --danger:         #f87171;

    /* Loại đất */
    --land-ont:  #FFE033;
    --land-odt:  #FF8C00;
    --land-cln:  #5ECB6E;
    --land-lua:  #98FB98;
    --land-dgt:  #8899AA;
    --land-skc:  #9370DB;
    --land-tmd:  #FF4D2E;
    --land-nts:  #5BC8E8;

    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  16px;
    --shadow:     0 4px 24px rgba(0,0,0,0.5);
    --shadow-lg:  0 8px 40px rgba(0,0,0,0.6);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    font-family: 'Be Vietnam Pro', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   BẢN ĐỒ
   ============================================================ */
#map {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: #0d1117;
}

/* Ẩn attribution Leaflet mặc định (hiển thị ở góc phải dưới) */
.leaflet-control-attribution {
    background: rgba(0,0,0,0.5) !important;
    color: rgba(255,255,255,0.4) !important;
    font-size: 10px !important;
    backdrop-filter: blur(4px);
}
.leaflet-control-attribution a { color: rgba(255,255,255,0.5) !important; }

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    width: 34px !important;
    height: 34px !important;
    line-height: 32px !important;
    font-size: 18px !important;
    transition: background var(--transition) !important;
}
.leaflet-control-zoom a:hover {
    background: var(--bg-panel-2) !important;
    color: var(--accent) !important;
}

/* ============================================================
   HEADER BAR
   ============================================================ */
#header-bar {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

/* Logo */
#logo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    text-decoration: none;
}
#logo .logo-icon {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
}
#logo .logo-text {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    white-space: nowrap;
}
#logo .logo-sub {
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Search Box */
#search-wrapper {
    flex: 1;
    max-width: 440px;
    position: relative;
}

#search-input {
    width: 100%;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 36px 8px 38px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13.5px;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
#search-input::placeholder { color: var(--text-dim); }
#search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
    position: absolute;
    left: 11px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    font-size: 16px;
    pointer-events: none;
}
#search-clear {
    position: absolute;
    right: 10px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    color: var(--text-dim);
    font-size: 15px;
    display: none;
    padding: 2px;
    transition: color var(--transition);
}
#search-clear:hover { color: var(--text-primary); }
#search-clear.visible { display: block; }

/* Kết quả tìm kiếm */
#search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    display: none;
    z-index: 200;
}
#search-results.active { display: block; }
#search-results::-webkit-scrollbar { width: 4px; }
#search-results::-webkit-scrollbar-track { background: transparent; }
#search-results::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 2px; }

.search-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--bg-panel-2); }

.search-item-icon {
    margin-top: 2px;
    color: var(--accent);
    font-size: 14px;
    flex-shrink: 0;
}
.search-item-body { flex: 1; min-width: 0; }
.search-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-item-addr {
    font-size: 11.5px;
    color: var(--text-secondary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-no-result {
    padding: 16px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}
.search-loading {
    padding: 14px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Region Select */
#region-select {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    cursor: pointer;
    min-width: 200px;
    transition: border-color var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238892a4' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}
#region-select:focus { border-color: var(--accent); }
#region-select option { background: var(--bg-panel); }

/* ============================================================
   PANEL TRÁI — THÔNG TIN THỬA ĐẤT
   ============================================================ */
#info-panel {
    position: absolute;
    bottom: 24px; left: 14px;
    width: 300px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    overflow: hidden;
    transform: translateY(120%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}
#info-panel.visible {
    transform: translateY(0);
    opacity: 1;
}

#info-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}
#info-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
#info-panel-close {
    background: none; border: none; cursor: pointer;
    color: var(--text-dim);
    font-size: 18px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color var(--transition), background var(--transition);
}
#info-panel-close:hover { color: var(--text-primary); background: var(--bg-panel-2); }

#info-panel-body { padding: 14px; }

/* Land type badge */
.land-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 12px;
    letter-spacing: 0.03em;
}
.land-badge-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.9;
}

/* Bảng thông tin */
.info-table {
    width: 100%;
    border-collapse: collapse;
}
.info-table tr { border-bottom: 1px solid var(--border); }
.info-table tr:last-child { border-bottom: none; }
.info-table td {
    padding: 7px 0;
    font-size: 13px;
    vertical-align: top;
}
.info-table td:first-child {
    color: var(--text-secondary);
    white-space: nowrap;
    width: 38%;
    font-size: 12px;
}
.info-table td:last-child {
    color: var(--text-primary);
    font-weight: 500;
    padding-left: 8px;
}

/* Tọa độ */
.coord-row {
    margin-top: 10px;
    padding: 8px 10px;
    background: var(--bg-panel-2);
    border-radius: var(--radius-sm);
    font-size: 11.5px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.land-note {
    margin-top: 10px;
    padding: 8px 10px;
    background: rgba(79,156,249,0.08);
    border-left: 2px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.info-no-data {
    text-align: center;
    padding: 10px 0;
    color: var(--text-secondary);
    font-size: 13px;
}
.info-no-data .coord-info {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

/* Loading spinner */
.info-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}
.spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   PANEL PHẢI — ĐIỀU KHIỂN LỚP BẢN ĐỒ
   ============================================================ */
#layer-panel {
    position: absolute;
    top: 70px; right: 14px;
    width: 210px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    z-index: 100;
    overflow: hidden;
}

.panel-section {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: none; }

.panel-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
}

/* Toggle switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.toggle-row:last-child { margin-bottom: 0; }
.toggle-label {
    font-size: 12.5px;
    color: var(--text-secondary);
}

.toggle-switch {
    position: relative;
    width: 32px; height: 18px;
    cursor: pointer;
}
.toggle-switch input { display: none; }
.toggle-track {
    position: absolute; inset: 0;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    transition: background var(--transition), border-color var(--transition);
}
.toggle-thumb {
    position: absolute;
    top: 2px; left: 2px;
    width: 12px; height: 12px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: transform var(--transition), background var(--transition);
}
.toggle-switch input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-switch input:checked ~ .toggle-thumb { transform: translateX(14px); background: #fff; }

/* Opacity slider */
#opacity-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
#opacity-slider {
    flex: 1;
    appearance: none;
    height: 4px;
    background: var(--bg-panel-2);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
#opacity-slider::-webkit-slider-thumb {
    appearance: none;
    width: 14px; height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 3px var(--accent-glow);
}
#opacity-value {
    font-size: 11px;
    color: var(--text-secondary);
    width: 28px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ============================================================
   NÚT ĐIỀU KHIỂN GÓC
   ============================================================ */
#fab-buttons {
    position: absolute;
    bottom: 80px; right: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.fab {
    width: 40px; height: 40px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 18px;
    transition: all var(--transition);
    box-shadow: var(--shadow);
    text-decoration: none;
}
.fab:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-panel);
}
.fab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Tooltip cho FAB */
.fab[title] { position: relative; }

/* ============================================================
   LEGEND BẢN ĐỒ
   ============================================================ */
#legend {
    position: absolute;
    bottom: 24px; right: 14px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    z-index: 100;
    min-width: 160px;
    box-shadow: var(--shadow);
}
#legend-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 5px;
    font-size: 11.5px;
    color: var(--text-secondary);
}
.legend-item:last-child { margin-bottom: 0; }
.legend-dot {
    width: 12px; height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ============================================================
   TỜ THỬA SEARCH FORM
   ============================================================ */
#parcel-form {
    position: absolute;
    top: 70px; left: 14px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    z-index: 100;
    width: 220px;
    box-shadow: var(--shadow);
    display: none;
}
#parcel-form.visible { display: block; }
#parcel-form h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

.form-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}
.form-field {
    flex: 1;
}
.form-field label {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
}
.form-field input {
    width: 100%;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 9px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}
.form-field input:focus { border-color: var(--accent); }

.btn-primary {
    width: 100%;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px;
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }

/* ============================================================
   TOAST THÔNG BÁO
   ============================================================ */
#toast-container {
    position: absolute;
    bottom: 24px; left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    animation: toast-in 0.3s ease forwards;
    white-space: nowrap;
}
.toast.error   { border-color: var(--danger);  color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   CROSSHAIR KHI HOVER BẢN ĐỒ
   ============================================================ */
#map.cursor-crosshair { cursor: crosshair !important; }

/* Leaflet popup tùy chỉnh */
.leaflet-popup-content-wrapper {
    background: var(--bg-panel) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow) !important;
    color: var(--text-primary) !important;
}
.leaflet-popup-tip { background: var(--bg-panel) !important; }
.leaflet-popup-content { margin: 10px 14px !important; font-size: 13px; }
.leaflet-popup-close-button { color: var(--text-secondary) !important; }

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */
@media (max-width: 600px) {
    #header-bar { padding: 8px 10px; gap: 8px; }
    #logo .logo-text { display: none; }
    #region-select { min-width: 140px; font-size: 12px; }
    #search-input { font-size: 13px; }

    #layer-panel { display: none; } /* Ẩn trên mobile, dùng FAB */

    #info-panel {
        left: 10px; right: 10px; bottom: 70px;
        width: auto;
    }

    #legend { display: none; }
    #fab-buttons { bottom: 70px; right: 10px; }

    #parcel-form { left: 10px; right: 10px; width: auto; }
}
