/* ============================================================================
   Réplica local · Identidad visual de Vector GPS
   Referencia: GUIA_ESTILOS_UI.md (patrón "Torre de control" + paneles heredados)
   ============================================================================ */

:root {
  --v-primary: #0f8995;
  --v-primary-border: #0d7d88;
  --v-primary-dark: #0a6670;
  --v-primary-tint: #e6f4f5;
  --v-primary-ring: rgba(15, 137, 149, .18);
  --v-info: #17a2b8;
  --v-success: #28a745;
  --v-success-dark: #1e8a37;
  --v-warning: #ffc107;
  --v-danger: #dc3545;
  --v-danger-dark: #bd2130;

  --v-page: #eef2f5;
  --v-surface: #ffffff;
  --v-carbon: #343a40;
  --v-text: #26313d;
  --v-title: #1f2a35;
  --v-muted: #607080;
  --v-label: #485664;
  --v-th-bg: #f4f7f9;
  --v-th-text: #536171;
  --v-input-bg: #f9fbfc;
  --v-input-border: #bfcbd6;
  --v-border: #cfd9e2;
  --v-border-soft: #e1e8ee;
  --v-segment: #f7f9fb;

  --v-shadow-card: 0 3px 12px rgba(31, 45, 61, .06);
  --v-shadow-hero: 0 8px 24px rgba(31, 45, 61, .08);
  --v-shadow-pop: 0 12px 24px rgba(26, 36, 44, .22);
}

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

html, body {
  margin: 0;
  background: var(--v-page);
  color: var(--v-text);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 13px;
  line-height: 1.45;
}

h1, h2, h3, h4, p { margin: 0; }
strong { font-weight: 700; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body.modal-open { overflow: hidden; }

main > * { min-width: 0; }

/* ============================================================================
   Hero (encabezado moderno)
   ============================================================================ */

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 14px 16px;
  background: var(--v-surface);
  border: 1px solid var(--v-border);
  border-left: 4px solid var(--v-primary);
  border-radius: 8px;
  box-shadow: var(--v-shadow-hero);
}

.eyebrow {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--v-primary);
}

.hero h1,
.hero .hero-heading {
  font-size: 22.7px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--v-title);
}

.hero-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--v-muted);
}

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

/* ============================================================================
   Botones
   ============================================================================ */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 34px;
  padding: 5px 12px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--v-label);
  background: var(--v-surface);
  border: 1px solid var(--v-input-border);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

button:hover:not(:disabled) {
  color: var(--v-primary);
  border-color: var(--v-primary);
  background: var(--v-primary-tint);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--v-primary);
  outline-offset: 2px;
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* Primario: turquesa */
:is(#create, #save, #saveGroup) {
  color: #fff;
  background: var(--v-primary);
  border-color: var(--v-primary-border);
}
:is(#create, #save, #saveGroup):hover:not(:disabled) {
  color: #fff;
  background: var(--v-primary-dark);
  border-color: var(--v-primary-dark);
}

/* Secundario con acento turquesa (solo habilitado) */
:is(#edit):not(:disabled) {
  color: var(--v-primary);
  border-color: var(--v-primary);
}

/* Peligro suave (barra de herramientas) */
:is(#remove):not(:disabled) {
  color: var(--v-danger);
  border-color: #e3a0a8;
  background: #fff5f6;
}
:is(#remove):hover:not(:disabled) {
  color: #fff;
  background: var(--v-danger);
  border-color: var(--v-danger);
}

/* Peligro lleno (confirmaciones) */
:is(#confirmDelete, #confirmGroupDelete) {
  color: #fff;
  background: var(--v-danger);
  border-color: var(--v-danger);
}
:is(#confirmDelete, #confirmGroupDelete):hover:not(:disabled) {
  color: #fff;
  background: var(--v-danger-dark);
  border-color: var(--v-danger-dark);
}

/* Descarga: verde */
:is(#excel) {
  color: #fff;
  background: var(--v-success);
  border-color: var(--v-success);
}
:is(#excel):hover:not(:disabled) {
  color: #fff;
  background: var(--v-success-dark);
  border-color: var(--v-success-dark);
}

