/* Colores de la marca Caroline (proyectos/caroline-brand/LEEME.md): morado #534AB7, morado noche
   #3C3489, morado profundo #26215C, morado fondo #EEEDFE */
:root {
  --bg: #f6f5fc;
  --surface: #ffffff;
  --text: #1f1c33;
  --muted: #5f5b78;
  --border: #dcdaeb;
  --accent: #534ab7;
  --accent-hover: #3c3489;
  --accent-text: #ffffff;
  --error: #b42318;
  --error-bg: #fdecea;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --ok: #1d7a46;
  --ok-bg: #e5f4ea;
  --info: #3c3489;
  --info-bg: #eeedfe;
  --focus: #534ab766;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14121f;
    --surface: #1e1b2e;
    --text: #e9e7f5;
    --muted: #a19db8;
    --border: #353049;
    --accent: #a59ef2;
    --accent-hover: #c3bef7;
    --accent-text: #1a1640;
    --error: #ff8a80;
    --error-bg: #3a1d1d;
    --warn: #f3c969;
    --warn-bg: #3a3017;
    --ok: #6fd39b;
    --ok-bg: #173325;
    --info: #c3bef7;
    --info-bg: #2a2550;
    --focus: #a59ef266;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 1.1rem; }
.brand-logo { display: block; height: 34px; width: auto; }
.login-logo { display: block; height: 56px; width: auto; margin: 0 auto 20px; }
.brand-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}

.session { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.9rem; }

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
}
.card.narrow { max-width: 400px; margin: 48px auto; }

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
.muted { color: var(--muted); margin: 0 0 20px; }


label { display: block; font-size: 0.9rem; margin: 12px 0 4px; }

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 11px;
}
textarea { font-family: ui-monospace, Consolas, monospace; resize: vertical; }
input:focus, textarea:focus { outline: 3px solid var(--focus); border-color: var(--accent); }



button { font: inherit; cursor: pointer; border-radius: 6px; }
button:disabled { opacity: 0.6; cursor: progress; }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  padding: 11px 16px;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 8px 14px;
  white-space: nowrap;
}

.btn-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}

.form-msg { min-height: 1.5em; margin: 12px 0; font-size: 0.9rem; color: var(--error); overflow-wrap: anywhere; }
.form-msg[data-kind="info"] { color: var(--muted); }

.notice { border-radius: 6px; padding: 10px 12px; margin-bottom: 16px; font-size: 0.9rem; }
.notice-error { background: var(--error-bg); color: var(--error); }
.notice-warn { background: var(--warn-bg); color: var(--warn); }

.mono { font-family: ui-monospace, Consolas, monospace; }

/* Pestanas */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* Listas */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.list-head h1, .list-head h2 { margin: 0; }
.count {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  vertical-align: middle;
}
.count:empty { display: none; }
.list-state { margin: 16px 0 0; }

.filters { display: flex; gap: 8px; }
.filters input { flex: 1; min-width: 0; }
select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 11px;
}
select:focus { outline: 3px solid var(--focus); border-color: var(--accent); }

table.data-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.data-table th {
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td.actions { width: 1%; }
.actions-inner { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; white-space: nowrap; }
.data-table .mono { white-space: nowrap; }
.cell-main { font-weight: 500; overflow-wrap: anywhere; }
.cell-sub { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }

.watch + .watch { margin-top: 8px; }
.watch .cell-main { margin-left: 6px; }
.watch .cell-sub { margin-left: 14px; }
td > .watch + .cell-sub { margin-left: 14px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; }
.dot-on { background: var(--ok); }
.dot-off { background: var(--border); box-shadow: inset 0 0 0 1px var(--muted); }

.badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 4px;
  padding: 1px 7px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge-info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.owner { margin-top: 6px; }
.pin { font-family: ui-monospace, Consolas, monospace; font-size: 1.15rem; font-weight: 700; letter-spacing: 0.08em; margin-top: 4px; }
.pin-note { margin-top: 8px; font-size: 0.85rem; color: var(--warn); background: var(--warn-bg); border-radius: 4px; padding: 4px 8px; }

.btn-small { padding: 5px 10px; font-size: 0.85rem; }
/* Accion destructiva (desvincular) */
.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
  white-space: nowrap;
}
.btn-danger:hover:not(:disabled) { background: var(--error-bg); }

/* Formulario de registro de reloj */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid input { font-family: ui-monospace, Consolas, monospace; }
.notice-ok { background: var(--ok-bg); color: var(--ok); }

