/* Simple, modern UI — no frameworks */
:root{
  --bg:#0b1220;
  --text:#e8eefc;
  --muted:#a8b3cc;
  --line:rgba(255,255,255,.10);

  --blue:#3b82f6;
  --green:#22c55e;
  --yellow:#eab308;
  --orange:#f97316;
  --red:#ef4444;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Helvetica Neue", Arial, "Apple Color Emoji","Segoe UI Emoji";
  background: radial-gradient(1200px 600px at 10% 0%, #16244a 0%, var(--bg) 55%) fixed;
  color:var(--text);
}

.container{max-width:1100px;margin:0 auto;padding:18px}
.header{border-bottom:1px solid var(--line);background:linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,0));}
.title-row{display:flex;gap:16px;align-items:flex-start;justify-content:space-between;flex-wrap:wrap}
.brand{display:flex;gap:12px;align-items:flex-start;min-width:0}
.brand-logo{
  width:46px;height:46px;object-fit:contain;
  border-radius:14px;
  background:rgba(255,255,255,.08);
  border:1px solid var(--line);
  padding:6px;
}
h1{font-size:28px;margin:0 0 6px 0;letter-spacing:.2px}
.subtitle{margin:0;color:var(--muted);font-size:14px;line-height:1.35}
.actions{display:flex;gap:12px;align-items:center}
.btn{
  background:rgba(255,255,255,.08);
  border:1px solid var(--line);
  color:var(--text);
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:700;
}
.btn:hover{background:rgba(255,255,255,.12)}
.toggle{display:flex;gap:8px;align-items:center;color:var(--muted);font-size:14px;user-select:none}
.toggle input{transform:scale(1.05)}
.status{
  margin-top:12px;
  padding:10px 12px;
  background:rgba(0,0,0,.18);
  border:1px solid var(--line);
  border-radius:14px;
  color:var(--muted);
  font-size:14px;
}

/* ===== Location panel (top) ===== */
.loc-panel{
  margin-top:14px;
  display:grid;
  grid-template-columns: 1.2fr .8fr;
  gap:14px;
  background:rgba(255,255,255,.06);
  border:1px solid var(--line);
  border-radius:20px;
  padding:14px;
}
@media (max-width: 900px){.loc-panel{grid-template-columns:1fr}}
.loc-left{min-width:0}
.loc-title{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.loc-input{
  width:100%;
  max-width:520px;
  background:transparent;
  border:0;
  outline:none;
  color:var(--text);
  font-size:30px;
  font-weight:900;
  letter-spacing:.2px;
  padding:0;
}
.loc-input:focus{
  box-shadow:0 0 0 2px rgba(59,130,246,.35);
  border-radius:10px;
  padding:4px 8px;
  margin-left:-8px;
}
.loc-sub{margin-top:6px;color:rgba(232,238,252,.88);font-size:22px;font-weight:800}
.loc-meta{margin-top:8px;color:var(--muted);font-size:14px;line-height:1.35}

.loc-right{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  justify-content:center;
  gap:10px;
  padding-left:10px;
}
@media (max-width: 900px){.loc-right{align-items:flex-start;padding-left:0}}
.loc-chip{
  font-weight:900;
  font-size:14px;
  padding:8px 12px;
  border-radius:999px;
  background:rgba(234,179,8,.22);
  border:1px solid rgba(234,179,8,.25);
}
.loc-value-row{display:flex;align-items:baseline;gap:10px}
.loc-value{
  font-size:78px;
  font-weight:1000;
  line-height:1;
  letter-spacing:1px;
}
@media (max-width: 560px){.loc-value{font-size:64px}}
.loc-unit{font-size:18px;color:rgba(232,238,252,.9);font-weight:800}
.loc-badge{
  display:inline-flex;align-items:center;gap:8px;
  padding:8px 12px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(0,0,0,.14);
  font-weight:900;
  font-size:14px;
}
.loc-badge .dot{width:9px;height:9px;border-radius:999px;background:currentColor}

/* ===== Rank panel ===== */
.rank-panel{margin-top:16px}
.rank-head{display:flex;align-items:flex-end;justify-content:space-between;gap:12px;flex-wrap:wrap}
.rank-note{
  margin:10px 0 10px 0;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--line);
  background:rgba(0,0,0,.16);
  color:rgba(232,238,252,.92);
  font-weight:800;
}
.rank-table tbody tr.khonkaen{
  outline:2px solid rgba(59,130,246,.35);
  outline-offset:-2px;
  background:rgba(59,130,246,.08);
}

