/* ---------------------------------------------------------------------------
   Cesium Desktop GIS — ArcGIS Pro / Microsoft Fluent ribbon shell.

   Palette and ribbon metrics are kept in step with SkylineOpsConsole/ui so the
   two desktop apps read as one product family. Token names mirror that sheet.
--------------------------------------------------------------------------- */

:root {
  /* --- chrome ------------------------------------------------------------ */
  --backgroundColorMain: #f4f6f8;   /* window chrome, tab strip */
  --ribbonBackground: #fdfdfe;      /* ribbon body */
  --panelBackground: #ffffff;       /* side panels */
  --panelAlt: #f4f6f8;              /* group headers, sunken rows */
  --buttonBackground: #ffffff;

  /* --- text -------------------------------------------------------------- */
  --textColor: #323639;
  --textDim: #6e7378;
  --textFaint: #9aa0a6;

  /* --- accents ----------------------------------------------------------- */
  --Color1: #0078d4;                /* Microsoft / ArcGIS Pro blue */
  --Color2: #c77700;                /* amber secondary */
  --Color5: #d3d8dd;                /* chrome borders */
  --Color6: #e4e8ec;                /* group separators */
  --Color7: #ffffff;
  --errorColor: #d13438;
  --warnColor: #c77700;
  --okColor: #107c10;
  --accentSoft: rgba(0, 120, 212, .10);
  --hoverFill: #e6f2fb;             /* Office button hover */
  --hoverBorder: #9ecdf0;
  --pressedFill: #cce4f7;           /* Office toggled / pressed */
  --pressedBorder: #66aede;
  --iconColor: #1b6fb5;             /* ribbon icon strokes */

  /* --- metrics ----------------------------------------------------------- */
  --rtabs-h: 34px;
  --ribbon-h: 130px;   /* tab strip + panel */
  --status-h: 26px;
  --panel-w: 306px;
  --right-w: 360px;
  --radiusM: 3px;                   /* Office ribbon uses tight radii */
  --radiusL: 4px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font: 13px/1.45 var(--font);
  color: var(--textColor);
  background: var(--backgroundColorMain);
  user-select: none;
}

button { font: inherit; color: inherit; }

#app {
  display: grid;
  grid-template-rows: var(--ribbon-h) 1fr var(--status-h);
  height: 100vh;
}

/* ===========================================================================
   Ribbon
   =========================================================================== */

#ribbon-shell {
  display: grid;
  grid-template-rows: var(--rtabs-h) 1fr;
  background: var(--ribbonBackground);
  border-bottom: 1px solid var(--Color5);
  min-height: 0;
}

/* --- tab strip ----------------------------------------------------------- */
.rtabs {
  display: flex;
  align-items: stretch;
  gap: 1px;
  padding: 0 8px;
  background: var(--backgroundColorMain);
  border-bottom: 1px solid var(--Color5);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 2px;
  margin-right: 8px;
  white-space: nowrap;
}
.brand svg { width: 19px; height: 19px; fill: none; stroke: var(--Color1); stroke-width: 1.5; }
.brand b { font-size: 12.5px; font-weight: 600; }

.rtab {
  padding: 0 15px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--textDim);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.rtab:hover { background: var(--hoverFill); color: var(--textColor); }
.rtab.active {
  color: var(--Color1);
  font-weight: 600;
  border-bottom-color: var(--Color1);
  background: var(--ribbonBackground);
}
.rtab-spacer { flex: 1; }

/* The way back to the solar system stays visible on every tab. */
#solar-system-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: center;
  padding: 4px 13px 4px 9px;
  background: var(--accentSoft);
  border: 1px solid #9ecdf0;
  border-radius: 13px;
  color: var(--Color1);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
#solar-system-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; }
#solar-system-btn em {
  font-style: normal;
  font-weight: 400;
  font-size: 11px;
  color: var(--textDim);
  padding-left: 8px;
  border-left: 1px solid #b9d7ef;
}
#solar-system-btn:hover { background: #d5e9f9; border-color: var(--Color1); }

