@font-face {
  font-family: "Manrope";
  src: url("/fonts/manrope-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --bg: #101012;
  --panel: #18181b;
  --panel-2: #1f1f23;
  --line: #2e2e33;
  --line-strong: #44444b;
  --text: #f3f0ea;
  --muted: #a09c94;
  --accent: #d6b27c;
  --accent-strong: #e6c896;
  --accent-ink: #1c1509;
  --danger: #ef8a7e;
  --danger-bg: #5c211b;
  --ok: #8dd0ae;
  --warn: #eec069;
  --radius: 10px;
  color-scheme: dark;
}

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

html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 16px; font-weight: 700; margin: 0 0 14px; }
p { margin: 0; }
.muted { color: var(--muted); }

button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Brand */
.brand-mark { font-weight: 800; letter-spacing: 0.14em; font-size: 14px; white-space: nowrap; }
.brand-mark em { font-style: normal; font-weight: 400; letter-spacing: 0.04em; color: var(--accent); }
.brand-mark.large { font-size: 20px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid transparent; border-radius: 8px; padding: 10px 18px;
  font-weight: 700; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: var(--line-strong); color: var(--text); }
.btn.ghost:hover:not(:disabled) { background: var(--panel-2); }
.btn.danger { background: var(--danger); color: #2a0b07; }
.btn.small { padding: 6px 12px; font-size: 13px; font-weight: 600; }
.btn.full { width: 100%; }
.btn.grow { flex: 1; }
.btn.center { display: flex; margin: 16px auto 0; }
.danger-text.btn { color: var(--danger); }
kbd {
  font: inherit; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px;
  background: rgb(0 0 0 / .14);
}

/* Forms */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span, .field > label { font-size: 13px; font-weight: 600; color: var(--muted); }
input:not([type=checkbox]), textarea, select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 9px 12px; min-width: 0;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; }
input::placeholder, textarea::placeholder { color: #85817a; }
textarea { resize: vertical; display: block; }
.warn { border-color: var(--warn) !important; background: #2e2616 !important; }
.input-row { display: flex; gap: 8px; }
.input-row input { font-variant-numeric: tabular-nums; }
.input-row .btn { flex: none; }

.check {
  display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600;
  align-self: end; min-height: 41px; cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: 2fr 2fr 1fr; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.form-error { color: var(--danger); font-size: 14px; font-weight: 600; margin: 0; }

.language-select { width: auto; padding: 6px 10px; font-size: 13px; font-weight: 600; }
.login-card .language-select { align-self: flex-end; }

/* Login */
.login-page { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.login-brand {
  background: linear-gradient(160deg, #1d1b18, #121213 70%);
  border-right: 1px solid var(--line);
  padding: 44px; display: flex; flex-direction: column; overflow: hidden;
}
.login-sample { flex: 1; display: flex; align-items: center; justify-content: center; }
#sample-label { transform: rotate(-3deg); box-shadow: 0 30px 70px rgb(0 0 0 / .55); }
.login-main { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.login-card { width: 100%; max-width: 380px; gap: 18px; }
.login-card h1 { margin-bottom: 4px; }
.mobile-only { display: none; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 28px;
  padding: 12px 24px; background: rgb(16 16 18 / .94); border-bottom: 1px solid var(--line);
}
.topbar-tag { color: var(--muted); font-size: 13px; font-weight: 600; }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-name { color: var(--muted); font-size: 13px; font-weight: 600; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  background: none; border: 0; padding: 7px 13px; border-radius: 7px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--panel-2); color: var(--text); }

/* Pages */
.page { max-width: 1040px; margin: 0 auto; padding: 32px 24px 64px; }
.page.narrow { max-width: 640px; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page.narrow .page-head { margin-bottom: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.search { margin-bottom: 14px; }
.empty {
  border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 40px 20px;
  text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.empty p { color: var(--muted); }
.empty .btn { margin-top: 10px; }

.pill {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px;
  border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap;
}
.pill.on { color: var(--ok); border-color: #3d6b55; }
.pill.off { color: var(--danger); border-color: #7a3f38; }

/* Admin */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat span { display: block; color: var(--muted); font-size: 13px; font-weight: 600; }
.stat b { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.client-list { display: flex; flex-direction: column; gap: 8px; }
.client {
  display: grid; grid-template-columns: minmax(0, 1fr) 70px 110px 76px auto; gap: 16px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px;
}
.client .pill { justify-self: start; }
.client.inactive .client-main, .client.inactive .client-stat { opacity: .55; }
.client-main { display: flex; gap: 12px; align-items: center; min-width: 0; }
.client-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--accent); font-weight: 700;
}
.client-id { min-width: 0; }
.client-id strong, .client-id span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-id span, .client-stat span { color: var(--muted); font-size: 12.5px; }
.client-stat b { display: block; font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.client-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Print workspace */
.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 28px;
  max-width: 1160px; margin: 0 auto; padding: 24px;
}
.work-form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.paste-box { background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px 16px 16px; }
.paste-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; align-items: baseline; flex-wrap: wrap; }
.paste-head label { font-weight: 700; }
.paste-status { font-size: 13px; font-weight: 600; }
.paste-status.success { color: var(--ok); }
.paste-status.warning { color: var(--warn); }
fieldset {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  margin: 0; padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
legend { font-weight: 700; padding: 0 6px; margin-left: -6px; }
legend small { color: var(--muted); font-weight: 500; font-size: 12.5px; margin-left: 4px; }
.submit-proxy { display: none; }

.preview-pane { position: sticky; top: 76px; align-self: start; }
.preview-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-weight: 700; }
.preview-head small { color: var(--muted); font-weight: 500; }
.preview-stage {
  background: #09090a; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 10px; display: flex; justify-content: center;
  max-height: calc(100vh - 210px); overflow: auto; align-items: flex-start;
}
#preview .label { box-shadow: 0 10px 30px rgb(0 0 0 / .5); }
.preview-actions { display: flex; gap: 10px; margin-top: 12px; }

.printer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 14px;
}
.printer-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; margin: 0; }
.printer-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; }
.printer-chip.connected { color: var(--text); }
.printer-chip.connected::before { background: var(--ok); }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
/* From addresses */
.sender-list { display: grid; gap: 12px; }
.sender { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; }
.sender-logo {
  width: 120px; height: 80px; border-radius: 8px; background: #fff; display: grid; place-items: center;
  overflow: hidden; color: #666; font-size: 12px; font-weight: 600; padding: 6px;
}
.sender-logo img { max-width: 100%; max-height: 100%; }
.sender-body p { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.sender-head { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; }
.sender-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-row {
  display: flex; align-items: center; gap: 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px;
}
.history-main { flex: 1; min-width: 0; }
.history-main strong, .history-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-main span { color: var(--muted); font-size: 13px; }
.history-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); }
.steps b { color: var(--text); font-weight: 600; }

/* Modal */
dialog.modal {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: 14px; padding: 24px; width: min(440px, calc(100vw - 32px));
}
dialog.modal.wide { width: min(600px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .65); }
.modal h2 { font-size: 19px; font-weight: 600; margin-bottom: 14px; }
.modal-text { color: var(--muted); margin-bottom: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.credentials {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px;
  font-family: Consolas, ui-monospace, monospace; font-size: 13.5px; white-space: pre-wrap;
  overflow-wrap: anywhere; margin: 12px 0 0; user-select: all;
}

/* Toasts */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: #f3f0ea; color: #17150f; border-radius: 9px; padding: 11px 15px; font-weight: 600; font-size: 14px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .5);
}
.toast.error { background: var(--danger); color: #2a0b07; }
.toast-action { background: none; border: 0; font-weight: 800; text-decoration: underline; cursor: pointer; padding: 0; }

/* Smaller screens */
@media (max-width: 940px) {
  .workspace { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .preview-pane { position: static; }
  .preview-stage { max-height: none; }
  .client { grid-template-columns: minmax(0, 1fr) auto; }
  .client-main { grid-column: 1 / -1; }
  .client-actions { grid-column: 1 / -1; justify-content: flex-start; }
  }
@media (max-width: 720px) {
  .login-page { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .mobile-only { display: block; margin-bottom: 26px; }
  .topbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .user-name { display: none; }
  .page { padding: 22px 16px 48px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .history-row { flex-wrap: wrap; }
  .history-main { flex-basis: 100%; }
  .history-meta { flex: 1 1 100%; flex-wrap: wrap; }
  kbd { display: none; }
}
@media (max-width: 460px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sender { grid-template-columns: 1fr; }
}
