* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
    color: #1f2937;
    background: #f3f4f6;
}

a {
    color: #1d4ed8;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

#container {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 430px;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

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

#panel {
    height: 100vh;
    overflow-y: auto;
    background: #ffffff;
    border-left: 1px solid #d1d5db;
    padding: 14px;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.08);
    z-index: 2;
}

#panel h2 {
    margin: 0 0 10px;
    font-size: 20px;
    line-height: 1.3;
    color: #0f172a;
}

.user-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 7px 12px;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 12px;
    border: 1px solid #dbeafe;
    border-radius: 10px;
    background: #eff6ff;
    font-size: 13px;
}

.legend-toggle-btn {
    position: absolute;
    left: 12px;
    bottom: 16px;
    z-index: 900;
    border: 0;
    border-radius: 999px;
    padding: 9px 14px;
    color: #ffffff;
    background: #1d4ed8;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

.custom-legend-panel {
    position: absolute;
    left: 12px;
    bottom: 58px;
    z-index: 900;
    width: 270px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.18);
}

.legend-hidden {
    display: none;
}

.legend-section {
    margin-bottom: 12px;
}

.legend-title {
    font-weight: 700;
    margin-bottom: 6px;
    color: #111827;
}

.legend-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    cursor: pointer;
    font-size: 14px;
}

.legend-symbol {
    display: inline-block;
    width: 18px;
    height: 12px;
    border: 2px solid #2563eb;
    background: rgba(96, 165, 250, 0.35);
    border-radius: 3px;
}

.toolbox-area {
    margin-bottom: 12px;
}

.toolbox-details {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #f9fafb;
    margin-bottom: 8px;
}

.toolbox-details summary {
    padding: 10px;
    font-weight: 700;
    cursor: pointer;
}

.toolbox-content {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 10px 10px;
}

.btn-action,
.btn-primary,
.btn-secondary,
.btn-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 9px;
    padding: 8px 11px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
}

.btn-primary {
    background: #1d4ed8;
    color: #ffffff;
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}

.btn-small {
    padding: 5px 9px;
    font-size: 13px;
    background: #e0f2fe;
    color: #075985;
}

.full {
    width: 100%;
}

.tab-buttons {
    display: flex;
    gap: 6px;
    margin: 12px 0;
}

.tab-button {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 9px;
    padding: 8px 6px;
    background: #f9fafb;
    cursor: pointer;
    font-weight: 600;
}

.tab-button.active {
    background: #1d4ed8;
    color: #ffffff;
    border-color: #1d4ed8;
}

.tab-content {
    display: none;
}

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

.card,
.panel-card {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px;
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
    margin-bottom: 12px;
}

.card h3,
.panel-card h2 {
    margin: 0 0 10px;
}

.layer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #f1f5f9;
    padding: 8px 0;
}

.layer-row:last-child {
    border-bottom: 0;
}

.layer-meta {
    color: #6b7280;
    font-size: 12px;
}

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #dbeafe, #f8fafc);
}

.auth-card {
    width: 100%;
    max-width: 430px;
    background: #ffffff;
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.16);
}

.auth-card h1 {
    margin: 0 0 6px;
    color: #0f172a;
}

.muted {
    color: #64748b;
}

label {
    display: block;
    margin: 10px 0 5px;
    font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    padding: 9px 10px;
    font: inherit;
    background: #ffffff;
}

textarea {
    resize: vertical;
}

.auth-links {
    margin-top: 14px;
    text-align: center;
}

.demo-account {
    margin-top: 14px;
    padding: 10px;
    border-radius: 10px;
    background: #f8fafc;
    color: #475569;
    font-size: 13px;
}

.alert {
    padding: 10px 12px;
    border-radius: 10px;
    margin: 10px 0;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.admin-page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px;
}

.topline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.topline h1 {
    margin: 0 0 10px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.admin-table th,
.admin-table td {
    border-bottom: 1px solid #e5e7eb;
    padding: 8px;
    text-align: left;
    vertical-align: top;
}

.admin-table th {
    background: #f8fafc;
}

.center {
    text-align: center;
}

.grid-form {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 10px 12px;
}

.grid-form h2,
.grid-form .form-actions,
.grid-form .alert {
    grid-column: 1 / -1;
}

.inline-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.small-card {
    max-width: 520px;
}

.leaflet-popup-content table {
    border-collapse: collapse;
    width: 100%;
}

.leaflet-popup-content td {
    border-bottom: 1px solid #e5e7eb;
    padding: 4px;
}

@media (max-width: 900px) {
    #container {
        grid-template-columns: 1fr;
        grid-template-rows: 55vh 45vh;
    }

    #map {
        height: 55vh;
    }

    #panel {
        height: 45vh;
        border-left: 0;
        border-top: 1px solid #d1d5db;
    }

    .legend-toggle-btn {
        bottom: calc(45vh + 12px);
    }

    .custom-legend-panel {
        width: calc(100vw - 24px);
        bottom: calc(45vh + 54px);
        max-height: 45vh;
    }

    .grid-form {
        grid-template-columns: 1fr;
    }
}