/* --- ribbon panels ------------------------------------------------------- */
#ribbon {
  display: flex;
  min-height: 0;
  overflow: hidden;
}
.rpanel {
  display: none;
  align-items: stretch;
  flex: 1;
  padding: 3px 6px 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.rpanel.active { display: flex; }
.rpanel::-webkit-scrollbar { height: 6px; }

/* --- ribbon dropdown fields ---------------------------------------------- */
.rfields { display: flex; flex-direction: column; justify-content: center; gap: 5px; padding: 4px 4px 0; }
.rfield { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--textDim); }
.rfield > span { min-width: 56px; }
.rfield select {
  min-width: 220px;
  padding: 3px 7px;
  background: var(--Color7);
  border: 1px solid #c8cdd2;
  border-radius: var(--radiusM);
  color: var(--textColor);
  font: inherit;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
.rfield select:hover { border-color: var(--hoverBorder); }
.rfield select:focus { border-color: var(--Color1); }
.rfield-note {
  font-size: 10.5px;
  color: var(--textFaint);
  max-width: 292px;
  /* One line only: the ribbon has a fixed height and a wrapped note clips. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- groups -------------------------------------------------------------- */
.rgroup {
  display: flex;
  flex-direction: column;
  padding: 1px 7px 0;
  position: relative;
  flex: none;
}
.rgroup::after {
  content: "";
  position: absolute;
  right: 0; top: 6px; bottom: 6px;
  width: 1px;
  background: var(--Color6);
}
.rgroup:last-child::after { display: none; }

.tool-row { display: flex; align-items: stretch; gap: 1px; flex: 1; }
/* Two half-height controls occupy the vertical space of one large control. */
.tool-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1px;
  padding-top: 1px;
}
.group-label {
  text-align: center;
  font-size: 10.5px;
  color: var(--textDim);
  padding: 2px 4px 3px;
  white-space: nowrap;
  flex: none;
}

/* --- large control: icon above label ------------------------------------- */
.rtool.big {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radiusM);
  color: var(--textColor);
  font-size: 11px;
  line-height: 1.15;
  cursor: pointer;
  min-width: 54px;
  max-width: 78px;
  padding: 6px 6px 3px;
}
.rtool.big svg { width: 26px; height: 26px; flex: none; }
.rtool.big span { text-align: center; }

/* --- small control: icon beside label ------------------------------------ */
.rtool.small {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radiusM);
  color: var(--textColor);
  font-size: 11.5px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 9px 2px 5px;
  height: 23px;
  text-align: left;
  white-space: nowrap;
}
.rtool.small svg { width: 15px; height: 15px; flex: none; }

.rtool svg { stroke: var(--iconColor); fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.rtool:hover { background: var(--hoverFill); border-color: var(--hoverBorder); }
.rtool:active { background: var(--pressedFill); }
.rtool.on { background: var(--pressedFill); border-color: var(--pressedBorder); }
.rtool.on svg { stroke: var(--Color1); }
.rtool:focus-visible { outline: 2px solid var(--Color1); outline-offset: 1px; }

/* ===========================================================================
   Workspace
   =========================================================================== */

#workspace {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr 0;
  min-height: 0;
  transition: grid-template-columns .16s ease;
}
#workspace.right-open { grid-template-columns: var(--panel-w) 1fr var(--right-w); }
#workspace.left-closed { grid-template-columns: 0 1fr 0; }
#workspace.left-closed.right-open { grid-template-columns: 0 1fr var(--right-w); }

#left-panel, #right-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panelBackground);
  overflow: hidden;
}
#left-panel { border-right: 1px solid var(--Color5); }
#right-panel { border-left: 1px solid var(--Color5); }

