:root {
  --navy: #0f172a;
  --blue: #2563eb;
  --cyan: #0ea5e9;
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe4f0;
  --card: rgba(255, 255, 255, 0.96);
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: #dbeafe;
}

.app-header {
  height: 68px;
  position: relative;
  z-index: 20000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  color: #fff;
  background: linear-gradient(110deg, #0f172a 0%, #16335f 65%, #075985 100%);
  box-shadow: 0 5px 18px rgba(15, 23, 42, 0.28);
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 12px;
  color: #7dd3fc;
  font-size: 25px;
  background: rgba(255,255,255,.1);
}

.brand-copy h1 { margin: 0; font-size: 20px; font-weight: 750; letter-spacing: .04em; }
.brand-copy p { margin: 2px 0 0; color: #a9c5e8; font-size: 11px; letter-spacing: .13em; text-transform: uppercase; }
.header-admin { margin-left: auto; padding: 8px 12px; border: 1px solid rgba(255,255,255,.24); border-radius: 9px; color: #e0f2fe; background: rgba(255,255,255,.08); font-size: 12px; font-weight: 700; text-decoration: none; transition: .18s ease; }
.header-admin:hover, .header-admin:focus { color: #fff; background: rgba(255,255,255,.16); text-decoration: none; }
.header-hint { display: flex; align-items: center; gap: 8px; color: #dbeafe; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 5px rgba(52,211,153,.13); }

.app-main { position: relative; height: calc(100% - 68px); }
#map { position: absolute; inset: 0; width: 100%; height: 100%; outline: none; }
#map:focus-visible { box-shadow: inset 0 0 0 3px var(--cyan); }

.control-panel {
  position: absolute;
  z-index: 10000;
  top: 18px;
  left: 18px;
  width: 326px;
  max-height: calc(100% - 36px);
  overflow: hidden;
  padding: 0;
  border: 1px solid rgba(203, 213, 225, .88);
  border-radius: 17px;
  background: rgba(248, 250, 252, .96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(15px);
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 transparent;
}

.tool-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 7px;
  border-bottom: 1px solid var(--line);
  background: rgba(241, 245, 249, .96);
}

.tool-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  height: 42px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  color: #64748b;
  background: transparent;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  transition: color .18s ease, background .18s ease, box-shadow .18s ease;
}

.tool-tab span { font-size: 16px; }
.tool-tab:hover { color: #1d4ed8; background: #eaf2ff; }
.tool-tab.active { color: #fff; background: linear-gradient(100deg, #2563eb, #0ea5e9); box-shadow: 0 6px 15px rgba(37,99,235,.24); }
.tool-tab:focus-visible { outline: 3px solid rgba(14,165,233,.3); outline-offset: 1px; }

.tab-panel {
  display: none;
  max-height: calc(100vh - 158px);
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 transparent;
}
.tab-panel.active { display: block; }
.tab-panel[hidden] { display: none; }

.panel-card {
  display: block;
  position: relative;
  margin-bottom: 10px;
  padding: 16px;
  border: 1px solid #dbe4f0;
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 5px 16px rgba(15, 23, 42, .06);
}
.tab-panel .panel-card:last-child { margin-bottom: 0; }

.card-heading { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.card-heading h2 { margin: 0; font-size: 15px; font-weight: 750; }
.card-heading p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.card-icon {
  flex: 0 0 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #1d4ed8;
  background: #eaf2ff;
  font-size: 18px;
}

.basemap-row, .layer-row { display: flex; align-items: center; min-height: 38px; }
.basemap-row { justify-content: flex-start; padding: 2px 3px 0; color: #475569; font-size: 13px; }
.basemap-row .switchbutton { width: 100% !important; height: 38px !important; }
.basemap-row .switchbutton-on,
.basemap-row .switchbutton-off { font-size: 13px; font-weight: 700; }

.coordinate-types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.coordinate-types label { margin: 0; cursor: pointer; }
.coordinate-types input { position: absolute; opacity: 0; pointer-events: none; }
.coordinate-types span {
  display: block;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: #526078;
  font-size: 12px;
  font-weight: 650;
  text-align: center;
  transition: .18s ease;
}
.coordinate-types input:checked + span { border-color: var(--blue); color: #fff; background: var(--blue); box-shadow: 0 5px 12px rgba(37,99,235,.22); }
.coordinate-types input:focus-visible + span { outline: 3px solid rgba(14,165,233,.28); }

.coordinate-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-width: 0;
}
.coordinate-fields label {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.coordinate-fields label > span { display: block; margin: 0 0 5px 2px; color: #64748b; font-size: 12px; font-weight: 700; }
.coordinate-fields .textbox {
  display: block;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  height: 40px !important;
  border-color: var(--line);
  border-radius: 9px;
}
.coordinate-fields .textbox-text {
  box-sizing: border-box !important;
  width: 100% !important;
  min-width: 0 !important;
  height: 38px !important;
  padding: 0 11px;
  font-size: 12px;
  line-height: 38px !important;
}
.search-button { width: 100% !important; height: 41px; margin-top: 12px; border: 0; border-radius: 10px; color: #fff; background: linear-gradient(100deg, #2563eb, #0ea5e9); }
.search-button:hover { color: #fff; background: linear-gradient(100deg, #1d4ed8, #0284c7); }
.search-button .l-btn-text { line-height: 39px; font-weight: 700; }

.layer-list { display: grid; gap: 4px; }
.layer-row { gap: 10px; padding: 7px 3px; border-top: 1px solid #edf1f6; }
.layer-row:first-child { border-top: 0; }
.layer-row .switchbutton { flex: 0 0 120px; width: 120px !important; height: 38px !important; }
.layer-row .switchbutton-on,
.layer-row .switchbutton-off { font-size: 13px; font-weight: 700; white-space: nowrap; }
.legend { flex: 0 0 auto; width: 20px; height: 5px; border-radius: 10px; box-shadow: 0 0 0 1px rgba(15,23,42,.1); }
.legend-point { width: 12px; height: 12px; margin: 0 4px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(15,23,42,.18); }
.legend-polygon { width: 18px; height: 12px; margin: 0 1px; border-radius: 3px; opacity: .55; }
.legend-orange { background: #f97316; }
.legend-yellow { background: #facc15; }
.legend-green { background: #22c55e; }
.layer-name { flex: 1; font-size: 13px; font-weight: 650; }
.layer-loading { padding: 12px 6px; color: var(--muted); font-size: 12px; text-align: center; }
.layer-error { color: #b91c1c; }

.switchbutton { border-color: #cbd5e1; border-radius: 18px; overflow: hidden; }
.switchbutton-on { background: #2563eb; }
.switchbutton-handle { border-radius: 50%; }
.ol-zoom { top: 16px !important; right: 16px !important; left: auto !important; padding: 4px !important; border-radius: 12px !important; background: rgba(255,255,255,.95) !important; box-shadow: 0 8px 24px rgba(15,23,42,.18); }
.ol-zoom button { width: 34px !important; height: 34px !important; margin: 2px !important; color: #334155 !important; background: #f8fafc !important; border-radius: 8px !important; }
.ol-attribution { right: 12px !important; bottom: 10px !important; border-radius: 8px 0 0 0; }

.feature-modal {
  position: fixed;
  z-index: 30000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}
.feature-modal[hidden] { display: none; }
.feature-modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .56); backdrop-filter: blur(3px); }
.feature-dialog {
  position: relative;
  width: min(580px, 100%);
  max-height: min(680px, calc(100vh - 40px));
  overflow: hidden;
  border: 1px solid rgba(203, 213, 225, .9);
  border-radius: 17px;
  background: #fff;
  box-shadow: 0 25px 70px rgba(15, 23, 42, .34);
}
.feature-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 18px;
  color: #fff;
  background: linear-gradient(110deg, #0f172a, #16335f 65%, #075985);
}
.feature-layer-name { display: block; margin-bottom: 3px; color: #7dd3fc; font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.feature-dialog-header h2 { margin: 0; font-size: 18px; font-weight: 750; }
.feature-dialog-close {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 10px;
  color: #fff;
  background: rgba(255,255,255,.1);
  font-size: 25px;
  line-height: 32px;
  cursor: pointer;
}
.feature-dialog-close:hover { background: rgba(255,255,255,.2); }
.feature-dialog-close:focus-visible { outline: 3px solid rgba(125,211,252,.5); }
.feature-properties { max-height: calc(min(680px, 100vh - 40px) - 90px); overflow-y: auto; padding: 12px 18px 18px; }
.feature-property-row { display: grid; grid-template-columns: 125px minmax(0,1fr); gap: 14px; padding: 12px 2px; border-bottom: 1px solid #e8eef5; }
.feature-property-row:last-child { border-bottom: 0; }
.feature-property-label { color: #64748b; font-size: 12px; font-weight: 750; overflow-wrap: anywhere; }
.feature-property-value { color: #172033; font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.feature-properties-empty { padding: 30px 10px; color: #64748b; text-align: center; font-size: 13px; }

@media (max-width: 720px) {
  .app-header { height: 58px; padding: 0 12px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand-copy h1 { font-size: 16px; }
  .brand-copy p, .header-hint { display: none; }
  .header-admin { margin-left: auto; padding: 7px 9px; font-size: 11px; }
  .app-main { height: calc(100% - 58px); }
  .control-panel {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 52%;
    padding: 0;
  }
  .tool-tabs { padding: 6px; }
  .tool-tab { height: 38px; }
  .tab-panel { max-height: calc(52vh - 54px); padding: 9px; }
  .panel-card { margin-bottom: 8px; padding: 13px; border-radius: 12px; }
  .card-heading { margin-bottom: 10px; }
  .card-heading p { display: none; }
  .ol-zoom { top: 10px !important; right: 10px !important; }
  .feature-modal { padding: 10px; }
  .feature-dialog { max-height: calc(100vh - 20px); border-radius: 14px; }
  .feature-dialog-header { padding: 14px; }
  .feature-properties { max-height: calc(100vh - 96px); padding: 8px 14px 14px; }
  .feature-property-row { grid-template-columns: 1fr; gap: 5px; padding: 10px 1px; }
}
