:root {
    --bg: #f3f6fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #687489;
    --line: #d9e0ea;
    --primary: #1769e0;
    --primary-dark: #0d4eb0;
    --danger: #d93838;
    --danger-bg: #fff1f1;
    --shadow: 0 10px 30px rgba(18, 32, 56, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

.page-wrap {
    width: min(100%, 2560px);
    min-height: 100vh;
    margin: 0 auto;
    padding: clamp(14px, 1.2vw, 30px);
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: stretch;
    margin-bottom: 18px;
}
.topbar h1 { margin: 0; font-size: clamp(24px, 1.55vw, 42px); letter-spacing: -.02em; }
.topbar p { margin: 6px 0 0; color: var(--muted); font-size: clamp(13px, .8vw, 18px); }
.summary-card {
    min-width: 180px;
    padding: 18px 22px;
    border-radius: var(--radius);
    background: linear-gradient(145deg, #ffffff, #e9f1ff);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: right;
}
.summary-card span { color: var(--muted); font-size: 13px; }
.summary-card strong { font-size: clamp(26px, 1.6vw, 44px); line-height: 1.05; }

.filter-panel,
.table-card,
.toolbar {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.filter-panel { padding: 16px; margin-bottom: 14px; }
.filter-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(130px, 1fr));
    gap: 12px;
    align-items: end;
}
.filter-grid label { display: flex; flex-direction: column; gap: 6px; }
.filter-grid span { font-size: 13px; font-weight: 700; color: #3c4658; }
input, select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 12px;
    background: #fff;
    color: var(--text);
    font-size: 14px;
}
input:focus, select:focus { outline: 2px solid rgba(23,105,224,.18); border-color: var(--primary); }
.filter-actions { display: flex; gap: 8px; }

.btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { background: #f7f9fc; color: #344154; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { background: var(--danger-bg); border-color: #ffc9c9; color: var(--danger); }
.btn.small { min-height: 30px; padding: 0 9px; font-size: 12px; }

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 14px;
}
.range-info { color: var(--muted); font-weight: 700; }
.auto-refresh-info {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    margin-right: auto;
}
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.table-card { overflow: hidden; }
.table-scroll {
    overflow: auto;
    max-height: calc(100vh - 330px);
    min-height: 420px;
}
.data-table {
    width: 100%;
    min-width: 1780px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: clamp(12px, .68vw, 15px);
}
.data-table th,
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    border-right: 1px solid #eef2f7;
    vertical-align: middle;
    white-space: nowrap;
}
.data-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #eef4ff;
    color: #26344d;
    text-align: left;
    font-weight: 800;
}
.data-table tbody tr:hover { background: #f9fbff; }
.check-col { width: 42px; text-align: center !important; }
.empty { text-align: center; color: var(--muted); padding: 50px !important; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.strong { font-weight: 800; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.gps-cell {
    white-space: nowrap;
    width: 220px;
    min-width: 220px;
    max-width: 220px;
}
.gps-cell .map-btn {
    vertical-align: middle;
}
.gps-cell .coord {
    display: inline-block;
    vertical-align: middle;
    margin-left: 6px;
    max-width: 154px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.coord { color: var(--muted); font-size: 11px; }
.map-btn {
    border: 1px solid #b7cdf6;
    background: #e9f1ff;
    color: #1752aa;
    border-radius: 999px;
    min-height: 28px;
    padding: 0 10px;
    font-weight: 800;
    cursor: pointer;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    margin: 18px 0 6px;
}
.page-link {
    min-width: 38px;
    min-height: 38px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    text-decoration: none;
    font-weight: 800;
}
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-link.disabled { opacity: .4; pointer-events: none; }

.modal { display: none; position: fixed; inset: 0; z-index: 1000; }
.modal.show { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(9, 16, 30, .58); }
.modal-panel {
    position: absolute;
    inset: clamp(16px, 4vh, 60px) clamp(16px, 6vw, 90px);
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 22px 70px rgba(0,0,0,.35);
}
.modal-head,
.modal-foot {
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--line);
}
.modal-foot { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-head p { margin: 3px 0 0; color: var(--muted); }
.modal-close {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    font-size: 28px;
    background: #f1f4f9;
    cursor: pointer;
}
.map-canvas { flex: 1; min-height: 420px; background: #e8edf5; }
.map-fallback {
    height: 100%;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 24px;
    color: var(--muted);
}

@media (min-width: 2500px) {
    .page-wrap { max-width: 3840px; }
    .filter-grid { grid-template-columns: repeat(9, minmax(160px, 1fr)); }
    .table-scroll { max-height: calc(100vh - 350px); }
    .data-table { min-width: 2150px; }
}

@media (max-width: 1300px) {
    .filter-grid { grid-template-columns: repeat(4, minmax(140px, 1fr)); }
    .topbar { flex-direction: column; }
    .summary-card { text-align: left; }
}

@media (max-width: 720px) {
    .page-wrap { padding: 10px; }
    .filter-grid { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .auto-refresh-info { margin-right: 0; }
    .toolbar-actions { justify-content: stretch; }
    .toolbar-actions .btn { flex: 1; }
    .modal-panel { inset: 10px; }
}
