:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef2f6;
  --line: #d8dee8;
  --text: #1d2733;
  --muted: #5f6c7b;
  --accent: #146c63;
  --accent-strong: #0d4f49;
  --danger: #b42318;
  --shadow: 0 18px 60px rgba(31, 41, 55, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 24px;
  width: min(1480px, calc(100% - 32px));
  margin: 24px auto;
  align-items: start;
}

.workspace,
.preview-card,
.history-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.workspace {
  padding: 22px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
}

.generator {
  display: grid;
  gap: 16px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
}

.type-button,
.primary-action,
.secondary-action,
.download {
  border: 0;
  border-radius: 7px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.type-button {
  min-height: 42px;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid transparent;
}

.type-button.active {
  background: var(--accent);
  color: #fff;
}

.panel {
  padding: 18px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  align-items: baseline;
}

.panel-title span,
#status,
.result-meta span {
  color: var(--muted);
  font-size: 14px;
}

.fields,
.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.controls {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.wide {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
}

input[type="color"] {
  padding: 4px;
}

input[type="range"] {
  padding: 0;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.checkline input {
  width: 18px;
  min-height: 18px;
}

.filepick input {
  padding: 8px;
}

.hidden {
  display: none;
}

.actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.primary-action {
  min-height: 48px;
  padding: 0 22px;
  background: var(--accent);
  color: #fff;
}

.secondary-action {
  min-height: 48px;
  padding: 0 18px;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
}

.primary-action:hover,
.download:hover {
  background: var(--accent-strong);
}

.secondary-action:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

#status.error {
  color: var(--danger);
}

.preview {
  position: sticky;
  top: 24px;
}

.preview-card {
  padding: 20px;
  box-shadow: var(--shadow);
}

.qr-frame {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.qr-frame img {
  width: min(86%, 320px);
  height: auto;
  display: block;
}

.result-meta {
  display: grid;
  gap: 6px;
  margin: 16px 0;
}

.result-meta span {
  max-height: 112px;
  overflow: auto;
  word-break: break-word;
}

.download-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.download {
  display: grid;
  min-height: 44px;
  place-items: center;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.download.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.utm-box {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
}

.utm-box summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 800;
}

.utm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.quality-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 16px;
}

.quality-grid div {
  padding: 10px;
  background: var(--surface-soft);
  border-radius: 7px;
}

.quality-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.quality-grid dd {
  margin: 2px 0 0;
  font-weight: 900;
}

#metric-score[data-score="średni"] {
  color: #986600;
}

#metric-score[data-score="ciężki"] {
  color: var(--danger);
}

.history-card {
  padding: 16px;
  margin-top: 14px;
  box-shadow: var(--shadow);
}

.history-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.history-title button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--muted);
  cursor: pointer;
  min-height: 34px;
  padding: 0 10px;
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-list button {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 54px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.history-list button:hover {
  border-color: var(--accent);
}

.history-list span,
.empty-history {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .preview {
    position: static;
  }

  .type-grid {
    grid-template-columns: repeat(4, minmax(100px, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: calc(100% - 20px);
    margin: 10px auto;
  }

  .workspace,
  .preview-card,
  .panel {
    border-radius: 6px;
  }

  .workspace {
    padding: 12px;
  }

  .topbar,
  .panel-title,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .type-grid,
  .fields,
  .controls,
  .utm-grid {
    grid-template-columns: 1fr;
  }
}
