/* LORECa data platform — shared shell.
 *
 * Institutional rather than playful: a dark navy masthead, square-ish corners,
 * borders instead of drop shadows, uppercase micro-labels, and tabular figures
 * everywhere a number can be compared down a column.
 */
:root {
  --bg: #eceef2;
  --card: #ffffff;
  --card-2: #f5f6f9;
  --card-3: #fbfcfd;
  --line: #d3d8e2;
  --line-2: #e5e8ef;
  --text: #101828;
  --text-2: #33405a;
  --muted: #5c6779;
  --accent: #16365e;          /* navy — primary actions, active states */
  --accent-ink: #1f4d85;      /* hover */
  --accent-soft: #e9eef6;
  --accent-line: #c3d1e6;
  --on-dark: #2d6cbf;         /* CTA that has to read against the masthead */
  --masthead: #0f2340;
  --masthead-2: #8fa4c2;
  --success: #14764f;
  --success-dark: #0f5d3e;
  --success-soft: #e6f2ec;
  --danger: #9f2d24;
  --danger-soft: #fbeceb;
  --danger-line: #f0cfcc;
  --shadow: 0 1px 2px rgba(16, 35, 64, .05);
  --radius: 4px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
code {
  background: var(--card-2); border: 1px solid var(--line);
  padding: 2px 7px; border-radius: 3px; font-size: 12px; color: var(--text-2);
}

/* ---- Masthead ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--masthead);
  border-bottom: 3px solid var(--on-dark);
  padding: 0 28px;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  max-width: 1320px; margin: 0 auto; min-height: 62px;
}
.brand { display: flex; align-items: center; gap: 13px; }
.add-btn .plus { font-size: 15px; line-height: 1; margin-right: 1px; }
.logo {
  width: 38px; height: 38px; border-radius: 3px; display: grid; place-items: center;
  background: #fff; overflow: hidden; flex: none;
}
.logo img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.topbar h1 {
  font-size: 15px; margin: 0; color: #fff; font-weight: 650;
  letter-spacing: .01em;
}
.topbar .muted, .topbar .who .muted { color: var(--masthead-2); font-size: 12px; }

main {
  max-width: 1320px; margin: 0 auto; padding: 22px 28px 40px;
  display: flex; flex-direction: column; gap: 18px;
}

/* ---- Cards ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0; box-shadow: var(--shadow);
}
.card > h2, .card > .card-head, .card > .table-head {
  padding: 14px 18px; margin: 0; border-bottom: 1px solid var(--line-2);
}
.card h2 {
  font-size: 13px; font-weight: 700; margin: 0;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-2);
}
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.card-head h2 { margin-bottom: 2px; }
.card > *:not(h2):not(.card-head):not(.table-head) { padding-left: 18px; padding-right: 18px; }
.card > *:last-child { padding-bottom: 16px; }
.barchart { padding-top: 14px; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid transparent; border-radius: var(--radius); padding: 8px 15px;
  font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex;
  align-items: center; gap: 7px; font-family: inherit; line-height: 1.3;
  text-decoration: none; transition: background .13s, border-color .13s, color .13s;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.success { background: var(--success); color: #fff; }
.btn.success:hover { background: var(--success-dark); }
.btn.ghost { background: var(--card); color: var(--text-2); border-color: var(--line); }
.btn.ghost:hover { background: var(--card-2); border-color: var(--accent-line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.btn.danger:hover { background: #f7ddda; }
.btn.tiny { padding: 4px 9px; font-size: 12px; }
.btn.link { background: none; color: var(--muted); border: 0; padding-left: 4px; }
.btn.link:hover { color: var(--text); text-decoration: underline; }
.btn:disabled { opacity: .4; cursor: default; }

/* Buttons sitting on the dark masthead */
.topbar .btn.ghost {
  background: rgba(255, 255, 255, .07); color: #dce5f2; border-color: rgba(255, 255, 255, .2);
}
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, .15); border-color: rgba(255, 255, 255, .32); }
.topbar .btn.primary { background: var(--on-dark); }
.topbar .btn.primary:hover { background: #3f7fd4; }

/* ---- Fields ---- */
.field { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
select, input[type=search] {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 11px; font-size: 13px; outline: none; font-family: inherit;
}
select:focus, input[type=search]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- Upload ---- */
.dropzone {
  margin: 14px 0; border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--card-2); padding: 24px; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-inner { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.dz-icon { font-size: 20px; color: var(--accent); }
.upload-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.file-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.file-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card-2);
}
.file-item .fi-name { font-size: 13px; font-weight: 550; }
.file-item .fi-status { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.file-item .fi-remove { cursor: pointer; color: var(--muted); border: 0; background: none; font-size: 16px; }
.file-item .fi-bar { grid-column: 1 / -1; height: 5px; background: var(--line-2); border-radius: 2px; overflow: hidden; }
.file-item .fi-fill { height: 100%; width: 0%; background: var(--on-dark); transition: width .3s; }
.file-item.done { border-color: #c8e2d5; background: var(--success-soft); }
.file-item.error { border-color: var(--danger-line); background: var(--danger-soft); }
.file-item .fi-detail { grid-column: 1 / -1; font-size: 12px; color: var(--text-2); line-height: 1.45; }
.file-item.error .fi-detail { color: var(--danger); }

/* ---- Stat tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 15px; box-shadow: var(--shadow);
}
/* min-height keeps every tile's figure on the same baseline when a label wraps. */
.tile .lbl {
  color: var(--muted); font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; line-height: 1.3;
  min-height: 2.6em;
}
.tile .num {
  font-size: 25px; font-weight: 680; letter-spacing: -.5px; margin-top: 7px;
  font-variant-numeric: tabular-nums; color: var(--text);
}

/* ---- Bar charts ---- */
.charts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.barchart { display: flex; flex-direction: column; gap: 8px; }
.barrow { display: grid; grid-template-columns: 104px 1fr 58px; align-items: center; gap: 10px; font-size: 12px; }
.barrow .name {
  color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; flex-direction: column; line-height: 1.25;
}
.barrow .name .sub { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; }
.barrow .track { background: var(--line-2); border-radius: 2px; height: 14px; overflow: hidden; }
.barrow .val { display: block; background: var(--accent); height: 100%; border-radius: 2px; min-width: 2px; }
.barrow .count { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text-2); }

/* ---- Province / district explorer ---- */
.geo-card .geo-body {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  border-top: 0; padding: 0 !important;
}
.geo-col { display: flex; flex-direction: column; min-width: 0; }
.geo-col + .geo-col { border-left: 1px solid var(--line-2); }
.geo-col-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 11px 18px; background: var(--card-2); border-bottom: 1px solid var(--line-2);
}
.col-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.geo-col-head .muted { font-variant-numeric: tabular-nums; }
.geo-search { position: relative; padding: 10px 18px; border-bottom: 1px solid var(--line-2); }
.geo-search input { width: 100%; padding-left: 30px; }
.geo-search .search-ic { left: 28px; }
.geo-list { overflow-y: auto; max-height: 340px; flex: 1; }
.geo-districts .geo-list { max-height: 392px; }
.geo-item {
  position: relative; display: grid; grid-template-columns: 1fr auto auto;
  align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line-2); background: none;
  padding: 9px 18px; font-family: inherit; font-size: 13px; cursor: pointer; color: var(--text);
}
.geo-item:hover { background: var(--card-2); }
.geo-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.geo-bar { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(22, 54, 94, .07); z-index: 0; }
.geo-item.active .geo-bar { background: rgba(22, 54, 94, .12); }
.geo-name, .geo-meta, .geo-num { position: relative; z-index: 1; }
.geo-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.geo-meta { color: var(--muted); font-size: 11px; white-space: nowrap; }
.geo-num { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--text-2); }
.geo-empty { padding: 22px 18px; text-align: center; }
.geo-alert {
  margin: 0; padding: 10px 18px; background: #fdf6e6; border-bottom: 1px solid #efe0bd;
  color: #7a5b10; font-size: 12.5px;
}