.tabs { display: flex; border-bottom: 1px solid var(--Color5); background: var(--panelAlt); }
.tab {
  flex: 1;
  padding: 8px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--textDim);
  cursor: pointer;
}
.tab:hover { background: var(--hoverFill); color: var(--textColor); }
.tab.active {
  color: var(--Color1);
  font-weight: 600;
  border-bottom-color: var(--Color1);
  background: var(--panelBackground);
}

.tab-body { display: none; flex-direction: column; min-height: 0; flex: 1; }
.tab-body.active { display: flex; }

.panel-toolbar {
  display: flex;
  gap: 4px;
  padding: 6px;
  border-bottom: 1px solid var(--Color6);
}
.panel-toolbar input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  background: var(--Color7);
  border: 1px solid #c8cdd2;
  border-radius: var(--radiusM);
  color: var(--textColor);
  font: inherit;
  user-select: text;
  outline: none;
}
.panel-toolbar input:focus { border-color: var(--Color1); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid var(--Color5);
  background: var(--panelAlt);
  font-weight: 600;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radiusM);
  color: var(--textDim);
  cursor: pointer;
  flex: none;
}
.icon-btn svg {
  width: 15px; height: 15px;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn:hover { background: var(--hoverFill); border-color: var(--hoverBorder); color: var(--Color1); }
.icon-btn.danger:hover { color: var(--errorColor); border-color: #f0b3b5; background: #fdf3f4; }

.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #c3c9cf; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a9b1b9; }

/* ===========================================================================
   Layer tree
   =========================================================================== */

.layer-group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--panelAlt);
  border-top: 1px solid var(--Color6);
  border-bottom: 1px solid var(--Color6);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--textDim);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}
.layer-group-head .count {
  margin-left: auto;
  background: var(--Color7);
  border: 1px solid var(--Color5);
  border-radius: 9px;
  padding: 0 7px;
  font-size: 10px;
  font-weight: 400;
}

.layer-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid #eef1f4;
  cursor: pointer;
}
.layer-row:hover { background: var(--hoverFill); }
.layer-row.selected { background: var(--accentSoft); box-shadow: inset 2px 0 0 var(--Color1); }
.layer-row input[type=checkbox] { accent-color: var(--Color1); width: 15px; height: 15px; cursor: pointer; }

.layer-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-sub {
  display: block;
  font-size: 10.5px;
  color: var(--textDim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layer-actions { display: flex; gap: 1px; opacity: 0; }
.layer-row:hover .layer-actions,
.layer-row.selected .layer-actions { opacity: 1; }

.layer-detail {
  padding: 9px 10px 11px 36px;
  background: var(--panelAlt);
  border-bottom: 1px solid var(--Color6);
  display: grid;
  gap: 8px;
}
.field { display: grid; grid-template-columns: 78px 1fr auto; align-items: center; gap: 8px; }
.field label { font-size: 11px; color: var(--textDim); }
.field input[type=range] { width: 100%; accent-color: var(--Color1); }
.field .val { font: 10.5px var(--mono); color: var(--textDim); min-width: 36px; text-align: right; }
.field select,
.field input[type=text],
.field input[type=number] {
  padding: 4px 6px;
  background: var(--Color7);
  border: 1px solid #c8cdd2;
  border-radius: var(--radiusM);
  color: var(--textColor);
  font: inherit;
  user-select: text;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--Color1); }

.empty-state { padding: 34px 20px; text-align: center; color: var(--textDim); }
.empty-state svg { width: 40px; height: 40px; fill: none; stroke: currentColor; stroke-width: 1.2; opacity: .45; }
.empty-state p { margin: 10px 0 4px; color: var(--textColor); }
.empty-state small { line-height: 1.5; display: block; }

/* ===========================================================================
   File browser
   =========================================================================== */

.chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border-bottom: 1px solid var(--Color6); }
.chip {
  padding: 3px 10px;
  background: var(--buttonBackground);
  border: 1px solid var(--Color5);
  border-radius: 11px;
  color: var(--textDim);
  font-size: 11px;
  cursor: pointer;
}
.chip:hover { background: var(--hoverFill); border-color: var(--hoverBorder); color: var(--Color1); }