/* Etiqueta imprimible: siempre negro sobre blanco, tambien en modo oscuro */
.label-card { border-color: var(--accent); }
.print-label {
  width: 240px;
  margin: 0 auto 20px;
  padding: 16px;
  background: #ffffff;
  color: #000000;
  border: 1px dashed #9aa4b5;
  border-radius: 6px;
  text-align: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.label-brand { font-weight: 700; font-size: 1rem; letter-spacing: 0.02em; }
.label-qr svg { display: block; width: 100%; height: auto; margin: 6px 0; }
.label-caption { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.label-pin { font-family: ui-monospace, Consolas, monospace; font-size: 2rem; font-weight: 700; letter-spacing: 0.1em; line-height: 1.2; }
.label-help { font-size: 0.75rem; line-height: 1.35; margin-top: 6px; }
.label-imei { font-family: ui-monospace, Consolas, monospace; font-size: 0.7rem; margin-top: 6px; color: #333333; }

@media print {
  @page { margin: 12mm; }
  /* Solo se imprime la etiqueta */
  body { background: #ffffff; }
  body * { visibility: hidden; }
  .print-label, .print-label * { visibility: visible; }
  .print-label {
    position: absolute;
    top: 0;
    left: 0;
    width: 55mm;
    margin: 0;
    padding: 4mm;
    border: 0.3mm dashed #000000;
  }
  .label-qr svg { width: 40mm; margin: 2mm auto; }
  .label-brand { font-size: 11pt; }
  .label-caption { font-size: 7pt; }
  .label-pin { font-size: 20pt; }
  .label-help { font-size: 7pt; }
  .label-imei { font-size: 6.5pt; color: #000000; }
}

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; }
  .list-head { flex-wrap: wrap; }
  .tabs { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  .tab { white-space: nowrap; }
}

@media (max-width: 720px) {
  /* La tabla pasa a tarjetas apiladas */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr { padding: 12px 0; border-bottom: 1px solid var(--border); }
  .data-table tr:last-child { border-bottom: 0; }
  .data-table td { border: 0; padding: 4px 0; }
  .data-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
  }
  .data-table td:first-child::before, .data-table td.actions::before { display: none; }
  .data-table td:first-child .cell-main { font-size: 1.05rem; font-weight: 600; }
  .data-table td.actions { width: 100%; padding-top: 10px; }
  .actions-inner { flex-direction: row; align-items: center; justify-content: flex-start; flex-wrap: wrap; gap: 8px 16px; }
}

@media (max-width: 480px) {
  .card { padding: 18px; }
}

/* Reemplazo de garantia */
.replaced-note { margin-left: 14px; font-style: italic; }
#replace-card .notice { margin-top: 12px; }

/* Diagnostico: probar comandos */
.hint { color: var(--muted); font-size: 0.85rem; margin: 8px 0 0; }
.diag-head { margin-top: 24px; }
.diag-title { margin-top: 24px; }
.diag-note { font-size: 0.8rem; font-weight: 400; }
#diag-params select, #diag-command { width: 100%; }
.diag-messages {
  max-height: 320px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
}
.diag-line { display: flex; gap: 8px; padding: 2px 0; }
.diag-time, .diag-dir { color: var(--muted); white-space: nowrap; }
.diag-raw { overflow-wrap: anywhere; }
.diag-out .diag-raw { color: var(--accent); }

/* Campos de texto libre dentro de formularios con letra monoespaciada */
.form-grid input.text-input, textarea.text-input { font-family: inherit; }

/* Inventario: resumen, lote, notas, bajas */
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 16px; }
.summary:empty { display: none; }
.summary-item { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.summary-value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.summary-label { font-size: 0.8rem; color: var(--muted); }
.filters select { min-width: 0; }
.warn-text { color: var(--warn); }
.note-text { font-style: italic; white-space: pre-line; }
.badge-danger { background: var(--error-bg); color: var(--error); border-color: transparent; }
.status-extra { display: inline-block; margin-top: 6px; }
.danger-card { border-color: var(--error); }
.btn-primary.btn-primary-danger { background: var(--error); color: var(--surface); }
.btn-primary.btn-primary-danger:hover:not(:disabled) { background: var(--error); filter: brightness(0.92); }

/* Verificacion en dos pasos */
.code-input { font-family: ui-monospace, Consolas, monospace; font-size: 1.4rem; letter-spacing: 0.15em; text-align: center; }
.steps { margin: 0 0 16px; padding-left: 20px; font-size: 0.95rem; }
.steps li + li { margin-top: 4px; }
/* El QR siempre negro sobre blanco para que la camara lo lea, tambien en modo oscuro */
.totp-qr { width: 200px; margin: 0 auto; background: #ffffff; border-radius: 6px; }
.totp-qr svg { display: block; width: 100%; height: auto; }
.totp-secret-hint { text-align: center; }
.totp-secret { text-align: center; font-size: 1rem; letter-spacing: 0.08em; overflow-wrap: anywhere; margin: 4px 0 0; user-select: all; }

/* Cambiar contrasena */
.password-cancel { display: block; margin: 12px auto 0; }

/* Usuarios y bitacora */
.temp-pass { margin-top: 16px; }
.temp-pass .pin { user-select: all; }
.data-table select { padding: 5px 8px; font-size: 0.9rem; }
.row-disabled td { opacity: 0.6; }
.row-warn td:nth-child(3) .cell-main { color: var(--warn); }
.audit-more { margin-top: 16px; }

/* Peticion periodica de ubicacion, dentro de "Probar comandos" */
.poll-form { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.poll-action { display: flex; align-items: flex-end; }
.resync-hint { margin: 0; flex: 1; }
