:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #182126;
  --muted: #667078;
  --line: #d9d0c3;
  --accent: #237f83;
  --danger: #c74338;
  --warn: #d99028;
  --good: #2f8f56;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  width: 100vw;
  height: 100dvh;
  min-height: 640px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(330px, 24vw, 400px);
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
}

.title-block {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: clamp(20px, 1.6vw, 28px);
  line-height: 1.15;
  letter-spacing: 0;
}

.title-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.view-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.view-switch button {
  width: 48px;
  min-height: 36px;
  border: 0;
  background: transparent;
  font-weight: 720;
}

.view-switch button.active {
  background: var(--accent);
  color: #ffffff;
}

.clock {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.clock strong {
  font-size: 21px;
  font-variant-numeric: tabular-nums;
}

.clock span {
  color: var(--good);
  font-size: 12px;
  font-weight: 720;
  white-space: nowrap;
}

.map-stage {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  background: #e9e0d4;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.map-status {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(239, 235, 226, 0.9);
  color: #344248;
  text-align: center;
}

.map-status[hidden] {
  display: none;
}

.map-status strong {
  font-size: 16px;
}

.map-status span {
  max-width: 360px;
  color: #65727a;
  font-size: 12px;
}

.map-status.error strong {
  color: var(--danger);
}

.view-label {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 9px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.82);
  color: #3c464d;
  font-size: 12px;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 7px 10px;
  max-width: calc(100% - 24px);
  padding: 9px 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.86);
  color: #293136;
  font-size: 11px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.legend i {
  width: 11px;
  height: 11px;
  border: 1px solid rgba(0, 0, 0, 0.16);
}

.side-panel {
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 14px 16px;
}

.panel-section {
  padding-bottom: 13px;
  margin-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.compact {
  padding-bottom: 12px;
  margin-bottom: 12px;
}

h2 {
  margin: 0 0 9px;
  color: #566068;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

button,
select {
  min-height: 34px;
  border: 1px solid #bfc7c7;
  background: #f8faf9;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(92px, 0.42fr) minmax(0, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.field-control {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: #2d363b;
  font-size: 12px;
}

.field-control span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.field-control output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.field-control input[type="number"] {
  width: 100%;
  min-height: 30px;
  border: 1px solid #bfc7c7;
  background: #f8faf9;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 4px 6px;
}

select {
  width: 100%;
}

.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: #46525a;
  font-size: 12px;
  font-weight: 650;
}

.inline-toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.policy-switch-notice {
  margin: 8px 0 0;
  padding: 7px 8px;
  border: 1px solid rgba(217, 144, 40, 0.42);
  background: rgba(217, 144, 40, 0.10);
  color: #6f4711;
  font-size: 11px;
  line-height: 1.35;
}

.policy-switch-notice[hidden] {
  display: none;
}

.agent-widget {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1000;
}

.agent-fab {
  width: 64px;
  height: 58px;
  min-height: 58px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 14px 34px rgba(24, 33, 38, 0.24);
  font-size: 17px;
  font-weight: 820;
  letter-spacing: 0;
}

.agent-fab:hover,
.agent-fab[aria-expanded="true"] {
  background: #1d6f72;
}

.agent-dialog {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: min(392px, calc(100vw - 32px));
  max-height: min(620px, calc(100dvh - 104px));
  display: grid;
  grid-template-rows: auto auto minmax(220px, 1fr) auto auto;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 18px 54px rgba(24, 33, 38, 0.22);
}

.agent-dialog.dragged {
  position: fixed;
}

.agent-dialog[hidden] {
  display: none;
}

.agent-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf7;
  cursor: move;
  user-select: none;
}

.agent-dialog-head div {
  min-width: 0;
}

.agent-dialog-head strong {
  display: block;
  font-size: 13px;
}

.agent-dialog-head span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.agent-dialog-head button {
  width: 30px;
  min-height: 30px;
  border: 0;
  background: transparent;
  color: #4a5359;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.agent-mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.agent-mode-tabs button {
  height: 30px;
  min-height: 30px;
  padding: 0 8px;
  border-color: var(--line);
  background: #fbfaf7;
  color: #3d474e;
  font-size: 12px;
  font-weight: 680;
}

