:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #646b78;
  --accent: #2357d9;
  --accent-hover: #1c47b5;
  --accent-soft: #e8eefc;
  --ok: #1a7f4b;
  --ok-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf1dc;
  --err: #c0362c;
  --err-soft: #fbe6e4;
  --info: #2357d9;
  --info-soft: #e8eefc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1d2128;
    --border: #2a2f38;
    --text: #e8eaee;
    --muted: #99a0ad;
    --accent: #5b8cff;
    --accent-hover: #7aa2ff;
    --accent-soft: #1d2a47;
    --ok: #4cc485;
    --ok-soft: #15301f;
    --warn: #f0b44c;
    --warn-soft: #362a12;
    --err: #ff7468;
    --err-soft: #3a1a18;
    --info: #7aa2ff;
    --info-soft: #1d2a47;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.hidden { display: none !important; }

/* ---------- Pantalla completa (sin scroll de página) ---------- */
html.app, html.app body { height: 100%; overflow: hidden; }
html.app body { display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 52px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; white-space: nowrap; }
.brand svg { color: var(--accent); }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
.user-chip strong { color: var(--text); font-weight: 600; }
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
}
.right { display: flex; flex-direction: column; gap: 16px; min-height: 0; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.card-head h2, .printers h2 { font-size: 15px; margin: 0; font-weight: 650; }
.card-body { padding: 14px 16px; }

/* ---------- Formulario ---------- */
.send { display: flex; flex-direction: column; min-height: 0; }
.send .card-body { overflow-y: auto; flex: 1; min-height: 0; }

.dropzone {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { color: var(--accent); flex-shrink: 0; }
.dropzone p { margin: 0; }
.dropzone .hint { color: var(--muted); font-size: 12px; }

.file-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; max-height: 118px; overflow-y: auto; }
.file-list:empty { display: none; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 3px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.file-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .size { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  height: 36px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.segmented { position: relative; display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; height: 36px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.segmented label {
  flex: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.segmented label + input + label { border-left: 1px solid var(--border); }
.segmented input:checked + label { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 550;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.block { width: 100%; padding: 10px; font-size: 14px; margin-top: 14px; }
.btn.danger { color: var(--err); }
.btn.icon { padding: 5px; border-color: transparent; background: transparent; color: var(--muted); }
.btn.icon:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

.progress { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.msg { margin-top: 10px; padding: 7px 12px; border-radius: 8px; font-size: 13px; }
.msg.error { background: var(--err-soft); color: var(--err); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- Impresoras (franja) ---------- */
.printers {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 10px 8px 16px;
  min-height: 48px;
  flex-shrink: 0;
}
.printer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 22px; flex: 1; min-width: 0; }
.printer-list li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.printer-list .grow { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.printer-list .pname { font-weight: 550; white-space: nowrap; }
.printer-list .pmeta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.printer-list .badge { font-size: 10px; padding: 1px 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }

/* ---------- Cola ---------- */
.queue { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 550;
  font-size: 13px;
}
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.tab .count { font-variant-numeric: tabular-nums; margin-left: 4px; opacity: 0.8; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.admin-tools { display: flex; gap: 6px; }

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 550;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* La lista de trabajos es lo único que se desplaza, y solo si hay muchos */
.jobs { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; overflow-y: auto; }
.job {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.job .pos {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
}
.job .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .meta { color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 1px; }
.job .err { color: var(--err); font-size: 12px; margin-top: 3px; }
.job .right { display: flex; flex-direction: row; align-items: center; gap: 6px; }
.job .info { min-width: 0; }
.job.mine .pos { border-color: var(--accent); color: var(--accent); }

.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill.queued { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.converting, .pill.printing { background: var(--info-soft); color: var(--info); }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.failed { background: var(--err-soft); color: var(--err); }
.pill.canceled { background: var(--surface-2); color: var(--muted); }

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; color: var(--muted); }
.empty svg { opacity: 0.5; margin-bottom: 8px; }

.conn { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login .card-body { padding: 26px; }
.login h1 { font-size: 20px; margin: 10px 0 4px; }
.login p.sub { color: var(--muted); margin: 0 0 18px; }
.login .field + .field { margin-top: 14px; }
.login .field input { height: 40px; }

/* ---------- Responsive ---------- */
/* Pantallas estrechas o muy bajas: se vuelve a una página normal con scroll */
@media (max-width: 900px), (max-height: 560px) {
  html.app, html.app body { height: auto; overflow-x: hidden; overflow-y: auto; }
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .send .card-body { overflow: visible; }
  .queue { min-height: 320px; }
  .jobs { overflow: visible; }
  .topbar { padding: 0 16px; }
}
@media (max-width: 520px) {
  .job { grid-template-columns: 1fr; gap: 8px; }
  .job .pos { display: none; }
  .job .right { justify-content: space-between; }
  .user-chip .who, .conn .who { display: none; }
  .printers { flex-wrap: wrap; }
}
