:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #dfe4ec;
  --border-strong: #c9d1dd;
  --text: #152033;
  --muted: #6b7485;
  --accent: #2563eb;
  --accent-soft: #eff5ff;
  --success: #1f9d50;
  --success-soft: #edf9f1;
  --danger: #d14343;
  --danger-soft: #fff1f1;
  --shadow: 0 8px 24px rgba(26, 39, 58, .07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(rgba(255,255,255,.58), rgba(255,255,255,.58)),
    radial-gradient(circle at 15% 10%, rgba(37,99,235,.07), transparent 27%),
    var(--bg);
}

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
svg { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

.topbar {
  min-height: 82px;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 14px clamp(20px, 3vw, 44px);
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
}
.brand-mark svg { width: 27px; height: 27px; }
.brand h1 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.brand p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }

.connection-strip {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  color: #495365;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(26,39,58,.03);
  font-size: 14px;
  white-space: nowrap;
}
.connection-strip strong { color: var(--text); }
.strip-separator { color: #a9b1be; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #aeb6c2; flex: 0 0 auto; box-shadow: 0 0 0 3px rgba(174,182,194,.15); }
.status-dot.ok { background: var(--success); box-shadow: 0 0 0 3px rgba(31,157,80,.13); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px rgba(209,67,67,.13); }
.status-dot.idle { background: #aeb6c2; }

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, transform .08s ease, box-shadow .16s ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .65; cursor: wait; }
.button-primary { color: #fff; background: var(--accent); border-color: var(--accent); box-shadow: 0 5px 14px rgba(37,99,235,.22); }
.button-primary:hover { background: #1e56d1; }
.button-outline { color: var(--accent); background: #fff; border-color: #9bb9ff; }
.button-outline:hover { background: var(--accent-soft); border-color: var(--accent); }
.button-block { width: 100%; }
.topbar > .button { justify-self: end; }

.app-shell {
  width: min(1500px, calc(100% - 40px));
  margin: 22px auto;
  display: grid;
  grid-template-columns: minmax(245px, 290px) minmax(500px, 1fr) minmax(290px, 360px);
  gap: 20px;
  align-items: start;
}

.side-column { display: grid; gap: 18px; }
.preview-column { position: sticky; top: 104px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.settings-panel { padding: 20px; }
.panel-title { display: flex; align-items: center; gap: 9px; }
.panel-title svg { color: var(--accent); }
.panel-title h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.settings-panel .panel-title { margin-bottom: 18px; }

.field { display: grid; gap: 7px; color: #394456; font-size: 13px; font-weight: 650; }
.field + .field { margin-top: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.field-row .field { margin: 0; }
input, select, textarea {
  width: 100%;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input, select { min-height: 42px; padding: 9px 11px; }
textarea { padding: 13px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.11); }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix input { border-radius: 8px 0 0 8px; }
.input-suffix span { display: grid; place-items: center; min-width: 48px; color: var(--muted); background: var(--surface-muted); border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 8px 8px 0; font-size: 13px; }

.settings-panel .button { margin-top: 16px; }
.inline-status { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px; color: var(--muted); }
.inline-status strong, .inline-status small { display: block; }
.inline-status strong { color: #4f5968; font-size: 13px; }
.inline-status small { margin-top: 2px; font-size: 11px; line-height: 1.35; }
.inline-status.ok strong { color: var(--success); }
.inline-status.error strong { color: var(--danger); }

.paper-summary { display: grid; gap: 5px; margin: 16px 0; color: var(--muted); font-size: 12px; }
.paper-summary strong { color: var(--text); font-size: 14px; }
.compact-details { border-top: 1px solid var(--border); padding-top: 13px; }
.compact-details summary { color: var(--accent); font-size: 12px; font-weight: 700; cursor: pointer; }
.details-content { margin-top: 13px; }
.tip { margin-top: 16px; padding: 12px; color: #667085; background: #f6f8fb; border: 1px solid #e7ebf1; border-radius: 8px; font-size: 12px; line-height: 1.5; }

.workspace { padding: 20px; min-width: 0; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 22px; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface-muted); }
.tab {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #495365;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-weight: 700;
}
.tab:last-child { border-right: 0; }
.tab:hover { background: #fff; }
.tab.active { color: var(--accent); background: #fff; box-shadow: inset 0 -2px 0 var(--accent); }
.tab-icon { font-family: Georgia, serif; font-size: 17px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 9px; }
.section-heading label { font-size: 14px; font-weight: 750; }
.section-heading span { color: var(--muted); font-size: 12px; }
.ticket-editor { min-height: 320px; resize: vertical; font: 14px/1.5 "SFMono-Regular", Consolas, "Liberation Mono", monospace; background: #fbfcfe; }
.code-editor { min-height: 280px; color: #27334a; }

.format-grid { display: grid; grid-template-columns: 1fr 1.25fr; gap: 12px; margin-top: 14px; }
.format-group { min-width: 0; margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 9px; }
.format-group legend { padding: 0 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.segmented button { min-height: 40px; color: #566174; background: #fff; border: 1px solid var(--border); border-radius: 7px; cursor: pointer; font-size: 23px; line-height: 1; }
.segmented button:nth-child(1) { text-align: left; padding-left: 12px; }
.segmented button:nth-child(3) { text-align: right; padding-right: 12px; }
.segmented button.active { color: var(--accent); border-color: #7ca4ff; background: var(--accent-soft); }
.format-line { display: grid; grid-template-columns: 46px 46px minmax(120px,1fr); gap: 7px; align-items: end; }
.toggle-button input { display: none; }
.toggle-button span { height: 42px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 7px; cursor: pointer; font-size: 20px; font-weight: 800; }
.toggle-button input:checked + span { color: var(--accent); border-color: #7ca4ff; background: var(--accent-soft); }
.toggle-button.underline span { text-decoration: underline; }
.size-select { display: grid; gap: 4px; color: var(--muted); font-size: 11px; }
.size-select select { min-height: 42px; }

.print-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding-top: 18px; margin-top: 18px; border-top: 1px solid var(--border); }
.compact-field { font-size: 11px; }
.compact-field input, .compact-field select { min-height: 40px; }
.checkbox-line { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.checkbox-line input { width: 16px; height: 16px; min-height: 0; }
.main-print-button { min-height: 50px; margin-top: 16px; font-size: 15px; }

.drop-zone { min-height: 230px; display: grid; place-items: center; align-content: center; gap: 9px; padding: 24px; text-align: center; color: var(--muted); border: 1.5px dashed #b9c3d2; border-radius: 10px; background: #fafbfd; cursor: pointer; }
.drop-zone:hover, .drop-zone.dragging { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.drop-zone svg { width: 38px; height: 38px; }
.drop-zone strong { color: var(--text); }
.drop-zone span { font-size: 12px; }
.drop-zone input { display: none; }
.image-options { margin-top: 14px; }
.hex-examples { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
.hex-examples button { display: grid; gap: 4px; padding: 10px; text-align: left; background: #fff; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.hex-examples code { color: var(--accent); font-weight: 800; }
.hex-examples span { color: var(--muted); font-size: 11px; }
.test-box { min-height: 430px; display: grid; place-items: center; align-content: center; gap: 10px; padding: 28px; text-align: center; border: 1px dashed var(--border-strong); border-radius: 10px; background: #fafbfd; }
.test-box > svg { width: 45px; height: 45px; color: var(--accent); }
.test-box h3 { margin: 3px 0 0; }
.test-box p { max-width: 430px; margin: 0 0 6px; color: var(--muted); line-height: 1.55; }

.preview-panel { padding: 18px; }
.preview-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.paper-badge { padding: 7px 10px; color: #4f5968; background: #f6f8fb; border: 1px solid var(--border); border-radius: 7px; font-size: 12px; font-weight: 700; }
.receipt-stage { min-height: 500px; display: grid; place-items: start center; padding: 16px 8px 22px; background: #f4f6f8; border: 1px solid #e7eaf0; border-radius: 9px; overflow: auto; }
.receipt { width: 245px; min-height: 420px; padding: 24px 18px 28px; color: #111; background: #fff; box-shadow: 0 8px 18px rgba(0,0,0,.12); font: 11px/1.3 "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; transition: width .2s ease; }
.receipt.paper-80 { width: 300px; }
.receipt-content { white-space: pre-wrap; }
.receipt-content.align-left { text-align: left; }
.receipt-content.align-center { text-align: center; }
.receipt-content.align-right { text-align: right; }
.receipt-content.is-bold { font-weight: 800; }
.receipt-content.is-underline { text-decoration: underline; }
.receipt-content[data-size="double_width"], .receipt-content[data-size="double"] { font-size: 14px; letter-spacing: .8px; }
.receipt-content[data-size="double_height"], .receipt-content[data-size="double"] { line-height: 1.7; }
.receipt-image { display: block; max-width: 100%; max-height: 300px; margin: 0 auto; filter: grayscale(1) contrast(1.15); object-fit: contain; }
.receipt-caption { margin-top: 12px; text-align: center; white-space: pre-wrap; }
.receipt-cut-line { margin-top: 22px; padding-top: 7px; color: #8b93a0; border-top: 1px dashed #8b93a0; text-align: left; font-size: 10px; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.quick-actions button { min-height: 78px; display: grid; place-items: center; align-content: center; gap: 6px; padding: 8px; color: #334058; background: #fff; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-size: 11px; font-weight: 700; }
.quick-actions button:hover { color: var(--accent); border-color: #9bb9ff; background: var(--accent-soft); }
.quick-actions svg { width: 22px; height: 22px; color: var(--accent); }

.activity-bar {
  width: min(1500px, calc(100% - 40px));
  min-height: 76px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  margin: 0 auto 24px;
  padding: 13px 18px;
  background: rgba(255,255,255,.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.activity-title { display: flex; align-items: center; gap: 8px; font-weight: 750; }
.activity-items { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.activity-item { min-width: 0; display: flex; align-items: center; gap: 9px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.activity-icon { width: 27px; height: 27px; display: grid; place-items: center; flex: 0 0 auto; color: var(--success); background: var(--success-soft); border-radius: 50%; }
.activity-item.error .activity-icon { color: var(--danger); background: var(--danger-soft); }
.activity-item strong, .activity-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-item strong { font-size: 12px; }
.activity-item small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.activity-empty { color: var(--muted); font-size: 12px; }
.history-clear { color: var(--muted); background: transparent; border: 0; cursor: pointer; font-weight: 700; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  min-width: 300px;
  max-width: min(420px, calc(100% - 44px));
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  color: #164b2b;
  background: #effaf3;
  border: 1px solid #a7dfbb;
  border-radius: 10px;
  box-shadow: 0 14px 35px rgba(26,39,58,.18);
}
.toast.error { color: #7f2424; background: #fff3f3; border-color: #efb2b2; }
.toast-icon { width: 31px; height: 31px; display: grid; place-items: center; color: #fff; background: var(--success); border-radius: 50%; }
.toast.error .toast-icon { background: var(--danger); }
.toast strong, .toast small { display: block; }
.toast small { margin-top: 2px; opacity: .78; }
.toast > button { color: currentColor; background: transparent; border: 0; cursor: pointer; font-size: 20px; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: 1fr auto; }
  .connection-strip { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; justify-content: center; }
  .app-shell { grid-template-columns: minmax(240px, 285px) minmax(480px, 1fr); }
  .preview-column { grid-column: 1 / -1; position: static; }
  .preview-panel { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(300px, 360px); gap: 16px; }
  .preview-heading { grid-column: 1 / -1; margin-bottom: 0; }
  .quick-actions { align-self: start; grid-template-columns: 1fr; margin-top: 0; }
  .quick-actions button { min-height: 70px; }
}

@media (max-width: 820px) {
  .topbar { position: static; grid-template-columns: 1fr auto; padding: 13px 16px; gap: 12px; }
  .connection-strip { justify-content: flex-start; overflow-x: auto; font-size: 12px; }
  .app-shell { width: min(100% - 24px, 700px); grid-template-columns: 1fr; margin-top: 14px; }
  .side-column { grid-template-columns: 1fr 1fr; }
  .preview-panel { display: block; }
  .quick-actions { grid-template-columns: repeat(3, 1fr); margin-top: 14px; }
  .activity-bar { width: min(100% - 24px, 700px); grid-template-columns: 1fr auto; }
  .activity-items { grid-column: 1 / -1; grid-row: 2; grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .brand h1 { font-size: 18px; }
  .brand-mark { width: 42px; height: 42px; }
  .topbar > .button { width: 42px; padding: 0; font-size: 0; }
  .topbar > .button svg { width: 20px; height: 20px; }
  .strip-separator, #headerTimeout { display: none; }
  .connection-strip { min-height: 40px; }
  .side-column { grid-template-columns: 1fr; }
  .workspace, .settings-panel, .preview-panel { padding: 16px; }
  .tabs { overflow-x: auto; grid-template-columns: repeat(4, minmax(88px, 1fr)); }
  .tab { min-width: 88px; font-size: 12px; }
  .section-heading { align-items: flex-start; }
  .ticket-editor { min-height: 280px; font-size: 13px; }
  .format-grid { grid-template-columns: 1fr; }
  .print-options { grid-template-columns: 1fr 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .hex-examples { grid-template-columns: 1fr; }
  .receipt-stage { min-height: 430px; padding-inline: 2px; }
  .receipt { width: min(245px, 100%); }
  .receipt.paper-80 { width: min(300px, 100%); }
  .quick-actions { gap: 6px; }
  .quick-actions button { min-height: 72px; font-size: 10px; }
  .activity-title { font-size: 13px; }
  .toast { left: 12px; right: 12px; bottom: 12px; min-width: 0; max-width: none; }
}