/* ============================================================================
   Tarjetas / paneles (encabezado carbón de la interfaz heredada)
   ============================================================================ */

:is(#editor) {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 0 14px;
  background: var(--v-surface);
  border: 1px solid var(--v-border);
  border-radius: 8px;
  box-shadow: var(--v-shadow-card);
  overflow: hidden;
}

:is(#editor) > :is(h2, .card-title),
:is(#editor)::before,
:is(#coverageGridHeading > h2) {
  display: block;
  margin: 0;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
  color: #fff;
  background: var(--v-carbon);
  border-bottom: 3px solid var(--v-primary);
}

:is(#editor) > :not(h2):not(.card-title) { margin-inline: 14px; }

/* ============================================================================
   Formularios
   ============================================================================ */

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--v-label);
}

label:has(> input[type="checkbox"]),
label:has(> input[type="radio"]),
.check-line {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--v-text);
  cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--v-primary);
  cursor: pointer;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select {
  width: 100%;
  min-height: 34px;
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
  font-weight: 400;
  color: var(--v-text);
  background-color: var(--v-input-bg);
  border: 1px solid var(--v-input-border);
  border-radius: 6px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input[type="file"] { font-size: 12px; color: var(--v-text); }

input::placeholder { color: #8b98a5; }

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus {
  outline: none;
  border-color: var(--v-primary);
  box-shadow: 0 0 0 3px var(--v-primary-ring);
}

input[aria-invalid="true"] { border-color: var(--v-danger); box-shadow: 0 0 0 3px rgba(220, 53, 69, .12); }

input:disabled, select:disabled, input[readonly] {
  color: #7d8a97;
  background-color: #f1f4f6;
}
input:disabled, select:disabled { cursor: not-allowed; }

select:not([size]):not([multiple]) {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%230f8995' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
  cursor: pointer;
}

select[size], select[multiple] {
  min-height: 118px;
  padding: 4px;
  background-image: none;
}
select[size] option, select[multiple] option { padding: 3px 6px; border-radius: 4px; }
select[size] option:checked, select[multiple] option:checked { color: #fff; background: var(--v-primary); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px 14px;
}
.form-grid .wide { grid-column: 1 / -1; }

fieldset {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  margin: 0;
  padding: 10px 12px 12px;
  background: var(--v-segment);
  border: 1px solid var(--v-border);
  border-radius: 8px;
}
fieldset fieldset { background: var(--v-surface); }

legend {
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--v-primary);
}

fieldset h3 { font-size: 12.5px; font-weight: 700; color: var(--v-title); }

.form-actions, .dialog-actions, .actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}
.form-actions, form > .actions, .editor .actions {
  padding-top: 12px;
  border-top: 1px solid var(--v-border-soft);
}

/* Listas de transferencia (Disponibles / Asignados) */
.transfer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: 8px 12px;
}
.transfer > .search-label,
.transfer > .transfer-wide { grid-column: 1 / -1; }

.transfer-pane, .transfer-list { display: flex; flex-direction: column; gap: 4px; }
.transfer-list { color: var(--v-title); }

.transfer-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 22px;
}
.transfer-controls button {
  min-width: 42px;
  min-height: 30px;
  padding: 2px 8px;
  font-size: 14px;
  color: var(--v-primary);
  border-color: var(--v-primary);
  background: var(--v-surface);
}

/* ============================================================================
   Mensajes
   ============================================================================ */

.message, .info, .form-result, .form-error:not(:empty) {
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 6px;
  border-left: 4px solid transparent;
}

.message.error, .form-error:not(:empty) {
  color: #8a1c27;
  background: rgba(220, 53, 69, .09);
  border-color: var(--v-danger);
}

.info {
  color: #0c5460;
  background: rgba(23, 162, 184, .11);
  border-color: var(--v-info);
}

.form-result {
  color: #155724;
  background: rgba(40, 167, 69, .11);
  border-color: var(--v-success);
}
.form-result.error {
  color: #8a1c27;
  background: rgba(220, 53, 69, .09);
  border-color: var(--v-danger);
}

