/* ============ Variables de tema ============ */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --border: #dbe1e6;
  --text: #1c2530;
  --text-muted: #64707c;
  --primary: #1a73c7;
  --primary-hover: #155a9e;
  --green: #1e8e4c;
  --green-bg: #e3f6ea;
  --yellow: #a8720b;
  --yellow-bg: #fff4d9;
  --red: #c22b2b;
  --red-bg: #fde3e3;
  --gray-bg: #eceef0;

  /* Anchos de columna fijos (versión PC) — editables aquí */
  --w-service: 170px;
  --w-locality: 120px;
  --w-freq: 70px;
  --w-freqrx: 70px;
  --w-mode: 70px;
  --w-enc: 70px;
  --w-key: 110px;
  --w-cc: 50px;
  --w-tg: 130px;
  --w-rid: 100px;
  --w-subtone: 90px;
  --w-sites: 150px;
  --w-lastrx: 155px;
  --w-notes: 180px;
  --w-location: 140px;
  --w-site: 140px;
  --w-fid: 70px;
  --w-actions: 90px;
}

html[data-theme="dark"] {
  --bg: #0f1418;
  --surface: #161c22;
  --surface-alt: #1c242b;
  --border: #2b343c;
  --text: #e4e9ed;
  --text-muted: #93a0ab;
  --primary: #4da3ff;
  --primary-hover: #79bcff;
  --green: #4fd485;
  --green-bg: #123322;
  --yellow: #e3b04b;
  --yellow-bg: #3a2f0f;
  --red: #ff6b6b;
  --red-bg: #3a1414;
  --gray-bg: #232b32;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ============ Topbar ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.role-badge { padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.role-master { background: var(--green-bg); color: var(--green); }
.role-badge.role-viewer { background: var(--gray-bg); color: var(--text-muted); }

/* ============ Toolbar ============ */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 12px 20px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; position: relative; }
.toolbar-group-right { margin-left: auto; }
#search-box {
  min-width: 220px;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.checkbox-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

/* ============ Botones ============ */
.btn {
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border: none; }
.toggle-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-mini { padding: 4px 8px; font-size: 12px; }
.btn-add-mini { padding: 4px 8px; cursor: pointer; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); }

/* ============ Dropdown de filtro de emplazamientos ============ */
.dropdown-panel {
  position: absolute;
  top: 36px;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  min-width: 220px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 6px 18px rgba(0,0,0,.15);
}
.dropdown-panel label { display: flex; gap: 6px; align-items: center; padding: 4px 2px; font-size: 13px; }
.hidden { display: none !important; }

/* ============ Tabla ============ */
/* El contenedor tiene su propio scroll (vertical y horizontal) para que la cabecera
   quede siempre fija arriba mientras se hace scroll por la lista de frecuencias. */
.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 118px);
}
.freq-table { border-collapse: collapse; width: 100%; min-width: 1400px; background: var(--surface); }
.freq-table th, .freq-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 12.5px;
}
.freq-table th {
  background: var(--surface-alt);
  position: sticky;
  top: 0;
  z-index: 5;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--text-muted);
  white-space: nowrap;
}
.col-service { width: var(--w-service); }
.col-locality { width: var(--w-locality); }
.col-freq { width: var(--w-freq); }
.col-freqrx { width: var(--w-freqrx); }
.col-mode { width: var(--w-mode); }
.col-enc { width: var(--w-enc); }
.col-key { width: var(--w-key); }
.col-cc { width: var(--w-cc); }
.col-tg { width: var(--w-tg); }
.col-rid { width: var(--w-rid); }
.col-subtone { width: var(--w-subtone); }
.col-sites { width: var(--w-sites); }
.col-lastrx { width: var(--w-lastrx); }
.col-notes { width: var(--w-notes); }
.col-location { width: var(--w-location); }
.col-site { width: var(--w-site); }
.col-fid { width: var(--w-fid); }
.col-actions { width: var(--w-actions); }

.loading-row { text-align: center; padding: 30px; color: var(--text-muted); }

.freq-row td { cursor: default; }
.freq-row.is-obsolete { opacity: .55; }

.offset-badge { font-size: 11px; color: var(--text-muted); display: block; }
.freq-alias { border-bottom: 1px dotted var(--text-muted); cursor: help; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--gray-bg);
  color: var(--text-muted);
  margin: 1px 2px 1px 0;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gray { background: var(--gray-bg); color: var(--text-muted); }

.site-chip { background: var(--gray-bg); border-radius: 8px; padding: 1px 6px; font-size: 11px; margin: 1px; display: inline-block; }