.btn-danger {
    background: #dc2626;
    color: #ffffff;
}

.hidden {
    display: none !important;
}

.feature-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #e5e7eb;
}

.note-box,
.form-help {
    grid-column: 1 / -1;
    padding: 9px 10px;
    border: 1px solid #dbeafe;
    border-radius: 10px;
    background: #eff6ff;
    color: #1e3a8a;
    font-size: 13px;
    line-height: 1.5;
}

.layer-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}

.layer-badge.editable {
    color: #166534;
    background: #dcfce7;
    border: 1px solid #bbf7d0;
}

.layer-badge.static {
    color: #92400e;
    background: #fef3c7;
    border: 1px solid #fde68a;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.45);
}

.modal-card {
    width: min(720px, calc(100vw - 32px));
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.35);
    padding: 16px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 10px;
}

.modal-header h3 {
    margin: 0;
    color: #0f172a;
}

.modal-close {
    border: 0;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #111827;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.modal-card .grid-form {
    grid-template-columns: 170px minmax(0, 1fr);
}

#featureProperties {
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 13px;
}

@media (max-width: 900px) {
    .modal-card .grid-form {
        grid-template-columns: 1fr;
    }
}


/* ============================================================
   V5 MOBILE RESPONSIVE
   Tối ưu WebGIS cho điện thoại/tablet: bản đồ lớn hơn,
   panel dưới gọn hơn, nút công cụ/chú giải phù hợp cảm ứng.
   ============================================================ */
@media (max-width: 900px) {
    :root {
        --mobile-map-height: 68dvh;
        --mobile-panel-height: 32dvh;
    }

    html,
    body {
        height: auto;
        min-height: 100%;
        overflow-x: hidden;
        background: #ffffff;
    }

    #container {
        display: block;
        width: 100%;
        min-height: 100dvh;
        height: auto;
        overflow: visible;
        position: relative;
        background: #ffffff;
    }

    #map {
        height: var(--mobile-map-height);
        min-height: 430px;
        max-height: 720px;
        width: 100%;
    }

    #panel {
        height: auto;
        min-height: var(--mobile-panel-height);
        max-height: none;
        overflow: visible;
        border-left: 0;
        border-top: 1px solid #e5e7eb;
        border-radius: 20px 20px 0 0;
        padding: 14px 14px 28px;
        box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.12);
        position: relative;
        z-index: 20;
    }

    #panel h2 {
        font-size: 21px;
        line-height: 1.25;
        margin-bottom: 8px;
    }

    .user-bar {
        font-size: 13px;
        gap: 6px 10px;
        padding: 9px 10px;
        margin-bottom: 10px;
        border-radius: 12px;
    }

    .user-bar a {
        display: inline-flex;
        align-items: center;
        min-height: 28px;
    }

    .toolbox-details {
        border-radius: 14px;
        margin-bottom: 10px;
    }

    .toolbox-details summary {
        min-height: 46px;
        padding: 12px 14px;
        font-size: 16px;
    }

    .toolbox-content {
        gap: 9px;
        padding: 0 12px 12px;
    }

    .toolbox-content .btn-action,
    .toolbox-content .btn-primary,
    .toolbox-content .btn-secondary {
        flex: 1 1 calc(50% - 9px);
        min-height: 42px;
        padding: 10px 12px;
        font-size: 14px;
        border-radius: 12px;
        white-space: normal;
        text-align: center;
    }

    .tab-buttons {
        gap: 8px;
        margin: 12px 0;
    }

    .tab-button {
        min-height: 42px;
        padding: 9px 6px;
        font-size: 14px;
        border-radius: 12px;
    }

    .card,
    .panel-card {
        border-radius: 15px;
        padding: 13px;
        font-size: 15px;
    }

    .card h3,
    .panel-card h2 {
        font-size: 20px;
        line-height: 1.25;
    }

    .legend-toggle-btn {
        position: fixed;
        left: 14px;
        bottom: calc(var(--mobile-panel-height) + 14px);
        z-index: 1200;
        border-radius: 999px;
        padding: 11px 18px;
        min-height: 42px;
        font-size: 15px;
        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.26);
    }

    .custom-legend-panel {
        position: fixed;
        left: 12px;
        bottom: calc(var(--mobile-panel-height) + 64px);
        width: calc(100vw - 24px);
        max-height: min(46dvh, 380px);
        z-index: 1200;
        border-radius: 16px;
        padding: 12px;
    }

    .legend-option {
        min-height: 34px;
        font-size: 14px;
    }

    .leaflet-top.leaflet-left {
        top: 10px;
        left: 8px;
    }

    .leaflet-control-zoom a {
        width: 40px;
        height: 40px;
        line-height: 40px;
        font-size: 24px;
    }

    .leaflet-draw-toolbar a {
        width: 40px !important;
        height: 40px !important;
        line-height: 40px !important;
    }

    .leaflet-control-attribution {
        font-size: 10px;
    }

    .feature-actions {
        gap: 9px;
    }

    .feature-actions .btn-action {
        flex: 1 1 calc(50% - 9px);
        min-height: 42px;
        border-radius: 12px;
    }

    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        min-height: 42px;
        font-size: 16px;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-card {
        width: 100%;
        max-height: 86dvh;
        border-radius: 20px 20px 0 0;
        padding: 14px;
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: #ffffff;
        z-index: 1;
    }

    .admin-page {
        padding: 12px;
    }

    .topline {
        align-items: flex-start;
        flex-direction: column;
    }

    .table-wrap {
        border: 1px solid #e5e7eb;
        border-radius: 12px;
    }
}