/* ===== main layout ===== */
.main{display:grid;grid-template-columns: 1fr 1.6fr;gap:16px}
@media (max-width: 900px){.main{grid-template-columns:1fr}}

.panel{
  background:linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  border:1px solid var(--line);
  border-radius:18px;
  padding:14px;
}

h2{margin:0 0 10px 0;font-size:16px;letter-spacing:.2px}
.small{font-size:12px}
.muted{color:var(--muted)}
.mono{font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;}

.controls{display:flex;gap:10px;flex-wrap:wrap}
.input,.select{
  background:rgba(0,0,0,.18);
  border:1px solid var(--line);
  color:var(--text);
  padding:10px 12px;
  border-radius:12px;
  outline:none;
  min-width:220px;
}
.input::placeholder{color:rgba(232,238,252,.45)}
.select{min-width:280px}

.district-card{
  margin-top:12px;
  padding:12px;
  border-radius:16px;
  border:1px solid var(--line);
  background:rgba(0,0,0,.16);
}
.hidden{display:none}
.card-top{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
.d-name{font-weight:900;font-size:16px}
.badge{
  display:inline-flex;align-items:center;gap:8px;
  padding:7px 10px;border-radius:999px;
  font-weight:900;font-size:12px;
  border:1px solid rgba(255,255,255,.12);
}
.badge .dot{width:8px;height:8px;border-radius:999px;background:currentColor}
.metrics{margin-top:10px;display:grid;grid-template-columns:1fr 1fr;gap:10px}
.metric{
  border:1px solid var(--line);
  background:rgba(255,255,255,.04);
  border-radius:14px;
  padding:10px;
}
.metric .label{font-size:12px;color:var(--muted)}
.metric .value{font-size:20px;font-weight:1000;margin-top:2px}
.metric .unit{font-size:12px;color:var(--muted);margin-left:6px;font-weight:800}

.table-head{display:flex;align-items:flex-end;justify-content:space-between;gap:10px;flex-wrap:wrap}
.table-wrap{overflow:auto;border-radius:14px;border:1px solid var(--line)}
.table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  min-width:520px;
}
.table thead th{
  position:sticky;top:0;
  background:rgba(12,18,32,.92);
  backdrop-filter: blur(8px);
  text-align:left;
  font-size:12px;
  color:var(--muted);
  padding:10px 10px;
  border-bottom:1px solid var(--line);
}
.table tbody td{
  padding:10px 10px;
  border-bottom:1px solid rgba(255,255,255,.06);
  font-size:14px;
}
.table tbody tr:hover{background:rgba(255,255,255,.04)}
.num{text-align:right;font-variant-numeric: tabular-nums;}
.level-cell{display:flex;justify-content:center}
.level-pill{
  width:18px;height:18px;border-radius:6px;
  border:1px solid rgba(255,255,255,.14);
}
.foot{margin-top:10px;display:grid;gap:4px}

