:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --text: #172033;
    --muted: #667085;
    --border: #dfe5ee;
    --primary: #0f4c81;
    --primary-dark: #0a365d;
    --secondary: #e9f1f8;
    --danger: #b42318;
    --success: #067647;
    --warning: #b54708;
    --shadow: 0 10px 30px rgba(30, 50, 80, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; }
code { background: #eef2f6; padding: .15rem .35rem; border-radius: 5px; }

.topbar {
    min-height: 66px;
    background: #0b2942;
    color: white;
    display: flex;
    align-items: center;
    padding: 0 max(20px, calc((100vw - 1500px) / 2));
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 5px 20px rgba(0, 0, 0, .15);
}
.brand { color: white; display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.05rem; }
.brand-mark, .auth-logo {
    display: grid;
    place-items: center;
    background: #36a3e6;
    color: white;
    font-weight: 800;
    letter-spacing: -.04em;
}
.brand-mark { width: 38px; height: 38px; border-radius: 10px; }
.main-nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.main-nav a { color: #dceaf5; padding: 10px 12px; border-radius: 8px; }
.main-nav a:hover { background: rgba(255,255,255,.1); color: white; }
.nav-user { color: #9fc0d8; font-size: .82rem; margin: 0 10px; }
.nav-toggle { display: none; margin-left: auto; border: 0; background: transparent; color: white; font-size: 1.5rem; }

.container { width: min(1500px, calc(100% - 36px)); margin: 30px auto 60px; }
.auth-container { min-height: calc(100vh - 55px); display: grid; place-items: center; padding: 30px 16px; }
.auth-card {
    width: min(440px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 34px;
    box-shadow: var(--shadow);
    text-align: center;
}
.install-card { width: min(650px, 100%); text-align: left; }
.auth-card h1 { margin: 12px 0 4px; }
.auth-card h2 { font-size: 1rem; text-align: left; margin: 14px 0 0; }
.auth-logo { width: 64px; height: 64px; margin: auto; border-radius: 18px; font-size: 1.35rem; }
.install-card .auth-logo { margin: 0 auto; }

.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 22px; }
.page-heading h1 { margin: 5px 0 3px; font-size: clamp(1.55rem, 3vw, 2.2rem); }
.page-heading p { color: var(--muted); margin: 0; }
.card, .form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card { padding: 20px; }
.form-card { padding: 26px; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

label { display: grid; gap: 6px; font-weight: 650; text-align: left; font-size: .92rem; }
label small, .muted, small { color: var(--muted); font-weight: 400; }
input, select, textarea {
    width: 100%;
    border: 1px solid #c9d3df;
    border-radius: 9px;
    background: white;
    padding: 10px 12px;
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: 3px solid rgba(54, 163, 230, .18);
    border-color: #2387c4;
}
textarea { resize: vertical; }
input[type="color"] { min-height: 44px; padding: 4px; }
input[type="checkbox"] { width: auto; }
.check-row { display: flex; align-items: center; gap: 9px; }
.field-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.button-row, .form-actions, .actions-cell { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.form-actions { justify-content: flex-end; margin-top: 24px; }
.button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 9px 14px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-weight: 700;
    line-height: 1.2;
}
.button-primary { background: var(--primary); color: white; }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { background: var(--secondary); color: #17496e; border-color: #c9ddeb; }
.button-light { background: white; color: var(--text); border-color: var(--border); }
.button-danger { background: #fff1f0; color: var(--danger); border-color: #fecdca; }
.button-small { padding: 7px 10px; font-size: .82rem; }
.button-block { width: 100%; }
.link-button { border: 0; background: transparent; color: var(--primary); cursor: pointer; padding: 0; }

.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 18px; border: 1px solid; }
.alert-success { background: #ecfdf3; color: #05603a; border-color: #abefc6; }
.alert-danger { background: #fef3f2; color: #912018; border-color: #fecdca; }
.alert-warning { background: #fffaeb; color: #93370d; border-color: #fedf89; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 17px; }
.stat-card strong { display: block; font-size: 1.65rem; color: var(--primary); }
.stat-card span { color: var(--muted); font-size: .88rem; }

.map-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 18px; }
.map-sidebar { padding: 16px; }
.sidebar-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sidebar-title h2 { font-size: 1rem; margin: 0; }
.filter-list { display: grid; gap: 5px; }
.filter-item {
    grid-template-columns: auto 30px 1fr auto;
    display: grid;
    align-items: center;
    gap: 8px;
    font-weight: 560;
    padding: 8px 4px;
    border-bottom: 1px solid #eef1f5;
}
.filter-item small { font-variant-numeric: tabular-nums; }
.legend-pin {
    width: 28px;
    height: 28px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    background: var(--pin-color);
    display: inline-grid;
    place-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,.2);
    color: white;
    flex: 0 0 auto;
}
.legend-pin > * { transform: rotate(45deg); }
.filter-item .legend-pin { font-size: 13px; line-height: 1; overflow: hidden; }
.notice-link { display: block; margin-top: 14px; padding: 10px; background: #fff8e6; border-radius: 8px; color: var(--warning); font-weight: 650; font-size: .86rem; }

.map-card { min-height: 650px; position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: white; box-shadow: var(--shadow); }
#map { height: 650px; width: 100%; }
.map-loading { position: absolute; z-index: 500; top: 12px; left: 50%; transform: translateX(-50%); padding: 8px 13px; background: white; border-radius: 20px; box-shadow: var(--shadow); font-size: .86rem; }
.map-loading.error { color: var(--danger); }
.custom-pin-wrap { background: transparent; border: 0; }
.map-pin {
    width: 36px;
    height: 36px;
    background: var(--pin-color);
    border: 3px solid white;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: grid;
    place-items: center;
    box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.map-pin span { transform: rotate(45deg); font-size: 17px; line-height: 1; }
.map-popup { display: grid; gap: 10px; }
.map-popup img { width: 260px; height: 135px; object-fit: cover; border-radius: 7px; }
.map-popup h3 { margin: 7px 0 0; font-size: 1rem; }
.map-popup p { margin: 3px 0 8px; color: var(--muted); }

.type-badge {
    --badge-color: #64748b;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    background: color-mix(in srgb, var(--badge-color) 13%, white);
    color: color-mix(in srgb, var(--badge-color) 75%, black);
    border: 1px solid color-mix(in srgb, var(--badge-color) 30%, white);
    font-size: .77rem;
    font-weight: 750;
}

.picker-map { height: 430px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.form-grid { align-items: start; }
.edit-preview { width: 100%; height: 260px; object-fit: contain; background: #eef2f6; border-radius: 10px; }

.filter-bar { display: grid; grid-template-columns: 2fr 1fr 1fr auto auto; align-items: end; gap: 12px; margin-bottom: 18px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 17px; }
.photo-card { background: white; color: var(--text); border: 1px solid var(--border); border-radius: 13px; overflow: hidden; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
.photo-card:hover { transform: translateY(-2px); box-shadow: 0 14px 36px rgba(30,50,80,.13); }
.photo-image { position: relative; aspect-ratio: 4 / 3; background: #e9edf2; }
.photo-image img { width: 100%; height: 100%; object-fit: cover; }
.missing-location { position: absolute; top: 9px; right: 9px; background: #fff0d5; color: #8a3e00; border-radius: 999px; padding: 4px 8px; font-size: .73rem; font-weight: 750; }
.photo-body { padding: 15px; }
.photo-body h2 { margin: 10px 0 4px; font-size: 1.03rem; }
.photo-body p { color: var(--muted); margin: 0 0 5px; font-size: .87rem; }
.empty-state { text-align: center; padding: 50px 20px; display: grid; gap: 5px; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 18px; }
.detail-photo { display: grid; place-items: center; min-height: 440px; background: #161d27; padding: 0; overflow: hidden; }
.detail-photo img { width: 100%; max-height: 75vh; object-fit: contain; }
.detail-info h2 { font-size: 1rem; margin: 0 0 12px; }
.detail-info h2:not(:first-child) { margin-top: 22px; }
.detail-info dl { margin: 0; display: grid; grid-template-columns: 145px 1fr; gap: 9px 14px; }
.detail-info dt { color: var(--muted); }
.detail-info dd { margin: 0; font-weight: 600; }
.preserve-lines { white-space: pre-wrap; }
.text-warning { color: var(--warning); }
.map-detail-card { margin-top: 18px; padding: 0; overflow: hidden; }
#detail-map { height: 400px; }

.admin-layout { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 18px; align-items: start; }
.card h2 { margin-top: 0; }
.table-card { padding: 0; overflow: hidden; }
.table-card > h2 { padding: 20px 20px 0; }
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 15px; border-top: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.actions-cell { justify-content: flex-end; }
.status { display: inline-flex; padding: 3px 8px; border-radius: 999px; font-size: .76rem; font-weight: 750; }
.status.active { background: #dcfae6; color: #087443; }
.status.inactive { background: #f2f4f7; color: #667085; }

.footer { min-height: 55px; display: flex; justify-content: center; gap: 25px; align-items: center; color: var(--muted); font-size: .8rem; padding: 12px; }

@media (max-width: 980px) {
    .nav-toggle { display: block; }
    .main-nav {
        display: none;
        position: absolute;
        top: 66px;
        left: 0;
        right: 0;
        background: #0b2942;
        padding: 10px 18px 18px;
        flex-direction: column;
        align-items: stretch;
    }
    .main-nav.open { display: flex; }
    .nav-user { margin: 8px 12px; }
    .map-layout, .admin-layout, .detail-grid { grid-template-columns: 1fr; }
    .map-sidebar { order: 2; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 650px) {
    .container { width: min(100% - 20px, 1500px); margin-top: 18px; }
    .page-heading { align-items: stretch; flex-direction: column; }
    .grid-2, .filter-bar { grid-template-columns: 1fr; }
    .form-card, .auth-card { padding: 20px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    #map, .map-card { height: 560px; min-height: 560px; }
    .picker-map { height: 350px; }
    .detail-info dl { grid-template-columns: 1fr; gap: 2px; }
    .detail-info dd { margin-bottom: 9px; }
    .footer { flex-direction: column; gap: 3px; }
}