.fs-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  cursor: pointer;
  border-bottom: 1px solid #f2f4f6;
}
.fs-row:hover { background: var(--hoverFill); }
.fs-row.loadable { color: var(--textColor); }
.fs-row.plain { color: var(--textFaint); }
.fs-row svg { width: 15px; height: 15px; fill: none; stroke: var(--iconColor); stroke-width: 1.5; }
.fs-row.plain svg { stroke: var(--textFaint); }
.fs-row .fs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-row .fs-size { font: 10px var(--mono); color: var(--textFaint); }
.fs-row.loadable .fs-name { font-weight: 500; }
.fs-badge {
  font-size: 9.5px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--accentSoft);
  color: var(--Color1);
  text-transform: uppercase;
  font-weight: 600;
}

/* ===========================================================================
   Viewer
   =========================================================================== */

#viewer-host { position: relative; min-width: 0; background: #000; }
#cesiumContainer { position: absolute; inset: 0; }
.cesium-widget-credits { font-size: 10px; opacity: .6; }
.cesium-viewer-bottom { padding-bottom: 2px; }

#drop-hint {
  position: absolute;
  inset: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--Color1);
  border-radius: 8px;
  background: rgba(0, 120, 212, .14);
  backdrop-filter: blur(2px);
  pointer-events: none;
  z-index: 20;
}
#drop-hint.show { display: flex; }
#drop-hint div {
  padding: 12px 22px;
  background: var(--panelBackground);
  border-radius: var(--radiusL);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  font-size: 15px;
  font-weight: 600;
}

#toast-stack {
  position: absolute;
  right: 14px;
  bottom: 34px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 30;
  pointer-events: none;
  max-width: 390px;
}
.toast {
  padding: 9px 13px;
  background: var(--panelBackground);
  border: 1px solid var(--Color5);
  border-left: 3px solid var(--Color1);
  border-radius: var(--radiusM);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  font-size: 12px;
  animation: toast-in .16s ease;
  pointer-events: auto;
  user-select: text;
}
.toast.error { border-left-color: var(--errorColor); }
.toast.warn { border-left-color: var(--warnColor); }
.toast.ok { border-left-color: var(--okColor); }
.toast .t-title { font-weight: 600; margin-bottom: 2px; }
.toast .t-detail { color: var(--textDim); font-size: 11px; word-break: break-word; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ===========================================================================
   Attributes / analysis panel
   =========================================================================== */

.attr-section { padding: 9px 12px; border-bottom: 1px solid var(--Color6); }
.attr-section h4 {
  margin: 0 0 6px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--textDim);
  font-weight: 600;
}
.attr-table { width: 100%; border-collapse: collapse; user-select: text; }
.attr-table td {
  padding: 3px 4px;
  vertical-align: top;
  border-bottom: 1px solid #f2f4f6;
  word-break: break-word;
}
.attr-table td:first-child { color: var(--textDim); width: 42%; }
.attr-table td:last-child { font: 11px var(--mono); }

/* Terrain-profile chart */
.profile-chart { width: 100%; height: 190px; display: block; background: var(--Color7); border: 1px solid var(--Color5); border-radius: var(--radiusM); }
.profile-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin-top: 8px; }
.profile-stat { background: var(--panelAlt); border: 1px solid var(--Color6); border-radius: var(--radiusM); padding: 5px 8px; }
.profile-stat b { display: block; font: 12px var(--mono); color: var(--textColor); }
.profile-stat span { font-size: 10px; color: var(--textDim); text-transform: uppercase; letter-spacing: .04em; }

/* ===========================================================================
   Status bar
   =========================================================================== */

#status-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--panelAlt);
  border-top: 1px solid var(--Color5);
  font-size: 11px;
  color: var(--textDim);
}
#status-bar .spacer { flex: 1; }
.mono { font: 10.5px var(--mono); color: var(--textDim); }