/* ===== Legend compact (bottom) ===== */
.legend{margin-top:8px;margin-bottom:6px}
.legend-compact{padding-top:0}
.legend-grid.compact{
  display:grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap:8px;
}
@media (max-width: 900px){.legend-grid.compact{grid-template-columns: repeat(3, minmax(0, 1fr));}}
@media (max-width: 560px){.legend-grid.compact{grid-template-columns: repeat(2, minmax(0, 1fr));}}
.legend-item{
  display:flex;gap:8px;align-items:center;
  background:rgba(0,0,0,.16);
  border:1px solid var(--line);
  border-radius:14px;
  padding:8px 10px;
}
.swatch{width:10px;height:10px;border-radius:4px;display:inline-block;flex:0 0 auto}
.swatch-blue{background:var(--blue)}
.swatch-green{background:var(--green)}
.swatch-yellow{background:var(--yellow)}
.swatch-orange{background:var(--orange)}
.swatch-red{background:var(--red)}
.legend-name{font-weight:900;font-size:12px}
.legend-range{font-size:11px;color:var(--muted);margin-top:1px}
.legend-note{margin:8px 0 0 0;line-height:1.35}

/* ===== Footer links ===== */
.footer{border-top:1px solid var(--line);margin-top:18px;padding:10px 0}
.footer-links{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
  justify-content:center;
}
.footer-links a{color:rgba(232,238,252,.92);text-decoration:none;font-weight:800}
.footer-links a:hover{text-decoration:underline}
.footer-links .sep{color:rgba(255,255,255,.35)}


/* ===== Province detail card (from Top 10 click) ===== */
.rank-table tbody tr{cursor:pointer}
.rank-table tbody tr:active{transform:translateY(0.5px)}
.province-card{
  margin-top:10px;
  padding:12px;
  border-radius:18px;
  border:1px solid var(--line);
  background:rgba(0,0,0,.18);
}
.province-card .p-top{
  display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex-wrap:wrap
}
.province-card .p-name{
  font-size:18px;font-weight:1000;letter-spacing:.2px
}
.province-card .p-rank{
  color:var(--muted);font-size:12px;font-weight:800
}
.province-card .p-badge{
  display:inline-flex;align-items:center;gap:8px;
  padding:7px 10px;border-radius:999px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.04);
  font-weight:900;font-size:12px;
}
.province-card .p-badge .dot{width:8px;height:8px;border-radius:999px;background:currentColor}
.province-card .p-metrics{
  margin-top:10px;display:grid;grid-template-columns:1fr 1fr;gap:10px
}
@media (max-width: 560px){.province-card .p-metrics{grid-template-columns:1fr}}

.rank-table tbody tr.selected{
  outline:2px solid rgba(255,255,255,.18);
  outline-offset:-2px;
  background:rgba(255,255,255,.06);
}


/* ===== Map panel ===== */
.map-panel{margin-top:16px}
.map-head{display:flex;align-items:flex-end;justify-content:space-between;gap:12px;flex-wrap:wrap}
.map{
  height:360px;
  border-radius:18px;
  overflow:hidden;
  border:1px solid var(--line);
  background:rgba(0,0,0,.18);
}
.leaflet-container{font: inherit}

/* ===== Buttons ===== */
.btn-primary{
  background:rgba(59,130,246,.22);
  border:1px solid rgba(59,130,246,.30);
}
.btn-primary:hover{background:rgba(59,130,246,.28)}
.btn-ghost{
  background:transparent;
  border:1px solid rgba(255,255,255,.12);
}
.btn-ghost:hover{background:rgba(255,255,255,.06)}

/* ===== Modal ===== */
.modal.hidden{display:none}
.modal{
  position:fixed;inset:0;z-index:50;
  display:flex;align-items:center;justify-content:center;
  padding:16px;
}
.modal-backdrop{
  position:absolute;inset:0;
  background:rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
}
.modal-card{
  position:relative;
  width:min(860px, 96vw);
  background:linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.06));
  border:1px solid var(--line);
  border-radius:22px;
  overflow:hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.modal-head{
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:14px 14px;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.modal-title{font-weight:1000;font-size:14px;color:rgba(232,238,252,.95)}
.modal-body{padding:14px}
.share-preview{
  width:100%;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(0,0,0,.18);
}
.modal-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:12px}

/* Right-align numeric columns */
.rank-table th.num, .rank-table td.num,
.table th.num, .table td.num,
table th.num, table td.num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.loc-temp{ margin-top:6px; }
