:root {
  --bg: #f2f4f8; --surface: #ffffff; --surface2: #f6f8fb; --border: #d5dae3; --text: #1b202b; --muted: #5f6b7e;
  --accent: #2d8cff; --accent-h: #4b9dff; --in: #22b56b; --out: #e5484d; --warn: #f0a202;
  --in-bg: rgba(34,181,107,.13); --out-bg: rgba(229,72,77,.12); --warn-bg: rgba(240,162,2,.16);
  --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 14px rgba(20,30,50,.05); --radius: 12px;
}
:root[data-theme="dark"] {
  --bg: #161920; --surface: #1e222b; --surface2: #252a35; --border: #343b48; --text: #e8ecf2; --muted: #9aa4b5;
  --in-bg: rgba(34,181,107,.18); --out-bg: rgba(229,72,77,.18); --warn-bg: rgba(240,162,2,.2); --shadow: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; max-width: 100%; }
body { overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", Tahoma, sans-serif; display: flex; flex-direction: column; min-height: 100dvh; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .3px; white-space: nowrap; display: flex; gap: 8px; color: var(--accent); }
.brand .sep { color: var(--muted); font-weight: 400; }
.brand .sub { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; align-items: center; gap: 8px; }
.chip-access { font-weight: 700; font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); white-space: nowrap; }
.chip-access.ok { background: var(--in-bg); color: var(--in); }

