:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #dce1ea;
  --border-strong: #c6cedb;
  --text: #1e2530;
  --muted: #667085;
  --primary: #1d4ed8;
  --primary-hover: #1b45c0;
  --accent: #ff8a3d;
  --danger: #d64545;
  --danger-bg: #fdecec;
  --ok: #157f3d;
  --ok-bg: #e9f7ef;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 6px 20px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

/* El atributo `hidden` debe ganar siempre: hay reglas de autor con `display`
   (p. ej. `.login { display:flex }`) que, si no, lo pisan y el elemento se
   sigue viendo aunque el JS ponga `hidden = true`. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

/* ─── Login ──────────────────────────────────────────────────────────────── */
.login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #f6f7fa 0%, #e6ebf3 100%);
  z-index: 100;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-logo {
  height: 96px;
  width: auto;
  object-fit: contain;
  margin: 0 auto 4px;
}
.login-card h2 { margin: 0; font-size: 20px; }
.login-card p { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

/* ─── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.04);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { height: 40px; width: auto; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: 0.2px; white-space: nowrap; }
.subtitle { color: var(--muted); font-size: 12px; }

.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── Controles ──────────────────────────────────────────────────────────── */
input[type="text"],
input[type="number"],
input[type="password"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 14px;
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
  background: var(--surface);
}

.btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: #f0f2f6; }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary.dirty {
  box-shadow: 0 0 0 3px rgba(255, 138, 61, 0.45);
}
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: #f0f2f6; }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.danger { border-color: #eebcbc; color: var(--danger); background: var(--danger-bg); }
.btn.danger:hover { background: #fbdede; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }

/* ─── Avisos (toast) ─────────────────────────────────────────────────────── */
/* Flotan sobre la pantalla, en la parte de arriba, sin empujar el contenido.
   Se ocultan solos (salvo los errores) o con el botón ×. */
.toast {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: max-content;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 12px 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.4;
  transform: translate(-50%, -12px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, transform .2s, visibility .2s;
}
.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
  visibility: visible;
}
.toast.info { background: #eaf0fd; color: #1e3a8a; border-color: #c7d7fb; }
.toast.ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe4cd; }
.toast.error { background: var(--danger-bg); color: var(--danger); border-color: #f3c9c9; }
.toast-close {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: .65;
}
.toast-close:hover { opacity: 1; background: rgba(0, 0, 0, .07); }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
main {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 24px 80px;
  display: grid;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-head h2 { margin: 0 0 4px; font-size: 17px; }
.card-head p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.card-actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }

.slots { display: grid; gap: 14px; }

/* ─── Conexión ───────────────────────────────────────────────────────────── */
.connection { display: grid; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-row { display: flex; gap: 10px; align-items: stretch; }
.field-row input { flex: 1 1 auto; min-width: 0; }
.test-result { font-size: 13px; min-height: 18px; }
.test-result.ok { color: var(--ok); }
.test-result.error { color: var(--danger); }
.test-result.pending { color: var(--muted); }

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

/* ─── Leyendas de tamaño de imagen ───────────────────────────────────────── */
.note {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}
.note strong { color: var(--text); }
.note b { color: var(--text); }
.note.warn {
  background: #fff7ed;
  border-color: #fbd9b5;
  border-left-color: var(--accent);
}
.note.warn strong { color: #9a4a00; }
.unit { align-self: center; color: var(--muted); font-size: 13px; white-space: nowrap; }
.manifest-field {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 16px;
}
input[readonly] { background: #eaeef4; color: var(--muted); }

/* ─── Items ──────────────────────────────────────────────────────────────── */
.item {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.item.disabled { opacity: 0.55; }

.thumb {
  width: 96px; height: 72px;
  border-radius: 8px;
  background: #eef1f5;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb .asset {
  font-size: 11px; color: var(--muted);
  text-align: center; padding: 4px; word-break: break-all;
}

.fields { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.fields .url { width: 100%; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.icon:hover { background: #f0f2f6; }

.slot-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin-bottom: 6px; font-weight: 700;
}

.empty { color: var(--muted); font-size: 13px; font-style: italic; }

/* ─── Responsive (móvil) ─────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px 16px;
  }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1 1 auto; text-align: center; }
  .brand-logo { height: 34px; }
  .brand h1 { font-size: 16px; }

  .toast { top: 8px; padding: 10px 10px 10px 14px; }
  main { padding: 16px 16px 72px; gap: 16px; }
  .card { padding: 16px; }

  .item { grid-template-columns: 72px minmax(0, 1fr); }
  .thumb { width: 72px; height: 60px; }
  .actions { grid-column: 1 / -1; }
  .actions .btn { flex: 1 1 auto; }
}

@media (max-width: 420px) {
  .field-row { flex-direction: column; }
  .field-row .btn { width: 100%; }
  .login-card { padding: 26px 20px; }
}