.lastrx-cell { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.btn-today-row { padding: 2px 6px; font-size: 11px; cursor: pointer; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); }

.link-btn {
  background: none; border: none; color: var(--primary); cursor: pointer;
  padding: 0; font-size: 12px; text-decoration: underline;
}
.icon-link-btn {
  background: none; border: none; cursor: pointer; padding: 0 2px; font-size: 14px; line-height: 1;
}
.small-muted { color: var(--text-muted); font-size: 11px; }
.maps-link { color: var(--primary); text-decoration: none; }
.maps-link:hover { text-decoration: underline; }
.notes-cell { cursor: help; }
.row-flash { animation: row-flash-anim 2.5s ease-out; }
@keyframes row-flash-anim {
  0%   { background-color: var(--primary); }
  100% { background-color: transparent; }
}
.dropdown-filter-search {
  width: 100%; padding: 5px 7px; margin-bottom: 6px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 12.5px;
  box-sizing: border-box;
}
/* El filtro de rangos tiene una cantidad fija y pequeña de opciones: le damos altura de sobra
   para que nunca necesite su propio scroll interno. */
#range-filter-panel { max-height: 340px; }

.actions-cell { display: flex; gap: 4px; }
.icon-btn { border: none; background: none; cursor: pointer; font-size: 14px; padding: 2px 4px; }

/* ============ Responsive: ocultar columnas en móvil ============ */
@media (max-width: 820px) {
  .hide-mobile { display: none !important; }
  .freq-table { min-width: 0; }
}

/* ============ Columna Acciones para el Visor: solo aparece si hay puente SDR conectado
   (lo único que puede hacer ahí es "Enviar a SDR"; sin puente sería una columna vacía) ============ */
.freq-table.is-viewer:not(.sdr-on) .col-actions { display: none; }

/* ============ Columna UID: oculta salvo que se marque el checkbox "Mostrar UID" ============ */
.freq-table:not(.show-uid) .col-fid { display: none !important; }

/* ============ Modales ============ */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 30px 12px; overflow-y: auto; z-index: 100;
}
.modal-box {
  background: var(--surface); border-radius: 10px; width: 100%;
  max-width: 480px; box-shadow: 0 12px 34px rgba(0,0,0,.25);
}
.modal-lg { max-width: 720px; }
.modal-md { max-width: 620px; }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-close { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 16px 18px; max-height: 65vh; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-muted); }
.form-grid label input, .form-grid label select, .form-grid label textarea {
  font-size: 13px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: inherit;
}
.form-grid .full-row { grid-column: 1 / -1; }
.select-with-add { display: flex; gap: 4px; }
.select-with-add select { flex: 1; }
.input-with-btn { display: flex; gap: 6px; }
.input-with-btn input { flex: 1; }

.fieldset { margin: 14px 0; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.fieldset legend { padding: 0 6px; font-size: 12px; color: var(--text-muted); }
.key-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.key-row input { flex: 1; padding: 5px 7px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.key-row input.keyid-input { flex: 0 0 60px; }
.key-row input[type="color"], .input-with-btn input[type="color"] { flex: 0 0 44px; padding: 2px; height: 30px; cursor: pointer; }

.mini-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; table-layout: fixed; }
.mini-table th, .mini-table td { border: 1px solid var(--border); padding: 5px 6px; font-size: 12.5px; }
.mini-table input { width: 100%; padding: 4px 5px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); color: var(--text); box-sizing: border-box; }
.mini-table .col-notes-wide { width: 32%; }
.mini-table .col-name-wide { width: 26%; }
.mini-table .col-narrow { width: 13%; }
.mini-table .col-mini-action { width: 30px; }

.checkbox-list label { display: flex; align-items: center; gap: 8px; padding: 5px 2px; font-size: 13px; }
.plain-list { list-style: none; padding: 0; margin: 6px 0; max-height: 160px; overflow-y: auto; }
.plain-list li { padding: 4px 6px; border-bottom: 1px solid var(--border); font-size: 13px; }

.form-error { color: var(--red); font-size: 12px; margin-top: 6px; }

/* ============ Login ============ */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg); }
.login-box { background: var(--surface); padding: 32px; border-radius: 12px; width: 320px; box-shadow: 0 10px 30px rgba(0,0,0,.12); text-align: center; }
.login-box h1 { font-size: 18px; margin-bottom: 4px; }
.login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }
.login-box form { display: flex; flex-direction: column; gap: 10px; }
.login-box input { padding: 9px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--text); }
.login-error { color: var(--red); font-size: 13px; }
.login-hint { color: var(--text-muted); font-size: 11px; margin-top: 16px; }