@media (max-width: 480px) {
    :root {
        --mobile-map-height: 68dvh;
        --mobile-panel-height: 32dvh;
    }

    #map {
        min-height: 410px;
    }

    #panel h2 {
        font-size: 20px;
    }

    .toolbox-content .btn-action,
    .toolbox-content .btn-primary,
    .toolbox-content .btn-secondary {
        flex-basis: calc(50% - 9px);
        font-size: 13.5px;
    }

    .tab-button {
        font-size: 13.5px;
    }

    .card h3,
    .panel-card h2 {
        font-size: 19px;
    }
}

@media (max-width: 900px) and (orientation: landscape) {
    :root {
        --mobile-map-height: 72dvh;
        --mobile-panel-height: 28dvh;
    }

    #map {
        min-height: 330px;
    }
}

/* ============================================================
   V5.1 MOBILE COMPACT
   Thu gọn tiêu đề/tài khoản, tăng diện tích bản đồ và thêm
   chế độ xem bản đồ toàn màn hình trên điện thoại.
   ============================================================ */
.user-bar-main,
.user-bar-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px 12px;
}

.user-bar-links {
    display: contents;
}

.account-menu-toggle,
.map-fullscreen-btn {
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
}

.account-menu-toggle {
    display: none;
    padding: 6px 10px;
    color: #ffffff;
    background: #1d4ed8;
}

.map-fullscreen-btn {
    display: none;
}

@media (max-width: 900px) {
    :root {
        --mobile-map-height: 74dvh;
        --mobile-panel-height: 26dvh;
    }

    #map {
        height: var(--mobile-map-height);
        min-height: 480px;
    }

    #panel {
        min-height: var(--mobile-panel-height);
        padding-top: 12px;
    }

    .app-title-main {
        display: none;
    }

    .user-bar {
        display: block;
        padding: 8px 10px;
        margin-bottom: 10px;
    }

    .user-bar-main {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    .user-summary {
        white-space: nowrap;
        font-size: 13px;
    }

    .account-menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 32px;
        padding: 6px 12px;
        font-weight: 700;
    }

    .user-bar-links {
        display: none;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 9px;
        padding-top: 9px;
        border-top: 1px solid #dbeafe;
    }

    .user-bar.account-menu-open .user-bar-links {
        display: grid;
    }

    .user-bar-links a {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 36px;
        padding: 8px 9px;
        border-radius: 10px;
        background: #ffffff;
        border: 1px solid #bfdbfe;
        text-align: center;
        font-size: 13px;
        line-height: 1.25;
    }

    .toolbox-details summary {
        display: flex;
        align-items: center;
        width: 100%;
        user-select: none;
    }

    .map-fullscreen-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        right: 14px;
        bottom: calc(var(--mobile-panel-height) + 14px);
        z-index: 1200;
        min-height: 42px;
        padding: 11px 16px;
        color: #ffffff;
        background: #0f766e;
        font-size: 15px;
        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.26);
    }

    .tab-buttons {
        position: sticky;
        top: 0;
        z-index: 25;
        background: #ffffff;
        padding-top: 2px;
        padding-bottom: 2px;
    }

    body.map-fullscreen-mobile {
        overflow: hidden;
        height: 100dvh;
    }

    body.map-fullscreen-mobile #container {
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
    }

    body.map-fullscreen-mobile #map {
        height: 100dvh;
        min-height: 100dvh;
        max-height: none;
    }

    body.map-fullscreen-mobile #panel {
        display: none;
    }

    body.map-fullscreen-mobile .legend-toggle-btn {
        bottom: 16px;
    }

    body.map-fullscreen-mobile .map-fullscreen-btn {
        bottom: 16px;
        background: #dc2626;
    }

    body.map-fullscreen-mobile .custom-legend-panel {
        bottom: 66px;
        max-height: min(68dvh, 520px);
    }
}