/* ---- Records table ---- */
.table-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-box { position: relative; }
.search-box input { padding-left: 30px; width: 270px; max-width: 60vw; }
.search-ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; }
.filter-btn .badge {
  background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px;
  padding: 1px 6px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.chips {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 11px 18px !important; border-bottom: 1px solid var(--line-2);
}
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft);
  color: var(--accent); border: 1px solid var(--accent-line); border-radius: 3px;
  padding: 3px 8px; font-size: 12px; font-weight: 550;
}
.chip button { border: 0; background: none; cursor: pointer; color: var(--accent); font-size: 13px; padding: 0; line-height: 1; }
/* Tables run edge to edge inside a card; the header rule above them is the divider. */
.table-wrap { overflow-x: auto; }
.card > .table-wrap { padding: 0 !important; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
th {
  color: var(--muted); font-weight: 700; background: var(--card-2);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
}
tbody tr:nth-child(even) { background: var(--card-3); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--accent-soft); }
td.mono { font-variant-numeric: tabular-nums; }
th.col-check, td.col-check { width: 34px; text-align: center; padding-left: 12px; padding-right: 4px; }
th.col-check input, td.col-check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.pager {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-top: 14px; border-top: 1px solid var(--line-2); margin-top: 0;
}
.pager .muted { font-variant-numeric: tabular-nums; }