.inline-error, .field-error, .error:not(.message):not(#status):not(#status-message) {
  display: block;
  min-height: 0;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--v-danger);
}
.inline-error:empty, .field-error:empty, .error:empty { display: none; }

/* Notificación de estado (toast) */
:is(#status) {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1100;
  width: min(380px, calc(100vw - 32px));
  padding: 10px 14px;
  font-size: 12.5px;
  color: #155724;
  background: #f1faf3;
  border: 1px solid #b9e3c3;
  border-left: 4px solid var(--v-success);
  border-radius: 8px;
  box-shadow: var(--v-shadow-pop);
}
:is(#status):empty { display: none; }
:is(#status).error {
  color: #8a1c27;
  background: #fff5f6;
  border-color: #f0b8bf;
  border-left-color: var(--v-danger);
}
:is(#status) .status-title { display: block; margin-bottom: 2px; font-weight: 700; }

/* ============================================================================
   Tablas
   ============================================================================ */

.table-wrap, .table-scroll, .table-viewport, .command-wrap {
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  background: var(--v-surface);
}

th {
  padding: 6.7px 8px;
  font-size: 11.5px;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
  color: var(--v-th-text);
  background: var(--v-th-bg);
  border-bottom: 2px solid var(--v-border);
}

td {
  padding: 8px;
  vertical-align: middle;
  color: var(--v-text);
  border-bottom: 1px solid var(--v-border-soft);
}

tbody tr:nth-child(even) { background: #fafcfd; }

tbody tr[aria-selected], tbody tr.data-row, tbody tr.driver-row { cursor: pointer; transition: background 120ms ease; }
tbody tr[aria-selected]:hover, tbody tr.data-row:hover, tbody tr.driver-row:hover { background: rgba(15, 137, 149, .07); }
tbody tr[aria-selected="true"], tbody tr.selected {
  background: var(--v-primary-tint);
  box-shadow: inset 4px 0 0 var(--v-primary);
}
tbody tr[aria-selected="true"] td, tbody tr.selected td { color: var(--v-title); font-weight: 600; }

tr:focus-visible { outline: 2px solid var(--v-primary); outline-offset: -2px; }

th button {
  min-height: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 4px;
}
th button:hover:not(:disabled) { color: var(--v-primary); background: transparent; border: 0; }

.sort-indicator, .sort-arrow { font-size: 10px; color: var(--v-primary); }

.column-menu-button {
  width: 22px;
  height: 22px;
  min-height: 0;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--v-muted);
  background: transparent;
  border: 0;
}
.column-menu-button:hover:not(:disabled) { color: var(--v-primary); background: rgba(15, 137, 149, .12); border: 0; }

th[aria-sort] { color: var(--v-primary-dark); background: #e9f3f4; }

/* Menús emergentes de columnas (posicionados por JS con coordenadas de viewport) */
:is(.coverage-column-menu) {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 210px;
  padding: 6px;
  background: var(--v-surface);
  border: 1px solid var(--v-border);
  border-radius: 8px;
  box-shadow: var(--v-shadow-pop);
}
:is(.coverage-column-menu) button {
  justify-content: flex-start;
  width: 100%;
  min-height: 30px;
  font-weight: 500;
  color: var(--v-text);
  background: transparent;
  border-color: transparent;
}
:is(.coverage-column-menu) button:hover:not(:disabled) { color: var(--v-primary); background: var(--v-primary-tint); border-color: transparent; }
:is(.coverage-column-menu) hr, .menu-separator { width: 100%; height: 0; margin: 4px 0; border: 0; border-top: 1px solid var(--v-border-soft); }
:is(.coverage-column-menu) label { padding: 4px 8px; border-radius: 6px; font-weight: 500; color: var(--v-text); }
:is(.coverage-column-menu) label:hover { background: var(--v-primary-tint); }

/* ============================================================================
   Diálogos
   ============================================================================ */

dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 18px 18px 14px;
  overflow: auto;
  color: var(--v-text);
  background: var(--v-surface);
  border: 1px solid var(--v-border);
  border-top: 4px solid var(--v-primary);
  border-radius: 8px;
  box-shadow: var(--v-shadow-pop);
}
dialog[open] { display: flex; flex-direction: column; gap: 10px; }
dialog::backdrop { background: rgba(26, 36, 44, .5); }
dialog > h2, .dialog-head h2 { font-size: 16px; font-weight: 700; color: var(--v-title); }
dialog > p { font-size: 13.5px; }
dialog .dialog-actions, dialog .actions { margin-top: 6px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dialog-head button { min-height: 28px; padding: 0 9px; font-size: 18px; line-height: 1; }

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 700px) {
  .hero { flex-direction: column; align-items: stretch; }
  .toolbar button { flex: 1 1 auto; }
  .transfer { grid-template-columns: 1fr; }
  .transfer-controls { flex-direction: row; margin-top: 0; }
  .transfer-controls button { flex: 1; }
  .form-actions button, .dialog-actions button, .actions button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================================================================
   Coberturas
   ============================================================================ */

#app {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100vh;
  padding: 14px 14px 44px;
}

#create::before { content: none; font-size: 16px; font-weight: 700; line-height: 1; }

#editor::before { content: none; }

.identity, .group-identity {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px 14px;
}

.subactions { display: flex; flex-wrap: wrap; gap: 6px; }
.subactions button {
  min-height: 30px;
  font-size: 12px;
  color: var(--v-primary);
  border-color: var(--v-primary);
}

.command-transfer {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px 14px;
}
.command-caption { font-weight: 700; color: var(--v-title); }

/* Encabezado + cuadrícula de coberturas */
#coverageGridHeading, #grid {
  background: var(--v-surface);
  border: 1px solid var(--v-border);
  box-shadow: var(--v-shadow-card);
}
#coverageGridHeading {
  margin-bottom: -10px;
  overflow: hidden;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}