/* ===========================================================================
   Modal
   =========================================================================== */

#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(32, 36, 39, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#modal-backdrop[hidden] { display: none; }
#modal {
  width: 470px;
  max-width: 90vw;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--panelBackground);
  border: 1px solid var(--Color5);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
#modal-body { padding: 12px; overflow-y: auto; display: grid; gap: 10px; }
#modal-body label { display: grid; gap: 4px; font-size: 11px; color: var(--textDim); }
#modal-body input, #modal-body select, #modal-body textarea {
  padding: 6px 8px;
  background: var(--Color7);
  border: 1px solid #c8cdd2;
  border-radius: var(--radiusM);
  color: var(--textColor);
  font: inherit;
  user-select: text;
  outline: none;
}
#modal-body input:focus, #modal-body select:focus { border-color: var(--Color1); }
#modal-body .hint { font-size: 10.5px; color: var(--textDim); line-height: 1.45; }
#modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--Color5);
  background: var(--panelAlt);
}
.btn {
  padding: 5px 16px;
  background: var(--buttonBackground);
  border: 1px solid var(--Color5);
  border-radius: var(--radiusM);
  color: var(--textColor);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}
.btn:hover { background: var(--hoverFill); border-color: var(--hoverBorder); }
.btn.primary { background: var(--Color1); border-color: var(--Color1); color: #fff; }
.btn.primary:hover { background: #106ebe; }

/* --- Google tool result badges ------------------------------------------- */
.g-badge {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 13px;
  margin-bottom: 9px;
  background: var(--badge, var(--Color1));
  border-radius: var(--radiusL);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.g-badge b { font-size: 22px; font-weight: 600; line-height: 1; }
.g-badge span { font-size: 11.5px; opacity: .95; }

/* --- Google Maps / Street View panel -------------------------------------- */
#gmap-panel {
  position: absolute;
  right: 14px;
  bottom: 40px;
  width: 420px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  background: var(--panelBackground);
  border: 1px solid var(--Color5);
  border-radius: var(--radiusL);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .35);
  overflow: hidden;
}
.gmap-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 11px;
  background: var(--panelAlt);
  border-bottom: 1px solid var(--Color5);
  font-size: 12px;
}
.gmap-head b { font-weight: 600; }
.gmap-head .gmap-mode { flex: 1; font-size: 10.5px; color: var(--textDim); }
.gmap-canvas { height: 300px; background: var(--panelAlt); }
.gmap-status { padding: 8px 11px; font-size: 11.5px; color: var(--textDim); }

/* --- Places results ------------------------------------------------------- */
.place-form { display: grid; gap: 7px; margin-bottom: 8px; }
.place-form input[type=text] {
  padding: 6px 9px;
  background: var(--Color7);
  border: 1px solid #c8cdd2;
  border-radius: var(--radiusM);
  color: var(--textColor);
  font: inherit;
  user-select: text;
  outline: none;
}
.place-form input[type=text]:focus { border-color: var(--Color1); }
.place-row-inline { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--textDim); }
.place-row-inline input[type=number] {
  width: 84px;
  padding: 4px 7px;
  background: var(--Color7);
  border: 1px solid #c8cdd2;
  border-radius: var(--radiusM);
  color: var(--textColor);
  font: inherit;
  user-select: text;
}
.place-row-inline .btn { margin-left: auto; }
.place-row {
  padding: 7px 9px;
  border-bottom: 1px solid #f2f4f6;
  cursor: pointer;
  user-select: text;
}
.place-row:hover { background: var(--hoverFill); }
.place-row b { display: block; font-size: 12.5px; font-weight: 600; }
.place-row span { display: block; font-size: 11px; color: var(--textDim); margin-top: 1px; }
.place-row small { display: block; font-size: 10.5px; color: var(--textFaint); margin-top: 2px; }