.agent-mode-tabs button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.agent-messages {
  display: grid;
  align-content: start;
  gap: 9px;
  overflow-y: auto;
  padding: 12px;
  background: #fbfaf7;
}

.agent-message {
  display: grid;
  gap: 5px;
  max-width: 92%;
  padding: 8px 10px;
  border: 1px solid rgba(0, 0, 0, 0.07);
  background: #ffffff;
  font-size: 12px;
  line-height: 1.45;
}

.agent-message.user {
  justify-self: end;
  border-color: rgba(35, 127, 131, 0.28);
  background: #e9f4f3;
}

.agent-message.agent {
  justify-self: start;
  border-color: rgba(0, 0, 0, 0.08);
}

.agent-message strong {
  color: #3c464d;
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.agent-body {
  display: grid;
  gap: 8px;
}

.agent-body p {
  margin: 0;
}

.agent-list {
  margin: 0;
  padding-left: 16px;
}

.agent-list li + li {
  margin-top: 3px;
}

.agent-metric-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  background: #fbfaf7;
}

.agent-metric-table th,
.agent-metric-table td {
  padding: 5px 6px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  text-align: left;
  vertical-align: top;
}

.agent-metric-table th {
  width: 54%;
  color: #3c464d;
  font-weight: 700;
  background: rgba(35, 127, 131, 0.07);
}

.agent-metric-table td {
  color: #1f2930;
  font-variant-numeric: tabular-nums;
}

.agent-plan {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.agent-plan span {
  padding: 3px 6px;
  border: 1px solid rgba(35, 127, 131, 0.22);
  background: rgba(35, 127, 131, 0.08);
  color: #2e4f51;
  font-size: 11px;
}

.agent-suggestions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 10px 12px 0;
  background: #ffffff;
}

.agent-suggestions button {
  min-height: 30px;
  padding: 5px 7px;
  font-size: 11px;
}

.agent-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
  align-items: stretch;
  padding: 10px 12px 12px;
  background: #ffffff;
}

.agent-form textarea {
  width: 100%;
  min-height: 58px;
  resize: vertical;
  border: 1px solid #bfc7c7;
  background: #f8faf9;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  line-height: 1.35;
  padding: 7px 8px;
}

.agent-form button {
  min-height: 58px;
}

.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
}

.toggle-grid label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 27px;
  font-size: 13px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metrics div {
  min-height: 52px;
  padding: 8px;
  border: 1px solid var(--line);
  background: #fbfaf7;
}

.metrics span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.metrics strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.sliders {
  display: grid;
  gap: 10px;
}

.slider-row {
  display: grid;
  gap: 4px;
}

.slider-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #2d363b;
  font-size: 12px;
}

.slider-head output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.uav-list {
  display: grid;
  gap: 7px;
}

.cycle-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.event-log {
  display: grid;
  gap: 6px;
  min-height: 34px;
}

.event-log.empty {
  color: var(--muted);
  font-size: 12px;
}

.event-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  padding: 6px 7px;
  border: 1px solid var(--line);
  background: #fbfaf7;
  font-size: 11px;
  line-height: 1.35;
}

.event-row time {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 720;
}

.uav-row {
  display: grid;
  grid-template-columns: 32px 1fr 76px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.uav-row span {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.bar {
  height: 8px;
  border: 1px solid #ccd2cb;
  background: #e5e8e4;
}

.fill {
  width: 50%;
  height: 100%;
  background: var(--good);
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: 1fr;
  }

  .workspace {
    min-height: 70dvh;
  }

  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }

  .agent-widget {
    right: 14px;
    bottom: 14px;
  }

  .agent-dialog {
    bottom: 68px;
    max-height: min(560px, calc(100dvh - 92px));
  }
}

@media (max-height: 760px) {
  .app-shell {
    min-height: 600px;
  }

  .workspace,
  .side-panel {
    padding: 10px;
  }

  .title-block p,
  .legend {
    font-size: 10px;
  }

  .panel-section {
    padding-bottom: 10px;
    margin-bottom: 10px;
  }

  .metrics div {
    min-height: 46px;
  }
}
