:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --text: #202124;
  --muted: #5f6368;
  --border: #e0e3e8;
  --primary: #0b57d0;
  --nav-active-bg: #d3e3fd;
  --nav-active-text: #041e49;
  --hover: #eaf1fb;
  --ok: #137333;
  --ok-bg: #e6f4ea;
  --alert: #c5221f;
  --alert-bg: #fce8e6;
  --warn: #b06000;
  --warn-bg: #fef7e0;
  --r-pill: 20px;
  --r-panel: 16px;
  --r-input: 8px;
  --h-control: 36px;
  --h-header: 56px;
  --nav-w: 200px;
  --aside-w: 280px;
  --font: "Roboto", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--primary);
  text-decoration: none;
}

#app {
  min-height: 100%;
}

.hidden {
  display: none !important;
}

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(450px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  padding: 36px 32px 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.isotipo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(145deg, #0b57d0, #4c8df6);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
}

.login-sub {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.input,
.select,
.textarea {
  height: var(--h-control);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  padding: 0 12px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.textarea {
  height: auto;
  min-height: 72px;
  padding: 10px 12px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--h-control);
  padding: 0 16px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover {
  background: var(--hover);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: #0842a0;
  color: #fff;
}

.btn-outline {
  border-color: var(--border);
  background: var(--surface);
}

.btn-ghost {
  color: var(--muted);
}

.btn-danger {
  color: var(--alert);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

.login-error {
  color: var(--alert);
  font-size: 13px;
  margin: 0 0 10px;
  min-height: 18px;
}

/* ---- Shell ---- */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: var(--h-header) 1fr;
}

.topbar {
  height: var(--h-header);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 12px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 15px;
}

.brand .isotipo {
  width: 32px;
  height: 32px;
  font-size: 13px;
  border-radius: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 12px;
}

.body-grid {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr var(--aside-w);
  min-height: calc(100vh - var(--h-header));
}

.nav-col {
  padding: 12px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-right: 1px solid transparent;
  background: var(--bg);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 16px 10px 20px;
  border-radius: 0 24px 24px 0;
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
}

.nav-item:hover {
  background: var(--hover);
}

.nav-item.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
}

.nav-item .icon {
  width: 18px;
  text-align: center;
  opacity: 0.85;
}

.nav-bottom {
  margin-top: auto;
  padding: 12px 12px 0 16px;
}

.nav-bottom h3 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 500;
}

.operario-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  font-size: 12px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c4c7c5;
  flex-shrink: 0;
}

.dot.online {
  background: var(--ok);
}

.main-col {
  padding: 12px 16px 24px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar .grow {
  flex: 1;
  min-width: 160px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  padding: 16px;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 500;
}

.aside-col {
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.aside-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.aside-head h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 500;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}

.bubble {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.35;
}

.bubble.in {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}

.bubble.out {
  align-self: flex-end;
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
}

.bubble time {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  color: var(--muted);
}

.composer {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--border);
}

.composer .input {
  flex: 1;
}

/* ---- KPIs ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  padding: 14px 16px;
}

.kpi-card .label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.kpi-card .value {
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.kpi-card .hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.bar-chart {
  width: 100%;
  height: 220px;
}

.bar-chart .bar {
  fill: var(--primary);
  opacity: 0.85;
}

.bar-chart .axis {
  fill: var(--muted);
  font-size: 10px;
  font-family: var(--font);
}

/* ---- Table ---- */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 220px);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  background: var(--surface);
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

table.data th,
table.data td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

table.data th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8f9fa;
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
}

table.data tbody tr:nth-child(even) {
  background: #fafbfc;
}

table.data tbody tr:hover {
  background: var(--hover);
}

table.data th.actions,
table.data td.actions {
  position: sticky;
  right: 0;
  background: inherit;
  z-index: 1;
  box-shadow: -4px 0 8px rgba(32, 33, 36, 0.04);
}

table.data th.actions {
  background: #f8f9fa;
  z-index: 3;
}

table.data td.actions {
  background: var(--surface);
}

table.data tbody tr:nth-child(even) td.actions {
  background: #fafbfc;
}

