:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --border: #e2e6ee;
  --text: #17202e;
  --muted: #5f6b7d;
  --accent: #1d4ed8;
  --accent-hover: #1a43bd;
  --accent-soft: #e8eefc;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf2e3;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }
/* `hidden` must win over component display rules (.btn, list items, …). */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
button, input { font: inherit; color: inherit; }
code, kbd { font-family: Consolas, ui-monospace, monospace; font-size: 12.5px; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.big { width: 40px; height: 40px; stroke-width: 1.5; color: var(--accent); }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.brand .icon { color: var(--accent); width: 22px; height: 22px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 4px; }

.agent-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); padding: 5px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.agent-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa5b1; }
.agent-status[data-state="online"] { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.agent-status[data-state="online"] .dot { background: var(--ok); }
.agent-status[data-state="offline"] { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.agent-status[data-state="offline"] .dot { background: var(--danger); }

/* Lines up with .layout: 1280px max width with 24px gutters. */
.agent-banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 20px max(24px, calc((100% - 1232px) / 2)) 0; padding: 14px 18px; border-radius: var(--radius); background: var(--warn-soft); color: #7c2d12; }
.agent-banner[hidden] { display: none; }
.agent-banner > div { display: flex; flex-direction: column; }
.agent-banner a.btn { text-decoration: none; }
@media (max-width: 900px) { .agent-banner { margin: 16px 16px 0; } }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; padding: 20px 24px; max-width: 1280px; margin: 0 auto; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.doc-panel { display: flex; flex-direction: column; min-height: calc(100vh - 110px); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.tab { border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .1); }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 9px; padding: 8px 16px; font-weight: 600; cursor: pointer; transition: background .15s, opacity .15s; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: var(--surface); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .tab:focus-visible, .icon-btn:focus-visible, .printer:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.tab-body { flex: 1; display: flex; flex-direction: column; background: #e9ecf2; }
.tab-body[hidden] { display: none; }
.paper-wrap { flex: 1; overflow: auto; padding: 24px; display: flex; justify-content: center; }
.paper { width: 794px; max-width: 100%; height: 1123px; border: 0; background: #fff; box-shadow: 0 2px 10px rgba(16, 24, 40, .15); flex: none; }

.dropzone {
  margin: 24px; flex: 1; min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  border: 2px dashed #b9c3d4; border-radius: var(--radius); background: var(--surface); cursor: pointer; padding: 24px; color: var(--muted);
}
.dropzone strong { color: var(--text); font-size: 15px; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { display: none; }
.file-card { margin: 0 24px 24px; display: flex; align-items: center; gap: 14px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.file-card[hidden] { display: none; }
.thumb { width: 56px; height: 56px; border-radius: 8px; background: var(--accent-soft) center/cover no-repeat; display: grid; place-items: center; color: var(--accent); font-weight: 700; font-size: 12px; flex: none; }
.file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta span { color: var(--muted); font-size: 13px; }

/* Info panel */
.info-panel { padding: 20px; align-self: start; position: sticky; top: 20px; }
.info-panel h2 { margin: 0 0 10px; font-size: 15px; }
.info-panel h3 { margin: 20px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; color: var(--muted); }
.steps strong { color: var(--text); }
.note { margin-top: 14px; padding: 10px 12px; border-radius: 9px; background: var(--accent-soft); color: #1e3a8a; font-size: 13px; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.history li { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); display: flex; flex-direction: column; }
.history li span { color: var(--muted); font-size: 12px; }
.history li.err strong { color: var(--danger); }
.history .empty { color: var(--muted); background: none; padding: 0; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 16px; z-index: 10; animation: fade .15s ease-out; }
.modal-backdrop[hidden] { display: none; }
.modal { position: relative; width: 520px; max-width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(15, 23, 42, .3); overflow: hidden; animation: pop .18s ease-out; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.spinning .icon { animation: spin .8s linear infinite; }

.printer-list { padding: 4px 20px 12px; overflow-y: auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-height: 120px; }
.printer { position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; transition: border-color .12s, background .12s; }
.printer:hover { border-color: #b9c3d4; }
.printer.selected { border-color: var(--accent); background: var(--accent-soft); }
.printer input { position: absolute; opacity: 0; pointer-events: none; }
.printer .p-icon { width: 38px; height: 38px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); flex: none; }
.printer.selected .p-icon { background: var(--accent); color: #fff; }
.p-main { flex: 1; min-width: 0; }
.p-name { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.p-detail { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.default { background: var(--accent); color: #fff; border-color: transparent; }
.badge.virtual { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.p-status { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 5px; color: var(--ok); white-space: nowrap; }
.p-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.p-status.warn { color: var(--warn); }
.p-status.bad { color: var(--danger); }

.list-message { text-align: center; color: var(--muted); padding: 24px 12px; display: grid; gap: 6px; justify-items: center; }
.list-message strong { color: var(--text); }
.list-message code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; }

.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.copies { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.stepper { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.stepper button { border: 0; background: none; width: 32px; cursor: pointer; font-size: 16px; color: var(--muted); }
.stepper button:hover { background: var(--surface-2); color: var(--text); }
.stepper input { width: 44px; border: 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border); text-align: center; padding: 6px 0; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.actions { display: flex; gap: 8px; }

.modal-state { position: absolute; inset: 0; background: rgba(255, 255, 255, .96); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 24px; }
.modal-state[hidden] { display: none; }
.modal-state strong { font-size: 16px; }
.modal-state span { color: var(--muted); }
.spinner { width: 40px; height: 40px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.state-ok { width: 48px; height: 48px; color: var(--ok); }
svg[hidden], .spinner[hidden] { display: none; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #17202e; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 20; max-width: calc(100% - 32px); }
.toast.error { background: var(--danger); }

.print-blocked { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .info-panel { position: static; }
  .topbar { padding: 12px 16px; }
  .brand small { display: none; }
}

/* Block the browser's own print dialog (and its "Save as PDF") from printing the app. */
@media print {
  .app, .modal-backdrop, .toast { display: none !important; }
  .print-blocked { display: block; font: 16pt "Segoe UI", sans-serif; padding: 40px; }
}

/* Install guide + offline choices */
.install-steps { margin: 0; padding: 4px 20px 8px 44px; display: grid; gap: 14px; overflow-y: auto; }
.install-steps li { padding-left: 4px; }
.install-steps li::marker { font-weight: 700; color: var(--accent); }
.install-steps li > * { display: block; }
.install-steps li > span { color: var(--muted); font-size: 13px; margin-top: 2px; }
.install-steps .btn { display: inline-flex; margin-top: 8px; text-decoration: none; }
.install-steps .hint { font-size: 12.5px; }
.install-steps code, .list-message code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.install-status { margin: 4px 20px 16px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); display: flex; gap: 12px; align-items: flex-start; }
.install-status > div { display: flex; flex-direction: column; }
.install-status span { color: var(--muted); font-size: 13px; }
.install-status[data-state="done"] { background: var(--ok-soft); }
.install-status[data-state="done"] .spinner { display: none; }
.install-status .state-ok { width: 24px; height: 24px; }
.spinner.small { width: 22px; height: 22px; border-width: 2.5px; flex: none; }
.offline-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