/* ---------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface2); cursor: pointer; text-decoration: none; color: var(--text); min-height: 40px; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-h); }
.btn.danger { color: var(--out); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; min-height: 32px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 10px; background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.burger, .burger::before, .burger::after { display: block; width: 16px; height: 2px; background: var(--text); border-radius: 2px; position: relative; }
.burger::before, .burger::after { content: ""; position: absolute; left: 0; }
.burger::before { top: -5px; } .burger::after { top: 5px; }
.ico-contrast { width: 16px; height: 16px; border: 2px solid var(--text); border-radius: 50%; background: linear-gradient(90deg, var(--text) 50%, transparent 50%); }
.ico-pin { width: 12px; height: 12px; border: 3px solid currentColor; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); margin-inline-end: 4px; }
.ico-lock { width: 14px; height: 10px; border: 2px solid currentColor; border-radius: 3px; position: relative; margin-top: 5px; }
.ico-lock::before { content: ""; position: absolute; left: 1px; top: -8px; width: 6px; height: 7px; border: 2px solid currentColor; border-bottom: 0; border-radius: 5px 5px 0 0; }
input[type=text], input[type=search], select { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-height: 40px; }
input:focus, select:focus, .btn:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.btnrow { display: flex; gap: 8px; margin: 4px 0 8px; }
.btnrow > .btn { flex: 1; } .btnrow.wrap { flex-wrap: wrap; }
.inline { display: flex; gap: 8px; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }
.note { font-size: 13px; padding: 7px 10px; border-radius: 8px; background: var(--surface2); margin: 8px 0 0; }
.note.warn { background: var(--warn-bg); color: var(--text); border-inline-start: 3px solid var(--warn); }
.note.bad { background: var(--out-bg); }
.note.good { background: var(--in-bg); }

/* ---------- layout */
.layout { flex: 1; display: grid; grid-template-columns: 330px minmax(380px, 1.1fr) minmax(340px, 1fr); gap: 12px; padding: 12px; min-height: 0; }
#side { overflow: auto; padding-inline-end: 2px; }
#center { display: grid; grid-template-rows: minmax(160px, .8fr) minmax(220px, 1.2fr); gap: 12px; min-height: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
#center .card { margin: 0; }
.card h2 { margin: 0 0 10px; font-size: 12px; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
#mapwrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); min-height: 320px; }
#map { position: absolute; inset: 0; }
.viewbar { position: absolute; top: 10px; inset-inline-start: 10px; z-index: 6; display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
.seg button { border: 0; background: transparent; padding: 6px 13px; cursor: pointer; color: var(--text); min-height: 32px; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
#plan { position: absolute; inset: 0; background: #ffffff; z-index: 4; }
#plan svg { display: block; width: 100%; height: 100%; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* ---------- quick result */
.quick { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.badge { display: block; text-align: center; font-weight: 700; padding: 10px; border-radius: 12px; color: #fff; background: var(--border); }
.badge.in { background: var(--in); } .badge.out { background: var(--out); } .badge.err { background: var(--warn); color: #231a00; }
.quick dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 0; }
.quick dd.ltr-end { text-align: start; unicode-bidi: plaintext; }
.quick dt { color: var(--muted); } .quick dd { margin: 0; font-weight: 600; word-break: break-word; }

/* ---------- usage / lock */
.usage { height: 8px; border-radius: 999px; background: var(--surface2); overflow: hidden; border: 1px solid var(--border); }
.usage i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.usage.low i { background: var(--warn); } .usage.none i { background: var(--out); }
.usage-text { margin: 6px 0 10px; font-size: 13px; }
#cardBatch { position: relative; }
.lock { display: none; position: absolute; inset: 0; border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 86%, transparent); backdrop-filter: blur(2px); align-items: center; justify-content: center; gap: 8px; font-weight: 600; color: var(--muted); text-align: center; padding: 10px; }
body.locked #batchLock { display: flex; }
body.locked #batchBody { filter: blur(1.5px); pointer-events: none; user-select: none; }
body.locked #cardInput { display: none; }
body.locked #center { grid-template-rows: 1fr; }
body.unlocked #accessLocked { display: none; }

/* ---------- tables */
.tbl { display: flex; flex-direction: column; min-height: 0; }
.tbl > header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.tbl > header h2 { margin: 0; color: var(--text); font-size: 13px; text-transform: none; letter-spacing: 0; }
.tbl .tools { margin-inline-start: auto; }
.tbl .scroll { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 10px; min-height: 80px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 10px; text-align: start; white-space: nowrap; border-bottom: 1px solid var(--border); }
th { position: sticky; top: 0; background: var(--surface2); font-size: 12px; color: var(--muted); cursor: default; z-index: 1; user-select: none; }
#tblRes th[data-s] { cursor: pointer; } #tblRes th.sorted::after { content: " ▲"; font-size: 9px; } #tblRes th.sorted.desc::after { content: " ▼"; }
td[contenteditable] { outline: none; } td[contenteditable]:focus { background: var(--surface2); box-shadow: inset 0 0 0 2px var(--accent); }
th.sel, td.sel { width: 30px; padding-inline: 8px; }
td.num { text-align: end; font-variant-numeric: tabular-nums; }
tr.r-in { background: var(--in-bg); } tr.r-out { background: var(--out-bg); } tr.r-err { background: var(--warn-bg); }
tr.picked { outline: 2px solid var(--accent); outline-offset: -2px; }
td.st { font-weight: 700; } .r-in td.st { color: var(--in); } .r-out td.st { color: var(--out); } .r-err td.st { color: var(--warn); }
td.wide { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--border); background: var(--surface2); border-radius: 999px; padding: 3px 11px; cursor: pointer; font-size: 13px; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips button.in:not(.on) { color: var(--in); } .chips button.out:not(.on) { color: var(--out); } .chips button.err:not(.on) { color: var(--warn); }
#search { max-width: 220px; min-height: 32px; padding: 4px 10px; margin-inline-start: auto; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 8px; font-size: 13px; color: var(--muted); }
.pager:empty { display: none; }
.pager button { padding: 3px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface2); cursor: pointer; }

/* ---------- progress, dialogs, toast, footer */
.progress { position: relative; height: 22px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--border); overflow: hidden; margin: 8px 0; }
.progress i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); opacity: .85; transition: width .15s; }
.progress span { position: relative; display: block; text-align: center; font-size: 12px; line-height: 20px; }
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); width: min(640px, 94vw); max-height: 90dvh; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,14,22,.55); }
.dlg { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; max-height: 88dvh; }
#dlgMap { width: min(780px, 94vw); } .dlg h3 { margin: 0; }
.dlg pre { white-space: pre-wrap; font: inherit; line-height: 1.7; overflow: auto; max-height: 50dvh; margin: 0; padding: 12px; background: var(--surface2); border-radius: 10px; border: 1px solid var(--border); }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.dlg-lang { display: flex; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.about { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; } .about dt { color: var(--muted); } .about dd { margin: 0; font-weight: 600; }
.prev { max-height: 200px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; min-width: 0; }
.dlg > * { min-width: 0; }
.row4 .field { min-width: 0; margin-bottom: 4px; }
#mapPreview th, #mapPreview td { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.toast { position: fixed; bottom: 18px; inset-inline: 0; margin-inline: auto; width: max-content; max-width: 92vw; background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.foot { padding: 8px 14px 12px; text-align: center; color: var(--muted); font-size: 12px; }
.foot .dot { margin: 0 6px; }
.only-mobile { display: none; }

/* ---------- tablet / phone */
@media (max-width: 1180px) { .layout { grid-template-columns: 310px 1fr; } #mapwrap { grid-column: 1 / -1; min-height: 360px; } }
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .brand .sub, .brand .sep { display: none; }
  .brand h1 { font-size: 15px; }
  .tabs { display: flex; position: sticky; top: 52px; z-index: 15; background: var(--surface); border-bottom: 1px solid var(--border); }
  .tabs button { flex: 1; padding: 11px 6px; border: 0; background: transparent; border-bottom: 3px solid transparent; font-weight: 600; color: var(--muted); cursor: pointer; }
  .tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
  .layout { display: block; flex: none; min-height: auto; padding: 10px; }
  .layout > #side, .layout > #center, .layout > #mapwrap { display: none; }
  .layout[data-tab="check"] > #side { display: block; }
  .layout[data-tab="data"] > #center { display: grid; }
  .layout[data-tab="map"] > #mapwrap { display: block; height: calc(100dvh - 190px); min-height: 380px; }
  #center { grid-template-rows: auto auto; } #center .tbl .scroll { max-height: 46dvh; }
  .row4 { grid-template-columns: 1fr 1fr; }
  .btn { min-height: 44px; } input[type=text], input[type=search], select { min-height: 44px; font-size: 16px; }
}
@media (max-width: 560px) {
  .top { flex-wrap: wrap; padding: 8px 10px; row-gap: 6px; }
  .brand h1 .b1, .brand h1 .sep { display: none; }
  .brand h1 { font-size: 17px; }
  .actions { gap: 6px; margin-inline-start: auto; }
  .chip-access { font-size: 11px; padding: 3px 8px; }
  .btn.small { padding: 6px 9px; }
  .tabs { top: 0; position: static; }
  .layout { padding: 8px; }
  .card { padding: 12px; }
  .row2 { gap: 8px; }
  .layout[data-tab="map"] > #mapwrap { height: calc(100dvh - 150px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- converter additions (same look as Urban Check) */
.home { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 10px; text-decoration: none; color: var(--text); font-size: 18px; flex: none; }
.home:hover { border-color: var(--accent); }
.picker { display: grid; gap: 6px; }
.picker input, .picker select { min-height: 36px; padding: 6px 10px; }
.row5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.row5 .field { min-width: 0; margin-bottom: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin: 0; display: grid; gap: 8px; align-content: start; }
legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
.field.inl { display: flex; align-items: center; gap: 8px; margin: 0; }
.field.inl > span { margin: 0; white-space: nowrap; } .field.inl input { width: 60px; min-height: 32px; padding: 4px 8px; }
.quick dl { grid-template-columns: auto 1fr; align-items: center; }
.quick dd { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.quick dd span { direction: ltr; unicode-bidi: plaintext; word-break: break-all; }
.copy { border: 1px solid var(--border); background: var(--surface2); border-radius: 8px; cursor: pointer; padding: 1px 8px; font-size: 12px; color: var(--muted); flex: none; }
.copy:hover { border-color: var(--accent); color: var(--text); }
.chips button.out:not(.on) { color: var(--out); }
.tbl > header .seg { box-shadow: none; }
td.num { direction: ltr; text-align: start; unicode-bidi: plaintext; }
tr.r-ok td.st { color: var(--in); }
tr.r-warn { background: var(--warn-bg); } tr.r-err { background: var(--out-bg); }
td.bad { color: var(--out); font-weight: 600; }
.area-out { margin: 4px 0; min-height: 40px; } .area-out table { width: auto; } .area-out th { position: static; background: transparent; color: var(--muted); font-weight: 600; font-size: 13px; }
.area-out td { white-space: normal; } .area-out .w { color: var(--out); margin: 6px 0 0; }
#calTable td[contenteditable] { min-width: 90px; }
.menu button { white-space: nowrap; }
@media (max-width: 860px) { .row5 { grid-template-columns: 1fr 1fr; } .two { grid-template-columns: 1fr; } }

#dlgExport, #dlgCalib, #dlgArea { width: min(760px, 94vw); }

#center, #center .card, .tbl .scroll, #side { min-width: 0; }
#tblRes th, #tblRes td, #tblIn th, #tblIn td { padding: 5px 8px; }

/* ---------- shapefile exporter additions */
.opts { display: grid; gap: 6px; margin: 6px 0; }
.report { margin: 0; padding: 10px; white-space: pre-wrap; font: 12.5px/1.6 "Segoe UI", system-ui, "Noto Sans Arabic", Tahoma, sans-serif; }
.syslist { display: grid; gap: 6px; max-height: 32dvh; overflow: auto; margin: 6px 0; }
.syslist label { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.syslist label:has(input:checked) { border-color: var(--accent); background: var(--surface2); }
.syslist small { color: var(--muted); }
td.chk { text-align: center; } td.chk.ok { color: var(--in); } td.chk.warn { color: var(--warn); } td.chk.err { color: var(--out); }
#dlgSystem { width: min(720px, 94vw); }

/* Survey Toolbox: one page, three modes */
.layout[data-mode="check"] [data-modes]:not([data-modes~="check"]),
.layout[data-mode="merge"] [data-modes]:not([data-modes~="merge"]),
.layout[data-mode="report"] [data-modes]:not([data-modes~="report"]) { display: none; }
.seg.wide { display: flex; width: 100%; }
.seg.wide button { flex: 1; padding: 6px 4px; }
.srclist { font-size: 12.5px; margin-top: 8px; display: grid; gap: 4px; }
.srclist div { padding: 4px 8px; border-radius: 7px; background: var(--surface2); }
.report-html { font-size: 13px; padding: 4px 6px; }
.report-html table { border-collapse: collapse; margin: 6px 0 12px; }
.report-html table.grid th, .report-html table.grid td { border: 1px solid var(--border); padding: 3px 8px; text-align: end; }
.report-html table.kv td { padding: 2px 10px 2px 0; vertical-align: top; }
.report-html .parcel { border-top: 2px solid var(--border); margin-top: 14px; padding-top: 4px; }
.report-html .meta, .report-html .note { color: var(--muted, #667); }
