/* Unit HKA BWS Maluku — Model DEM 3D DAS */
.bws-terrain-panel {
  margin: 16px 0 4px;
  padding: 16px;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  background: linear-gradient(145deg, #f8fafc 0%, #eef7f4 100%);
  color: #0f172a;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .08);
}

.bws-terrain-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.bws-terrain-head h4 {
  margin: 0 0 4px;
  font-size: 1rem;
  line-height: 1.3;
  color: #0f3d33;
}

.bws-terrain-head p {
  margin: 0;
  color: #475569;
  font-size: .78rem;
  line-height: 1.45;
}

.bws-terrain-badge {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid #5eead4;
  border-radius: 999px;
  background: #ccfbf1;
  color: #115e59;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .06em;
}

.bws-terrain-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 11px;
}

.bws-terrain-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.bws-terrain-field > span {
  color: #334155;
  font-size: .75rem;
  font-weight: 750;
}

.bws-terrain-span-2 {
  grid-column: 1 / -1;
}

.bws-terrain-field select,
.bws-terrain-field input[type="range"] {
  width: 100%;
  min-width: 0;
}

.bws-terrain-field select {
  min-height: 42px;
  padding: 8px 34px 8px 10px;
  border: 1px solid #94a3b8;
  border-radius: 10px;
  background: #fff;
  color: #0f172a;
}

.bws-terrain-range-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.bws-terrain-range-label output {
  color: #0f766e;
  font-weight: 800;
}

.bws-terrain-help {
  margin: -2px 0 1px;
  color: #64748b;
  font-size: .67rem;
  line-height: 1.4;
}

.bws-terrain-field input[type="range"]:disabled {
  opacity: .42;
}

.bws-terrain-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 12px;
}

.bws-terrain-actions button,
.bws-terrain-viewer button {
  min-height: 42px;
  border: 1px solid #94a3b8;
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  color: #0f172a;
  font: inherit;
  font-size: .78rem;
  font-weight: 750;
  cursor: pointer;
  touch-action: manipulation;
}

.bws-terrain-actions button:hover:not(:disabled),
.bws-terrain-viewer button:hover:not(:disabled) {
  border-color: #0f766e;
  background: #f0fdfa;
}

.bws-terrain-actions button:disabled,
.bws-terrain-viewer button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.bws-terrain-actions .bws-terrain-primary {
  border-color: #0f766e;
  background: #0f766e;
  color: #fff;
}

.bws-terrain-actions .bws-terrain-primary:hover:not(:disabled) {
  background: #115e59;
  color: #fff;
}

.bws-terrain-status {
  margin-top: 11px;
  padding: 10px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: rgba(255, 255, 255, .82);
  color: #475569;
  font-size: .76rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.bws-terrain-status.loading { border-color: #7dd3fc; background: #f0f9ff; color: #075985; }
.bws-terrain-status.success { border-color: #86efac; background: #f0fdf4; color: #166534; }
.bws-terrain-status.warning { border-color: #fcd34d; background: #fffbeb; color: #92400e; }
.bws-terrain-status.error { border-color: #fca5a5; background: #fef2f2; color: #991b1b; }

.bws-county-dem-card #bwsCountyDemDownload {
  border-color: #0f766e !important;
  background: #0f766e !important;
  color: #fff !important;
  font-weight: 800 !important;
}

.bws-county-dem-card #bwsCountyDemDownload:hover:not(:disabled) {
  border-color: #115e59 !important;
  background: #115e59 !important;
}

.bws-dem-download-mode {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.bws-dem-download-mode > button {
  min-height: 34px;
  border: 1px solid rgba(15, 118, 110, .34) !important;
  background: rgba(15, 118, 110, .08) !important;
  color: inherit !important;
  font-weight: 800 !important;
}

.bws-dem-download-mode > button.is-active {
  border-color: #0f766e !important;
  background: #0f766e !important;
  color: #fff !important;
}

.bws-dem-download-panel {
  display: grid;
  gap: 8px;
}

.bws-dem-download-panel[hidden] {
  display: none !important;
}

.bws-county-dem-card #bwsSingleDemDownload {
  border-color: #0f766e !important;
  background: #0f766e !important;
  color: #fff !important;
  font-weight: 800 !important;
}

.bws-county-dem-card #bwsCountyDemDownload[aria-busy="true"]::before {
  content: "";
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  vertical-align: -2px;
  animation: bws-county-dem-spin .75s linear infinite;
}

.bws-county-dem-loading {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(15, 118, 110, .16);
}

.bws-county-dem-loading[hidden] {
  display: none !important;
}

.bws-county-dem-loading > i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #14b8a6;
  transition: width .35s ease;
}

.bws-county-dem-loading[data-state="error"] > i {
  background: #ef4444;
}

@keyframes bws-county-dem-spin {
  to { transform: rotate(360deg); }
}

.bws-terrain-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.bws-terrain-summary[hidden] { display: none !important; }

.bws-terrain-summary > div {
  min-width: 0;
  padding: 9px;
  border: 1px solid #dbe5e1;
  border-radius: 10px;
  background: rgba(255, 255, 255, .88);
}

.bws-terrain-summary span,
.bws-terrain-summary b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bws-terrain-summary span {
  margin-bottom: 3px;
  color: #64748b;
  font-size: .65rem;
}

.bws-terrain-summary b {
  color: #0f172a;
  font-size: .76rem;
  white-space: nowrap;
}

.bws-terrain-modal[hidden] { display: none !important; }

.bws-terrain-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: grid;
  place-items: center;
  padding: 3vh 3vw;
  background: rgba(2, 6, 23, .82);
  backdrop-filter: blur(4px);
}

