:root {
  --bg-app: #0e1117;
  --bg-surface: #161b24;
  --bg-panel: #1b222d;
  --bg-input: #10151d;
  --bg-hover: #242d3b;
  --border: #2a3444;
  --border-strong: #39465b;

  --text-main: #edf2f7;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --cyan: #06b6d4;
  --amber: #f59e0b;
  --purple: #a855f7;
  --emerald: #10b981;
  --danger: #ef4444;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  color: #cbd5e1;
}

/* Scrollbary */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #2f3a4c;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #425169;
}

/* Przyciski */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
  color: var(--text-main);
  background: transparent;
  white-space: nowrap;
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-secondary {
  background: var(--bg-panel);
  border-color: var(--border-strong);
  color: var(--text-main);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
}
.btn-ghost {
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.06);
}
.btn-danger-outline {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}
.btn-danger-outline:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.14);
}
.btn-full {
  width: 100%;
}
.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}
.btn-xs {
  padding: 4px 8px;
  font-size: 11.5px;
}
.btn-icon {
  padding: 0;
  width: 34px;
  height: 34px;
  font-size: 15px;
  align-self: end;
}
.btn-icon.active {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--primary);
  color: #93c5fd;
}

/* Pola formularza */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.stack-compact {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
}
.field input[type="text"],
.field input[type="password"],
.field input[type="email"],
.field input[type="url"],
.field input[type="number"],
.field select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-main);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.22);
}

.field-hint {
  margin: 4px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.45;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-main);
  user-select: none;
}
.checkbox-row input[type="checkbox"] {
  margin-top: 2px;
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.grid-sheet-dims {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 34px;
  gap: 8px;
}
.grid-gap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr);
  gap: 8px;
}

/* Modale i ekran logowania */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 14, 0.8);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.modal-card.modal-wide {
  max-width: 740px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.modal-actions .spacer {
  flex: 1;
}

.login-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.login-brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.login-brand .subtitle {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12.5px;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.lang-btn:hover {
  color: var(--text-main);
}
.lang-btn.active {
  background: var(--primary);
  color: #ffffff;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #0d1419;
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.brand-mark.small {
  width: 30px;
  height: 30px;
  border-radius: 7px;
}
.brand-logo-img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  display: block;
}

.alert-error {
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: var(--radius);
  color: #fecaca;
  font-size: 12px;
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.method-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-users-section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.subsection-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #cbd5e1;
}
.users-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 145px;
  overflow-y: auto;
}
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
}
.user-row-info {
  display: flex;
  align-items: center;
  gap: 8px;
}
.grid-user-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 105px auto;
  gap: 8px;
  align-items: end;
}
.btn-save-user {
  height: 34px;
}

.static-config-section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.static-config-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.static-config-info strong {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #cbd5e1;
}
#btn-export-config {
  flex-shrink: 0;
}

/* Układ główny aplikacji */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-header {
  height: 54px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.header-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.app-name {
  font-size: 14.5px;
  font-weight: 700;
  white-space: nowrap;
}
.pill-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
  color: #67e8f9;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
}
.user-badge #user-display-name {
  color: var(--text-main);
  font-weight: 600;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}
.status-dot.configured {
  background: var(--emerald);
}

.role-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.role-badge.role-admin {
  background: rgba(168, 85, 247, 0.2);
  border: 1px solid rgba(168, 85, 247, 0.5);
  color: #e9d5ff;
}
.role-badge.role-client {
  background: rgba(6, 182, 212, 0.16);
  border: 1px solid rgba(6, 182, 212, 0.45);
  color: #a5f3fc;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
}