#coverageGridHeading > h2 { margin: 0; }

.grid-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--v-border-soft);
}
.grid-tools .search-field { margin: 0; }
#search {
  width: min(280px, 100%);
  padding-left: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23607080' stroke-width='2.2' stroke-linecap='round' d='M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zm9 16-4.2-4.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 9px center;
  background-size: 16px;
}
#excel { min-width: 40px; font-size: 16px; }

#grid {
  overflow-x: auto;
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

.headers, .row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(150px, 1fr);
}

.headers {
  background: var(--v-th-bg);
  border-bottom: 2px solid var(--v-border);
}

.coverage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
  padding: 6.7px 8px;
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
  color: var(--v-th-text);
}
.coverage-head[aria-sort] { color: var(--v-primary-dark); background: #e9f3f4; }

.sort-label {
  display: inline-flex;
  align-items: center;
  min-height: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
}
.sort-label:hover:not(:disabled) { color: var(--v-primary); background: transparent; border: 0; }
.sort-arrow { margin-left: 5px; }

.row {
  cursor: pointer;
  border-bottom: 1px solid var(--v-border-soft);
  transition: background 120ms ease;
}
.row > [data-column] {
  min-width: 0;
  padding: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--v-text);
}
#rows > .row:nth-child(even) { background: #fafcfd; }
.row:hover { background: rgba(15, 137, 149, .07) !important; }
.row.selected {
  background: var(--v-primary-tint) !important;
  box-shadow: inset 4px 0 0 var(--v-primary);
}
.row.selected > [data-column] { color: var(--v-title); font-weight: 600; }
.row:focus-visible { outline: 2px solid var(--v-primary); outline-offset: -2px; }

.coverage-columns-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
  padding-top: 4px;
  border-top: 1px solid var(--v-border-soft);
}

#confirm, #groupDeleteDialog { border-top-color: var(--v-danger); }
#groupDialog { width: min(640px, calc(100vw - 32px)); }
#editor[hidden]::before { display: none; }

@media (max-width: 700px) {
  #app { padding: 8px 8px 32px; }
}