.bws-terrain-viewer {
  width: min(1180px, 94vw);
  height: min(820px, 92vh);
  min-height: 520px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, .6);
  border-radius: 18px;
  background: #07111f;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}

.bws-terrain-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 10px 12px;
  border-bottom: 1px solid #243244;
  background: #0f1d2d;
  color: #e2e8f0;
}

.bws-terrain-title {
  min-width: 0;
  margin-right: auto;
}

.bws-terrain-title strong,
.bws-terrain-title small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bws-terrain-title strong { font-size: .92rem; }
.bws-terrain-title small { margin-top: 2px; color: #94a3b8; font-size: .7rem; }

.bws-terrain-toolbar button {
  min-height: 38px;
  border-color: #475569;
  background: #16283c;
  color: #e2e8f0;
  white-space: nowrap;
}

.bws-terrain-toolbar button.active {
  border-color: #22d3ee;
  background: #164e63;
  color: #ecfeff;
}

.bws-terrain-toolbar .bws-terrain-close {
  width: 40px;
  padding: 4px;
  font-size: 1.25rem;
}

.bws-terrain-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #19334b 0%, #081423 52%, #030712 100%);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.bws-terrain-stage.is-dragging { cursor: grabbing; }

.bws-terrain-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.bws-terrain-hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: grid;
  gap: 7px;
  max-width: min(440px, calc(100% - 24px));
  pointer-events: none;
}

.bws-terrain-hud > div {
  padding: 8px 10px;
  border: 1px solid rgba(148, 163, 184, .35);
  border-radius: 10px;
  background: rgba(7, 17, 31, .78);
  color: #dbeafe;
  font-size: .69rem;
  line-height: 1.4;
  backdrop-filter: blur(5px);
}

.bws-terrain-ramp {
  display: block;
  width: 180px;
  max-width: 100%;
  height: 8px;
  margin: 5px 0 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, #155e75, #22c55e, #facc15, #b45309, #f8fafc);
}

.bws-terrain-ramp.is-slope {
  background: linear-gradient(90deg, #1f9d55, #a6c72e, #f5bd15, #eb4512, #701075);
}

.bws-terrain-ramp-labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #bfdbfe;
}

.bws-terrain-lc-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 9px;
  margin-top: 6px;
}

