:root {
  color-scheme: light;
  --ink: #173332;
  --muted: #526d6a;
  --soft: #ebf3f0;
  --line: #dce8e4;
  --surface: #fff;
  --accent: #086b5d;
  --accent-dark: #064e44;
  --shadow: 0 2px 10px #163e3524, 0 1px 2px #163e3520;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; width: 100%; height: 100%; }
body { background: #f9fbfa; color: var(--ink); overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button { border: 0; background: none; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid #078877; outline-offset: 2px; }
h1, h2, p { margin: 0; }

.topbar {
  position: relative; z-index: 900; display: grid; grid-template-columns: 1fr minmax(300px, 560px) 1fr;
  align-items: center; gap: 22px; border-bottom: 1px solid var(--line); background: #fbfdfc;
  padding: calc(12px + env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; white-space: nowrap; }
.brand h1 { font-size: 20px; font-weight: 750; letter-spacing: .015em; }
.brand-mark { position: relative; display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 12px; background: var(--accent); }
.brand-mark::before, .brand-mark::after { position: absolute; content: ""; width: 23px; height: 23px; border: 2px solid transparent; border-top-color: #cbeade; border-radius: 100%; transform: translateY(4px); }
.brand-mark::after { width: 14px; height: 14px; transform: translateY(4px); }
.brand-mark i { width: 5px; height: 5px; border-radius: 50%; background: #fff; transform: translateY(4px); }
.search { min-width: 0; display: flex; align-items: center; gap: 12px; padding: 4px 4px 4px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--soft); }
.search:focus-within { border-color: #3d9688; }
.search-symbol { display: inline-block; flex: none; width: 15px; height: 15px; border: 1.7px solid #4d7771; border-radius: 50%; position: relative; margin-right: 3px; }
.search-symbol::after { content: ""; position: absolute; width: 7px; height: 1.7px; background: #4d7771; rotate: 45deg; bottom: -3px; right: -5px; }
.search input, .login-form input { font-size: 16px; }
.search input { border: 0; padding: 5px 0; background: transparent; flex: 1; width: 0; min-width: 0; outline: none; }
.search input::placeholder { color: #577470; }
.primary { background: var(--accent); color: #fff; border-radius: 8px; font-weight: 650; padding: 8px 15px; min-height: 35px; white-space: nowrap; }
.primary:hover { background: var(--accent-dark); }
.logout { justify-self: end; }
.quiet { border-radius: 8px; border: 1px solid var(--line); min-height: 36px; padding: 6px 13px; background: var(--surface); font-weight: 600; }
.quiet:hover { background: var(--soft); }

.workspace { display: grid; grid-template-columns: 302px minmax(0, 1fr); min-height: 0; flex: 1; position: relative; }
.map-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.sidebar { display: flex; flex-direction: column; background: #fbfdfc; border-right: 1px solid var(--line); min-height: 0; z-index: 800; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--soft); }
.view-tabs { display: flex; flex: 1; min-width: 0; gap: 4px; }
.view-tab { flex: 1; padding: 9px 3px; min-height: 39px; color: var(--muted); font-weight: 650; border-radius: 8px; white-space: nowrap; }
.view-tab.current { background: #fff; color: var(--accent-dark); box-shadow: 0 1px 3px #183f2820; }
.drawer-panel { display: flex; flex-direction: column; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.drawer-summary { padding: 15px 16px 8px; display: flex; gap: 10px; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }
.list { display: grid; gap: 6px; padding: 3px 10px 12px; }
.layer-item, .result-item { display: flex; width: 100%; min-width: 0; gap: 10px; align-items: center; background: #fff; border: 1px solid #e3ece9; border-radius: 10px; padding: 10px; text-align: left; }
.layer-item { cursor: pointer; }
.layer-item:hover, .result-item:hover { border-color: #97bfb5; }
.layer-item:has(input:checked), .result-item[aria-current="true"] { border-color: #9ec6ba; background: #f0f8f4; }
.result-item[aria-current="true"] { border-left: 4px solid var(--accent); padding-left: 7px; }
.layer-item input { flex: none; margin: 0; width: 17px; height: 17px; accent-color: var(--accent); }
.layer-actions { padding: 0 16px 8px; display: grid; gap: 7px; }
.layer-action-buttons { display: flex; gap: 7px; flex-wrap: wrap; }
.layer-action-buttons button { min-height: 44px; }
.cell-label-toggle { display: flex; align-items: center; gap: 9px; min-height: 44px; width: fit-content; margin: 0 16px; cursor: pointer; }
.cell-label-toggle input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.update-summary { color: var(--accent-dark); font-size: 12px; overflow-wrap: anywhere; }
.update-summary[data-state="failed"] { color: #9a351e; }
.swatch { width: 9px; height: 9px; flex: 0 0 9px; display: inline-block; border-radius: 50%; }
.list-content { min-width: 0; display: grid; gap: 3px; flex: 1; }
.item-name { font-weight: 650; overflow-wrap: anywhere; }
.item-meta { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.load-row { padding: 0 11px 14px; }
.load-row button { width: 100%; }

.map-frame { position: relative; isolation: isolate; min-height: 0; background: #e4eeea; overflow: hidden; }
#map { width: 100%; height: 100%; background: #e4eeea; font: inherit; }
.map-toolbar, .map-actions, .map-footer, .details { position: absolute; z-index: 700; }
.map-toolbar { top: 14px; left: 14px; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; max-width: calc(100% - 80px); }
.map-actions { right: max(14px, env(safe-area-inset-right)); bottom: calc(38px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.tool { min-height: 40px; border-radius: 10px; box-shadow: var(--shadow); background: #fff; font-size: 13px; font-weight: 650; }
.select-tool { display: flex; gap: 6px; align-items: center; padding: 0 6px 0 10px; }
.select-tool select { border: 0; background: var(--soft); border-radius: 6px; font-size: 16px; padding: 2px; }
.segmented { display: flex; gap: 3px; align-items: center; padding: 3px; }
.segmented button { border-radius: 7px; padding: 6px 9px; color: var(--muted); }
.segmented button[aria-pressed="true"] { color: var(--accent-dark); background: var(--soft); }
.map-button { width: 40px; height: 40px; display: grid; place-items: center; font-size: 23px; }
.map-button:hover, .close:hover { background: var(--soft); }
.zoom { overflow: hidden; }
.zoom button + button { border-top: 1px solid var(--line); }
.target { width: 15px; height: 15px; position: relative; border: 1.6px solid var(--accent-dark); border-radius: 50%; }
.target::before { content: ""; width: 5px; height: 5px; position: absolute; top: 3.4px; left: 3.4px; border-radius: 50%; background: var(--accent); }
.map-footer { bottom: calc(36px + env(safe-area-inset-bottom)); left: max(14px, env(safe-area-inset-left)); max-width: calc(100% - 82px); pointer-events: none; }
.map-status, .map-legend { width: fit-content; max-width: 100%; padding: 6px 9px; color: #345550; border-radius: 7px; box-shadow: var(--shadow); background: #fffffff5; font-size: 11px; font-weight: 650; }
.map-legend { display: flex; flex-wrap: wrap; gap: 5px 10px; margin-bottom: 7px; }
.legend-item { display: inline-flex; gap: 4px; align-items: center; }
.leaflet-control-attribution { margin-bottom: env(safe-area-inset-bottom) !important; font-size: 10px !important; }
.leaflet-control-scale { margin-bottom: calc(8px + env(safe-area-inset-bottom)) !important; }
.cell-labels { position: absolute; inset: 0; z-index: 620; pointer-events: none; font-size: 11px; font-weight: 600; line-height: 16px; }
.cell-label { position: absolute; top: 0; left: 0; padding: 0 4px; white-space: nowrap; border-radius: 3px; color: #173332; background: #ffffffa8; text-shadow: 0 0 2px #fff, 0 1px #fff, 0 -1px #fff; }
.cell-label.chosen { background: #e0f5ecf5; box-shadow: 0 0 0 1px #086b5da0; color: var(--accent-dark); }

.details { top: 14px; right: max(14px, env(safe-area-inset-right)); width: min(350px, calc(100% - 30px)); max-height: calc(100% - 170px); display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); overflow: auto; overscroll-behavior: contain; }
.detail-heading { position: relative; flex-shrink: 0; padding: 15px 15px 11px; background: #fbfdfc; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.detail-heading p { max-width: calc(100% - 32px); width: fit-content; padding: 3px 8px; border-radius: 5px; background: #d3eee5; font-size: 11px; color: var(--accent-dark); }
.detail-heading h2 { margin: 7px 30px 8px 0; font-size: 16px; line-height: 1.4; }
.detail-heading h2:focus { outline: none; }
.detail-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0; }
.detail-metrics div { padding: 6px 8px; border-radius: 8px; background: var(--soft); }
.detail-metrics dt { font-size: 10px; color: var(--muted); }
.detail-metrics dd { margin: 2px 0 0; color: var(--accent-dark); font-weight: 750; font-variant-numeric: tabular-nums; }
.close { flex: none; width: 34px; height: 34px; border-radius: 8px; line-height: 1; font-size: 25px; color: var(--muted); }
.detail-heading .close { position: absolute; top: 8px; right: 8px; }
.detail-heading:has(#detail-meta[hidden]) h2 { min-height: 30px; display: flex; align-items: center; margin-block: 0; }
#back-to-cells { min-height: 44px; margin-top: 7px; }
.cell-choice { min-height: 44px; padding: 6px 8px; margin-top: 5px; }

.update-dialog {
  width: min(520px, calc(100% - 24px)); max-width: none; max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px; background: #fff;
  color: inherit; box-shadow: 0 12px 28px #1a242129; overflow: auto;
}
.update-dialog::backdrop { background: #086b5d2e; backdrop-filter: blur(2px); }
.update-head, .update-footer { padding: 10px 20px; display: flex; align-items: center; gap: 10px; }
.update-head { border-bottom: 1px solid var(--line); justify-content: space-between; }
.update-head h2 { margin: 0; font-size: 18px; }
.update-head .close { width: 44px; height: 44px; }
.update-body { padding: 18px 20px; }
.update-body fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.update-body legend, .update-field { padding: 0; font-size: 14px; font-weight: 650; }
.update-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 15px; }
.update-modes label { min-height: 44px; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.update-modes label:has(input:checked) { background: var(--soft); border-color: #9ec6ba; }
.update-modes input, .update-feedback progress { accent-color: var(--accent); }
.update-field { display: block; }
.update-field select, .update-field input {
  display: block; width: 100%; min-height: 44px; margin: 7px 0 15px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--soft); font-size: 16px;
}
.update-hint { margin: 4px 0 8px; color: var(--muted); font-size: 12px; }
#update-files {
  width: 100%; min-height: 48px; padding: 3px 8px; border: 1px dashed #9ec6ba; border-radius: 8px;
  background: var(--soft); color: var(--muted); font: inherit;
}
#update-files::file-selector-button {
  min-height: 44px; margin-right: 9px; padding: 0 9px; border: 0;
  background: transparent; color: var(--accent-dark); font: inherit; font-weight: 650; cursor: pointer;
}
.update-file-list { margin: 8px 0 0; padding: 0; max-height: 90px; overflow: auto; list-style: none; }
.update-file-list li { margin-bottom: 3px; padding: 5px 8px; border-radius: 5px; background: var(--soft); font-size: 12px; overflow-wrap: anywhere; }
.update-feedback { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--soft); overflow-wrap: anywhere; font-size: 13px; }
.update-feedback[data-state="failed"] { background: #fdf0ed; color: #97321c; }
.update-feedback progress { margin-top: 7px; width: 100%; height: 12px; }
.update-footer { border-top: 1px solid var(--line); justify-content: flex-end; }
.update-footer button { min-height: 44px; }
.layer-actions button:disabled, .update-dialog button:disabled { opacity: .55; cursor: default; }
@media (max-width: 760px) {
  .update-dialog { width: 100%; max-height: calc(100dvh - 18px); margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .update-modes { grid-template-columns: 1fr; }
  .update-footer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}
.detail-body { min-height: 52px; padding: 5px 15px 13px; overflow: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
.detail-body p { padding: 8px 0; font-size: 12px; color: var(--muted); }
.detail-grid { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.detail-grid th, .detail-grid td { padding: 7px 6px; border-bottom: 1px solid #ebf1ef; vertical-align: top; }
.detail-grid tr:nth-child(even) { background: #f5f9f7; }
.detail-grid th { width: 44%; padding-right: 10px; font-weight: 600; text-align: left; color: var(--muted); }
.mobile-only { display: none; }

.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); background: radial-gradient(ellipse at 25% 12%, #dcefe7, transparent 65%), #f6faf7; }
.login-card { width: min(100%, 370px); padding: 26px; border: 1px solid var(--line); border-radius: 17px; background: #fff; box-shadow: var(--shadow); }
.login-form { display: grid; gap: 11px; margin-top: 26px; }
.login-form label { font-weight: 650; }
.login-form input { width: 100%; min-height: 43px; padding: 8px 12px; border: 1px solid #a9c1b9; border-radius: 8px; }
.login-form .primary { min-height: 43px; }
.login-error { color: #a62a33; }

@media (max-width: 900px) and (min-width: 761px) {
  .workspace { grid-template-columns: 244px minmax(0, 1fr); }
  .details { width: 265px; }
  .topbar { grid-template-columns: max-content minmax(0, 1fr) max-content; }
}
@media (max-width: 760px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; row-gap: 8px; padding: calc(8px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); }
  .brand h1 { font-size: 17px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 9px; }
  .search { grid-row: 2; grid-column: 1 / -1; }
  .logout { grid-column: 2; grid-row: 1; }
  .workspace { display: block; }
  .map-frame { height: 100%; }
  .mobile-only { display: inline-block; }
  .sidebar { display: none; position: absolute; top: 54px; left: max(8px, env(safe-area-inset-left)); width: min(320px, calc(100% - 16px - env(safe-area-inset-left) - env(safe-area-inset-right))); border: 1px solid var(--line); max-height: min(65%, 490px); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
  .sidebar.open { display: flex; }
  .sidebar.with-details { max-height: 26%; }
  .drawer-head { padding-top: 5px; padding-bottom: 5px; }
  .drawer-summary { padding-top: 10px; }
  .map-toolbar { top: 8px; left: max(8px, env(safe-area-inset-left)); gap: 5px; max-width: calc(100% - 16px); }
  #open-drawer { min-width: 46px; }
  .map-actions { right: max(8px, env(safe-area-inset-right)); bottom: calc(29px + env(safe-area-inset-bottom)); }
  .map-footer { bottom: calc(30px + env(safe-area-inset-bottom)); }
  .map-frame.with-details .map-actions { bottom: calc(40% + 19px + env(safe-area-inset-bottom)); }
  .map-frame.with-details .map-footer { visibility: hidden; }
  .map-frame.with-details .leaflet-control-scale { visibility: hidden; }
  .details { top: auto; right: max(8px, env(safe-area-inset-right)); bottom: calc(21px + env(safe-area-inset-bottom)); left: max(8px, env(safe-area-inset-left)); width: auto; max-height: 39%; }
  .detail-heading { padding-top: 9px; padding-bottom: 8px; }
  .detail-heading .close { top: 3px; width: 44px; height: 44px; }
}
@media (max-height: 500px) and (max-width: 900px) {
  .details { max-height: 58%; }
  .map-frame.with-details .map-actions { bottom: 30px; }
}