table.data tbody tr:hover td.actions {
  background: var(--hover);
}

.actions-cell {
  display: flex;
  gap: 4px;
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge-alert {
  background: var(--alert-bg);
  color: var(--alert);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge-muted {
  background: #eef0f2;
  color: var(--muted);
}

/* ---- Evidence cards ---- */
.ev-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.ev-card {
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.ev-photo {
  position: relative;
  aspect-ratio: 4/3;
  background: #e8eaed;
  cursor: zoom-in;
}

.ev-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ev-photo.ev-sin-foto {
  cursor: default;
  background: var(--warn-bg);
}

.ev-placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--warn);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}

.ev-placeholder-icon {
  font-size: 26px;
  line-height: 1;
}

.ev-overlay {
  position: absolute;
  left: 8px;
  bottom: 8px;
  right: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.ev-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ev-body h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
}

.ev-body p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.ev-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

/* ---- Map ---- */
#map {
  height: 420px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(32, 33, 36, 0.6);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  width: min(520px, 100%);
  background: var(--surface);
  border-radius: var(--r-panel);
  border: 1px solid var(--border);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.modal.wide {
  width: min(860px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

.modal-body {
  padding: 16px;
}

.modal-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal img.zoom {
  width: 100%;
  border-radius: 8px;
  display: block;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-row.one {
  grid-template-columns: 1fr;
}

.empty {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
}

.config-grid {
  display: grid;
  gap: 14px;
  max-width: 560px;
}

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

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #202124;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--r-pill);
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show {
  opacity: 1;
}

/* ---- Agente orquestador (chat flotante) ---- */
.agent-root {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.agent-fab,
.agent-panel,
.agent-composer,
.agent-icon-btn {
  pointer-events: auto;
}

.agent-fab {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  border: none;
  background: var(--primary, #1a73e8);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(26, 115, 232, 0.35);
}

.agent-fab.is-open {
  width: 44px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.agent-fab:hover {
  filter: brightness(1.05);
}

.agent-panel {
  width: min(380px, calc(100vw - 24px));
  height: min(520px, calc(100vh - 100px));
  background: #fff;
  border: 1px solid var(--border, #dadce0);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.agent-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border, #dadce0);
  background: linear-gradient(180deg, #f8fbff 0%, #fff 100%);
}

.agent-head-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.agent-head-text strong {
  font-size: 14px;
}

.agent-head-text span {
  font-size: 12px;
  color: var(--muted, #5f6368);
}

.agent-icon-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #5f6368;
  padding: 0 4px;
}

.agent-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fafafa;
}

.agent-empty {
  font-size: 12px;
  color: var(--muted, #5f6368);
  line-height: 1.5;
}

.agent-bubble {
  max-width: 92%;
  padding: 8px 11px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-bubble.user {
  align-self: flex-end;
  background: #e8f0fe;
  color: #174ea6;
}

.agent-bubble.assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border, #dadce0);
  color: #202124;
}

.agent-composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border, #dadce0);
  background: #fff;
}

.agent-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border, #dadce0);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  min-height: 42px;
}

.agent-input:disabled {
  opacity: 0.7;
}

@media (max-width: 640px) {
  .agent-root {
    left: 50%;
    right: auto;
    bottom: 12px;
    transform: translateX(-50%);
    align-items: center;
    width: min(100% - 24px, 380px);
  }

  .agent-fab {
    align-self: center;
  }

  .agent-panel {
    width: 100%;
    height: min(70vh, 560px);
  }
}

@media (max-width: 1100px) {
  .body-grid {
    grid-template-columns: 1fr;
  }

  .nav-col {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
  }

  .nav-list {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0 8px;
    width: 100%;
  }

  .nav-item {
    border-radius: 24px;
    padding: 8px 14px;
  }

  .nav-bottom {
    width: 100%;
    margin-top: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    align-items: center;
  }

  .nav-bottom h3 {
    width: 100%;
  }

  .aside-col {
    border-left: 0;
    border-top: 1px solid var(--border);
    min-height: 320px;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .dash-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .brand span {
    display: none;
  }
}