.bws-terrain-lc-legend span {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bws-terrain-lc-legend i {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border: 1px solid rgba(255, 255, 255, .45);
  border-radius: 2px;
}

.bws-terrain-lc-legend + small {
  display: block;
  margin-top: 5px;
  color: #bfdbfe;
}

.bws-rain-panel[hidden],
.bws-rain-panel [hidden] {
  display: none !important;
}

.bws-rain-panel {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 12;
  width: min(410px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 12px;
  border: 1px solid rgba(103, 232, 249, .42);
  border-radius: 14px;
  background: rgba(7, 17, 31, .94);
  color: #e2e8f0;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .38);
  backdrop-filter: blur(9px);
  cursor: default;
  touch-action: pan-y;
  user-select: text;
  scrollbar-width: thin;
  scrollbar-color: #475569 transparent;
}

.bws-rain-head,
.bws-rain-grid-head,
.bws-rain-load-row,
.bws-rain-timeline,
.bws-rain-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bws-rain-head {
  align-items: flex-start;
  margin-bottom: 10px;
}

.bws-rain-head > div {
  min-width: 0;
  margin-right: auto;
}

.bws-rain-head b,
.bws-rain-head small {
  display: block;
}

.bws-rain-head b {
  color: #ecfeff;
  font-size: .82rem;
}

.bws-rain-head small {
  margin-top: 3px;
  color: #a5f3fc;
  font-size: .62rem;
  line-height: 1.35;
}

.bws-rain-head button {
  flex: 0 0 34px;
  width: 34px;
  min-height: 34px;
  padding: 2px;
  border-color: #475569;
  background: #17283a;
  color: #e2e8f0;
  font-size: 1.05rem;
}

.bws-rain-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.bws-rain-fields label {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 4px;
}

.bws-rain-fields label > span {
  min-width: 0;
  color: #cbd5e1;
  font-size: .62rem;
  font-weight: 750;
  line-height: 1.25;
}

.bws-rain-fields output {
  float: right;
  color: #67e8f9;
}

.bws-rain-fields select,
.bws-rain-fields input[type="date"],
.bws-rain-fields input[type="number"] {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid #475569;
  border-radius: 8px;
  background: #0f2032;
  color: #f8fafc;
  color-scheme: dark;
  font: inherit;
  font-size: .7rem;
}

.bws-rain-fields input[type="range"] {
  width: 100%;
  min-width: 0;
  margin: 7px 0;
  accent-color: #22d3ee;
}

.bws-rain-load-row {
  margin-top: 9px;
  align-items: stretch;
}

.bws-rain-load-row button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 9px;
  border-color: #0891b2;
  background: #164e63;
  color: #ecfeff;
  font-size: .67rem;
}

.bws-rain-load-row small {
  align-self: center;
  color: #94a3b8;
  font-size: .58rem;
  line-height: 1.3;
}

.bws-rain-grid-head {
  justify-content: space-between;
  margin: 10px 0 6px;
  color: #dbeafe;
  font-size: .66rem;
}

.bws-rain-grid-head button {
  min-height: 30px;
  padding: 4px 7px;
  font-size: .6rem;
}

.bws-rain-grid-list {
  max-height: 156px;
  overflow: auto;
  display: grid;
  gap: 5px;
  padding-right: 2px;
  color: #94a3b8;
  font-size: .65rem;
  scrollbar-width: thin;
  scrollbar-color: #475569 transparent;
}

.bws-rain-grid-card {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr) auto;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 6px 7px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: rgba(15, 32, 50, .78);
}

.bws-rain-grid-card.selected {
  border-color: rgba(34, 211, 238, .55);
  background: rgba(8, 47, 73, .74);
}