@media (max-width: 480px) {
    :root {
        --mobile-map-height: 74dvh;
        --mobile-panel-height: 26dvh;
    }

    #map {
        min-height: 465px;
    }

    .user-bar-main {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .account-menu-toggle {
        margin-left: auto;
    }

    .user-bar-links {
        grid-template-columns: 1fr;
    }

    .map-fullscreen-btn {
        padding-left: 14px;
        padding-right: 14px;
        font-size: 14px;
    }
}

@media (max-width: 900px) and (orientation: landscape) {
    :root {
        --mobile-map-height: 78dvh;
        --mobile-panel-height: 22dvh;
    }

    #map {
        min-height: 340px;
    }
}

/* v6 - hỗ trợ hiển thị trạng thái xác minh email trong bảng quản trị */
.small-text {
    font-size: 12px;
    line-height: 1.3;
}

/* ============================================================
   V7 - Tìm kiếm, trường thuộc tính động, tệp đính kèm, xuất dữ liệu
   ============================================================ */
.search-card {
    margin: 0 0 12px;
    padding: 10px;
    border: 1px solid #dbeafe;
    border-radius: 12px;
    background: #f8fbff;
}

.search-title {
    font-weight: 700;
    margin-bottom: 7px;
    color: #0f172a;
}

.search-row {
    display: flex;
    gap: 7px;
}

.search-row input {
    flex: 1;
    min-width: 0;
}

.search-results {
    margin-top: 8px;
    display: grid;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
}

.search-result-item {
    display: block;
    width: 100%;
    padding: 8px 9px;
    text-align: left;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    background: #ffffff;
    cursor: pointer;
}

.search-result-item:hover {
    background: #eff6ff;
}

.search-result-item b,
.search-result-item span,
.search-result-item small {
    display: block;
}

.search-result-item span {
    color: #1d4ed8;
    font-size: 12.5px;
    margin-top: 2px;
}

.search-result-item small {
    color: #64748b;
    margin-top: 3px;
    line-height: 1.35;
}

.layer-actions-mini {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
    font-size: 12px;
}

.layer-actions-mini a {
    padding: 3px 6px;
    border-radius: 6px;
    background: #e0f2fe;
}

.form-section-title {
    grid-column: 1 / -1;
    font-weight: 700;
    padding: 8px 0 2px;
    color: #0f172a;
}

.dynamic-fields-wrapper {
    grid-column: 1 / -1;
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px dashed #93c5fd;
    border-radius: 12px;
    background: #f8fbff;
}

.dynamic-fields-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px 12px;
}

.dynamic-field-item {
    display: grid;
    gap: 5px;
}

.dynamic-field-label {
    font-weight: 700;
    color: #334155;
}

.feature-files-section {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #e5e7eb;
}

.feature-files-section h4 {
    margin: 0 0 8px;
    font-size: 15px;
    color: #0f172a;
}

.feature-files-list {
    display: grid;
    gap: 8px;
    margin-bottom: 10px;
}

.file-item {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #ffffff;
}

.file-thumb {
    width: 58px;
    height: 44px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.file-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 44px;
    border-radius: 8px;
    background: #eff6ff;
    font-size: 24px;
}

.file-info {
    min-width: 0;
    overflow-wrap: anywhere;
}

.feature-upload-form {
    display: grid;
    gap: 7px;
    padding: 8px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.inline-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.danger-link {
    background: #fee2e2 !important;
    color: #991b1b !important;
}

@media (max-width: 900px) {
    .search-card {
        padding: 9px;
    }

    .search-row {
        flex-direction: column;
    }

    .search-results {
        max-height: 180px;
    }

    .dynamic-fields-box {
        grid-template-columns: 1fr;
    }

    .file-item {
        grid-template-columns: 52px minmax(0, 1fr);
    }

    .file-item .btn-small {
        grid-column: 1 / -1;
        justify-self: start;
    }
}