/* ---- Modals ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 35, 64, .45);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal-overlay.hidden, .hidden { display: none !important; }
.modal {
  width: 760px; max-width: 100%; max-height: 88vh; background: var(--card);
  border-radius: var(--radius); border: 1px solid var(--line);
  box-shadow: 0 18px 48px rgba(16, 35, 64, .28); display: flex; flex-direction: column; overflow: hidden;
}
.upload-modal { width: 640px; }
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  padding: 15px 20px; border-bottom: 1px solid var(--line); background: var(--card-2);
}
.modal-head h3 { margin: 0 0 3px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.modal-close { border: 0; background: none; cursor: pointer; font-size: 15px; color: var(--muted); padding: 4px; border-radius: 3px; }
.modal-close:hover { background: var(--line-2); color: var(--text); }
.upload-modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-body { display: grid; grid-template-columns: 210px 1fr; min-height: 400px; }
.modal-nav {
  border-right: 1px solid var(--line); padding: 10px 8px; display: flex; flex-direction: column;
  gap: 1px; background: var(--card-2);
}
.nav-item {
  text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 3px;
  cursor: pointer; font-size: 13px; font-family: inherit; color: var(--text-2);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.nav-item:hover { background: var(--line-2); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 650; }
.nav-item .nav-badge {
  background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px;
  padding: 0 6px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-badge { background: rgba(255, 255, 255, .25); }
.modal-panel { padding: 16px 20px; display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.panel-head h3 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.panel-search { position: relative; margin-bottom: 9px; }
.panel-search input { width: 100%; padding-left: 32px; }
.panel-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.panel-meta #panelHint { text-align: right; }
.option-list { overflow-y: auto; flex: 1; border: 1px solid var(--line); border-radius: var(--radius); }
.opt {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-bottom: 1px solid var(--line-2); cursor: pointer; font-size: 13px;
}
.opt:last-child { border-bottom: 0; }
.opt:hover { background: var(--card-2); }
.opt input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex: none; }
.opt-label { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.opt-sub { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
.opt .opt-count { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.modal-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; border-top: 1px solid var(--line); background: var(--card-2);
}
.foot-right { display: flex; gap: 8px; }

/* ---- Skeletons ---- */
.skel { position: relative; overflow: hidden; background: var(--line-2); border-radius: 2px; display: block; }
.skel::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .7), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skel-tile .lbl-s { height: 10px; width: 46%; }
.skel-tile .num-s { height: 24px; width: 62%; margin-top: 10px; }
.barrow .track.skel { background: var(--line-2); }

@media (max-width: 1000px) {
  .charts { grid-template-columns: 1fr; }
  .geo-card .geo-body { grid-template-columns: 1fr; }
  .geo-col + .geo-col { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 700px) {
  main { padding: 16px; }
  .topbar { padding: 0 16px; }
  .modal-body { grid-template-columns: 130px 1fr; }
}