.bws-rain-grid-select {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.bws-rain-grid-select input {
  flex: 0 0 auto;
  accent-color: #22d3ee;
}

.bws-rain-grid-select span,
.bws-rain-grid-select b,
.bws-rain-grid-select small {
  min-width: 0;
  display: block;
}

.bws-rain-grid-select b { color: #f8fafc; font-size: .66rem; }
.bws-rain-grid-select small { color: #94a3b8; font-size: .54rem; }

.bws-rain-grid-value {
  min-width: 0;
  overflow: hidden;
  color: #bae6fd;
  font-size: .59rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bws-rain-grid-factor {
  display: flex;
  align-items: center;
  gap: 3px;
  color: #94a3b8;
  font-size: .52rem;
}

.bws-rain-grid-factor > span:first-child { display: none; }

.bws-rain-grid-factor input {
  width: 48px;
  min-height: 29px;
  box-sizing: border-box;
  padding: 3px 4px;
  border: 1px solid #475569;
  border-radius: 6px;
  background: #0b1727;
  color: #f8fafc;
  font: inherit;
  font-size: .61rem;
  text-align: right;
}

.bws-rain-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  margin-top: 9px;
}

.bws-rain-metrics span {
  min-width: 0;
  padding: 6px;
  border: 1px solid #334155;
  border-radius: 7px;
  background: rgba(15, 23, 42, .7);
  color: #94a3b8;
  font-size: .54rem;
  line-height: 1.25;
}

.bws-rain-metrics b {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: #e0f2fe;
  font-size: .63rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bws-rain-timeline {
  margin-top: 8px;
}

.bws-rain-timeline progress {
  flex: 1 1 auto;
  width: 100%;
  height: 8px;
  border: 0;
  accent-color: #22d3ee;
}

.bws-rain-timeline span {
  flex: 0 0 auto;
  min-width: 78px;
  color: #bae6fd;
  font-size: .59rem;
  text-align: right;
}

.bws-rain-actions {
  margin-top: 8px;
}

.bws-rain-actions button {
  flex: 1 1 0;
  min-height: 36px;
  padding: 6px;
  font-size: .66rem;
}

.bws-rain-actions button.primary {
  border-color: #0891b2;
  background: #0e7490;
  color: #fff;
}

.bws-rain-status {
  margin-top: 8px;
  padding: 7px 8px;
  border: 1px solid #334155;
  border-radius: 7px;
  background: rgba(15, 23, 42, .7);
  color: #cbd5e1;
  font-size: .59rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.bws-rain-status.loading { border-color: #0e7490; color: #a5f3fc; }
.bws-rain-status.success { border-color: #15803d; color: #bbf7d0; }
.bws-rain-status.warning { border-color: #a16207; color: #fde68a; }
.bws-rain-status.error { border-color: #b91c1c; color: #fecaca; }

.bws-rain-note {
  display: block;
  margin-top: 7px;
  color: #94a3b8;
  font-size: .54rem;
  line-height: 1.35;
}

.bws-terrain-progress {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 7, 18, .82);
  color: #e2e8f0;
  text-align: center;
  font-size: .84rem;
}

.bws-terrain-progress[hidden] { display: none !important; }

.bws-terrain-progress::before {
  content: '';
  width: 38px;
  height: 38px;
  margin: 0 auto 12px;
  display: block;
  border: 3px solid #334155;
  border-top-color: #2dd4bf;
  border-radius: 50%;
  animation: bws-terrain-spin .9s linear infinite;
}

body.bws-terrain-open { overflow: hidden !important; }

@keyframes bws-terrain-spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .bws-terrain-panel { margin: 12px 0 2px; padding: 12px; border-radius: 13px; }
  .bws-terrain-head { align-items: center; }
  .bws-terrain-head p { font-size: .71rem; }
  .bws-terrain-form { grid-template-columns: minmax(0, 1fr); }
  .bws-terrain-span-2 { grid-column: auto; }
  .bws-terrain-actions { grid-template-columns: minmax(0, 1fr); }
  .bws-terrain-actions button { width: 100%; min-height: 44px; }
  .bws-terrain-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bws-terrain-modal { padding: 0; }
  .bws-terrain-viewer { width: 100vw; height: 100dvh; min-height: 0; border: 0; border-radius: 0; }
  .bws-terrain-toolbar { flex-wrap: wrap; gap: 7px; padding: 8px; min-height: 0; }
  .bws-terrain-title { flex: 1 1 calc(100% - 52px); }
  .bws-terrain-toolbar button:not(.bws-terrain-close) { flex: 1 1 calc(33.333% - 7px); min-width: 0; padding: 7px 5px; font-size: .68rem; }
  .bws-terrain-toolbar .bws-terrain-close { order: 2; flex: 0 0 40px; }
  .bws-terrain-stage { min-height: 240px; }
  .bws-terrain-hud { left: 8px; bottom: 8px; max-width: calc(100% - 16px); }
  .bws-terrain-hud > div { padding: 6px 8px; font-size: .62rem; }
  .bws-terrain-lc-legend { grid-template-columns: minmax(0, 1fr); max-height: 92px; overflow: hidden; }
  .bws-rain-panel { left: 8px; right: 8px; bottom: 8px; width: auto; max-height: min(58%, 460px); padding: 10px; border-radius: 12px; }
  .bws-terrain-stage.has-rain-panel .bws-terrain-hud { top: 8px; bottom: auto; max-width: min(48%, 250px); }
  .bws-terrain-stage.has-rain-panel #bwsTerrainHint { display: none; }
  .bws-rain-grid-list { max-height: 112px; }
  .bws-rain-grid-card { grid-template-columns: minmax(0, 1fr) minmax(80px, .8fr) auto; }
  .bws-rain-fields select,
  .bws-rain-fields input[type="date"],
  .bws-rain-fields input[type="number"] { min-height: 34px; }
  .bws-rain-actions button { min-height: 38px; }
}

@media (max-width: 390px) {
  .bws-terrain-summary { grid-template-columns: minmax(0, 1fr); }
  .bws-terrain-toolbar button:not(.bws-terrain-close) { font-size: .62rem; }
  .bws-rain-panel { max-height: 62%; }
  .bws-rain-fields { gap: 7px; }
  .bws-rain-grid-card { grid-template-columns: minmax(0, 1fr) auto; }
  .bws-rain-grid-value { grid-column: 1; grid-row: 2; text-align: left; }
  .bws-rain-grid-factor { grid-column: 2; grid-row: 1 / span 2; }
  .bws-rain-load-row { align-items: center; }
  .bws-rain-load-row small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .bws-terrain-progress::before { animation-duration: 1.8s; }
}