.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Panel boczny */
.sidebar {
  width: 365px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #cbd5e1;
}

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: 14px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
}
.dropzone-icon {
  font-size: 22px;
  line-height: 1;
}
.dropzone-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.dropzone-text strong {
  font-size: 12.5px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dropzone-text span {
  font-size: 11px;
  color: var(--text-muted);
}

.info-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.info-box span {
  color: var(--text-muted);
}
.info-box strong {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #cbd5e1;
}

/* Obszar roboczy podglądu */
.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #0b0e13;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.stats-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
}
.stats-actions .btn-primary {
  min-height: 44px;
  padding: 0 18px;
  font-size: 13px;
}
.stat-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  min-width: 115px;
}
.stat-label {
  font-size: 10.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-value {
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-main);
}
.stat-item.accent-rotated {
  border-color: rgba(168, 85, 247, 0.45);
}
.stat-item.accent-rotated .stat-value {
  color: #d8b4fe;
}
.stat-item.accent-total {
  border-color: rgba(59, 130, 246, 0.5);
  background: rgba(59, 130, 246, 0.09);
}
.stat-item.accent-total .stat-value {
  color: #93c5fd;
}
.stat-item.accent-fit {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.09);
}
.stat-item.accent-fit .stat-value {
  color: #6ee7b7;
}

.canvas-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px);
  background-size: 20px 20px;
}

#preview-canvas {
  display: block;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
  border-radius: 2px;
  background: #ffffff;
}

.empty-state {
  max-width: 440px;
  text-align: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-lg);
}
.empty-icon {
  font-size: 36px;
  margin-bottom: 8px;
}
.empty-state h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.empty-state p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 12.5px;
}
.empty-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.workspace-footer {
  height: 44px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}
.swatch-trim {
  border: 2px solid var(--cyan);
  background: rgba(6, 182, 212, 0.15);
}
.swatch-bleed {
  border: 1.5px dashed var(--amber);
  background: rgba(245, 158, 11, 0.15);
}
.swatch-rotated {
  border: 2px solid var(--purple);
  background: rgba(168, 85, 247, 0.25);
}
.swatch-crop {
  background: #e2e8f0;
  height: 2px;
  width: 14px;
}
.swatch-margin {
  border: 1.5px dashed #94a3b8;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.zoom-controls input[type="range"] {
  width: 100px;
  accent-color: var(--primary);
}
.zoom-label {
  font-family: var(--font-mono);
  font-size: 11.5px;
  min-width: 40px;
  text-align: right;
  color: var(--text-muted);
}

/* Tabela historii */
.table-wrap {
  max-height: 55vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.history-table th,
.history-table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.history-table th {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
}
.empty-cell {
  text-align: center !important;
  color: var(--text-muted);
  padding: 24px !important;
}
.status-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.status-pill.ok {
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
}
.status-pill.local {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}
.status-pill.err {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
}

/* Toast */
.toast-container {
  position: fixed;
  right: 18px;
  bottom: 58px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  max-width: 390px;
}
.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 11px 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: toast-in 0.2s ease-out;
}
.toast.success {
  border-left-color: var(--emerald);
}
.toast.warning {
  border-left-color: var(--amber);
}
.toast.error {
  border-left-color: var(--danger);
}
.toast-title {
  font-weight: 700;
  font-size: 12.5px;
}
.toast-body {
  font-size: 12px;
  color: var(--text-muted);
}
.toast-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsywność */
@media (max-width: 960px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }
  .app-header {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  .header-right {
    flex-wrap: wrap;
  }
  .app-layout {
    flex-direction: column;
    overflow: visible;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .canvas-stage {
    min-height: 460px;
  }
  .workspace-footer {
    height: auto;
    padding: 10px 14px;
    flex-wrap: wrap;
  }
  .static-config-section {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Ostrzeżenia układu (margines, spad, limit, układ mieszany) */
.layout-warnings {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}
.layout-warnings.hidden {
  display: none;
}
.layout-warning {
  font-size: 12px;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: var(--radius);
  border-left: 3px solid var(--primary);
  background: rgba(59, 130, 246, 0.1);
  color: var(--text-main);
}
.layout-warning.warning {
  border-left-color: var(--amber);
  background: rgba(245, 158, 11, 0.12);
}
.layout-warning.error {
  border-left-color: var(--danger);
  background: rgba(239, 68, 68, 0.14);
}
.info-notes {
  grid-column: 1 / -1;
  font-size: 11.5px;
  color: var(--amber);
}
#login-firstrun-hint {
  color: var(--amber);
}
.dropzone:focus-visible,
.btn:focus-visible,
.lang-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
#info-pdfx.pdfx-ok {
  color: var(--emerald);
}
