:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f1efec;
  --border: #e4e1dc;
  --text: #1d1b18;
  --muted: #6f6a63;
  --accent: #e8590c;
  --accent-text: #ffffff;
  --accent-soft: #fdebe0;
  --ok: #1f8a4c;
  --ok-soft: #e1f3e8;
  --bad: #c92a2a;
  --bad-soft: #fbe4e4;
  --warn: #a96500;
  --warn-soft: #fbf0d9;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1e1c1a;
    --surface-2: #262421;
    --border: #34312d;
    --text: #f1eee9;
    --muted: #a19a91;
    --accent: #ff7a33;
    --accent-text: #1a0d05;
    --accent-soft: #3a2316;
    --ok: #4cc77f;
    --ok-soft: #173525;
    --bad: #ff6b6b;
    --bad-soft: #3d1c1c;
    --warn: #f0b44c;
    --warn-soft: #3a2e14;
    --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, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* Botones e inputs */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 550;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
input:not([type=checkbox]) {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Marca */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-lg { font-size: 22px; }
.logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  -webkit-mask: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 5h10v6H7zM5 10h14v6h-2v3H7v-3H5z' fill='white'/%3E%3C/svg%3E");
  background-size: 18px; background-position: center; background-repeat: no-repeat;
  flex: none;
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 10px;
}
.login-card p { margin: 0 0 8px; }
.login-card label { font-weight: 550; font-size: 13px; }
.login-card .btn { margin-top: 6px; padding: 10px; }

/* Estructura */
.topbar {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-width: 0; }
.sidebar-head { display: flex; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); }
.list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
}
.list li:hover { background: var(--surface-2); }
.list li.active { background: var(--accent-soft); }
.list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { grid-column: 2 / 4; font-size: 12.5px; color: var(--muted); }
.list .badge-err { font-size: 12px; color: var(--bad); font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); opacity: .5; }
.dot.on { background: var(--ok); opacity: 1; box-shadow: 0 0 0 3px var(--ok-soft); }
.empty { color: var(--muted); text-align: center; padding: 28px 16px; margin: 0; }
.empty.big { padding: 80px 16px; }

.detail { padding: 24px; min-width: 0; }
#detailBody { max-width: 980px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.back { display: none; }

.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head h1 { font-size: 24px; letter-spacing: -.02em; }
.head .meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--surface-2); color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12.5px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .value.bad { color: var(--bad); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card-head h2 { font-size: 15px; }
.card-head p { margin: 2px 0 0; font-size: 13px; }
.card-body { padding: 16px 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row code {
  flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.printers { list-style: none; margin: 0; padding: 0; }
.printers li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 18px; border-top: 1px solid var(--border); }
.printers li:first-child { border-top: 0; }
.printers .pname { font-weight: 600; }
.printers .ptype { font-size: 12.5px; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 18px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 18px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
td .err { color: var(--bad); font-size: 12.5px; margin-top: 2px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.done { background: var(--ok-soft); color: var(--ok); }
.chip.error { background: var(--bad-soft); color: var(--bad); }
.chip.queued, .chip.sent { background: var(--warn-soft); color: var(--warn); }

.danger-zone .card-body { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }

dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  width: min(420px, calc(100vw - 32px)); padding: 22px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h3 { font-size: 17px; margin-bottom: 6px; }
dialog p { margin: 0 0 12px; }
.dialog-actions { display: flex; flex-direction: row-reverse; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-weight: 550; z-index: 20;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; }
  .layout.show-detail .sidebar { display: none; }
  .layout:not(.show-detail) .detail { display: none; }
  .detail { padding: 16px; }
  .back { display: inline-flex; justify-self: start; margin-bottom: 4px; }
  .two { grid-template-columns: minmax(0, 1fr); }
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .value { font-size: 22px; }
  #summary { display: none; }
  th, td { padding-left: 12px; padding-right: 12px; }
}
