:root {
  --bg-primary: #ffffff;
  --bg-secondary: #ffffff;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --border: rgba(17, 24, 39, 0.1);
  --text-primary: #111111;
  --text-secondary: #525252;
  --button-bg: #111111;
  --button-text: #ffffff;
  --shadow: 0 18px 40px rgba(17, 24, 39, 0.06);
  --preview-bg: #fafafa;
  --preview-pattern: rgba(17, 24, 39, 0.03);
}

body[data-theme="dark"] {
  --bg-primary: #0d0d0d;
  --bg-secondary: #0d0d0d;
  --surface: #151515;
  --surface-strong: #181818;
  --border: rgba(255, 255, 255, 0.09);
  --text-primary: #f5f5f5;
  --text-secondary: #c7c7c7;
  --button-bg: #ffffff;
  --button-text: #111111;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.24);
  --preview-bg: #101010;
  --preview-pattern: rgba(255, 255, 255, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--bg-primary), var(--bg-secondary));
  color: var(--text-primary);
}

.theme-switch {
  position: static;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: fit-content;
  max-width: max-content;
  padding: 0.55rem 0.7rem 0.55rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow);
}

.theme-switch-track {
  width: 58px;
  height: 32px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.1);
  display: flex;
  align-items: center;
}

.theme-switch-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--button-bg);
  color: var(--button-text);
  display: grid;
  place-items: center;
  transform: translateX(0);
  transition: transform 180ms ease, background-color 180ms ease, color 180ms ease;
}

body[data-theme="dark"] .theme-switch-thumb {
  transform: translateX(26px);
}

.theme-icon {
  width: 14px;
  height: 14px;
  display: none;
}

.theme-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.theme-icon-sun {
  display: block;
}

body[data-theme="dark"] .theme-icon-sun {
  display: none;
}

body[data-theme="dark"] .theme-icon-moon {
  display: block;
}

.theme-switch-label {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}

.app-shell {
  width: min(960px, calc(100% - 2rem));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 360px);
  grid-template-areas:
    "switch switch"
    "panel preview"
    "bulk bulk"
    "history history";
  gap: 1.5rem;
  align-items: stretch;
  padding: 2rem 0 1rem;
}

body {
  display: flex;
  flex-direction: column;
}

main.app-shell {
  flex: 1;
}

#theme-toggle {
  grid-area: switch;
  justify-self: center;
  align-self: center;
  margin-bottom: 0.5rem;
}

.panel,
.preview-card,
.bulk-panel,
.history-panel {
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  grid-area: panel;
}

.preview-card {
  grid-area: preview;
}

.bulk-panel {
  grid-area: bulk;
  padding: 1.5rem;
  display: grid;
  gap: 1.25rem;
}

.history-panel {
  grid-area: history;
  padding: 1.5rem;
  display: grid;
  gap: 1.25rem;
}

.panel {
  padding: 2rem;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.panel-copy h1 {
  margin: 0;
  font-family: "Manrope", "Inter", sans-serif;
  font-size: clamp(2rem, 4vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.04em;
}

.preview-copy h2 {
  margin: 0;
  font-family: "Manrope", "Inter", sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.panel-copy p,
.preview-copy p,
.status-message {
  margin: 0;
  color: var(--text-secondary);
  font-family: "Inter", "Segoe UI", sans-serif;
}

.panel-copy {
  display: grid;
  gap: 0.5rem;
}

.generator-form {
  display: grid;
  gap: 1.25rem;
  flex: 1;
}

.type-switch {
  margin: 0;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-strong);
  display: inline-flex;
  gap: 0.35rem;
}

.type-switch legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.type-option {
  position: relative;
  cursor: pointer;
}

.type-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.type-option span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  color: var(--text-secondary);
  transition: background-color 140ms ease, color 140ms ease;
}

.type-option input:checked + span {
  background: var(--button-bg);
  color: var(--button-text);
}

.field-group {
  display: grid;
  gap: 0.65rem;
}

.field-group span {
  font-size: 0.95rem;
  font-weight: 500;
}

input[type="url"],
input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-strong);
  transition: border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

input[type="url"]:focus,
input[type="text"]:focus,
textarea:focus,
input[type="color"]:focus {
  outline: none;
  border-color: rgba(217, 119, 6, 0.75);
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.12);
}

textarea {
  resize: vertical;
  min-height: 180px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.color-field {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface-strong);
  padding: 1rem;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

input[type="color"] {
  width: 56px;
  height: 56px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

output {
  font-size: 0.95rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

button {
  border: none;
  border-radius: 999px;
  padding: 1rem 1.25rem;
  font: inherit;
  font-weight: 700;
  color: var(--button-text);
  background: var(--button-bg);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(17, 24, 39, 0.18);
}

.download-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.download-button {
  padding: 0.85rem 1rem;
  border-radius: 16px;
  color: var(--text-primary);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  box-shadow: none;
}

.download-button:hover {
  box-shadow: 0 10px 18px rgba(17, 24, 39, 0.08);
}

.status-message {
  min-height: 1.25rem;
  font-size: 0.94rem;
}

.status-message.error {
  color: #b42318;
}

.status-message.success {
  color: #166534;
}

.preview-card {
  padding: 1.5rem;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 1.25rem;
  justify-items: center;
  align-content: start;
}

.preview-copy {
  width: 100%;
  display: grid;
  gap: 0.4rem;
}

.helper-copy {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.bulk-copy {
  display: grid;
  gap: 0.4rem;
}

.bulk-copy h2 {
  margin: 0;
  font-family: "Manrope", "Inter", sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.bulk-copy p,
.bulk-status,
.bulk-item-value {
  margin: 0;
  color: var(--text-secondary);
}

.bulk-form {
  display: grid;
  gap: 1rem;
}

.bulk-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.bulk-generate {
  padding-inline: 1.5rem;
}

.bulk-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.bulk-download-all {
  display: none;
}

.bulk-download-all.is-visible {
  display: inline-flex;
}

.bulk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.bulk-item {
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface-strong);
  padding: 1rem;
  display: grid;
  gap: 0.85rem;
}

.bulk-item canvas {
  width: 100%;
  max-width: 180px;
  height: auto;
  margin: 0 auto;
  border-radius: 16px;
  background: #ffffff;
}

.bulk-item-meta {
  display: grid;
  gap: 0.4rem;
}

.bulk-item-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.bulk-item-value {
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.bulk-item .download-button {
  width: 100%;
}

.bulk-item-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.history-list {
  display: grid;
  gap: 0.9rem;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface-strong);
  padding: 1rem;
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr) 130px;
  gap: 1rem;
  align-items: start;
}

.history-thumb {
  width: 168px;
  height: 168px;
  border-radius: 16px;
  background: #ffffff;
  display: block;
}

.history-content {
  display: grid;
  gap: 0.35rem;
}

.history-title,
.history-value,
.history-meta {
  margin: 0;
}

.history-title {
  font-size: 1rem;
  font-weight: 700;
}

.history-value,
.history-meta {
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.history-actions {
  display: grid;
  gap: 0.5rem;
  width: 130px;
}

.preview-frame {
  width: 100%;
  min-height: 340px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(145deg, var(--preview-bg), var(--preview-bg)),
    repeating-linear-gradient(
      45deg,
      var(--preview-pattern),
      var(--preview-pattern) 12px,
      transparent 12px,
      transparent 24px
    );
  border: 1px solid var(--border);
  flex: 1;
}

#qr-canvas {
  width: min(100%, 280px);
  height: auto;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(17, 24, 39, 0.12);
}

.copyright {
  margin: -1rem 0 1.5rem;
  text-align: center;
  font-family: "Inter", "Segoe UI", sans-serif;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "switch"
      "panel"
      "preview"
      "bulk"
      "history";
    padding: 1.25rem 0;
  }

  .panel,
  .preview-card,
  .bulk-panel,
  .history-panel {
    padding: 1.25rem;
  }

  .panel-header {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 560px) {
  .theme-switch {
    width: fit-content;
    max-width: calc(100vw - 2rem);
  }

  .color-grid {
    grid-template-columns: 1fr;
  }

  .download-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bulk-toolbar,
  .bulk-results-header {
    align-items: stretch;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .history-actions,
  .bulk-item-actions {
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .type-switch {
    width: 100%;
    justify-content: space-between;
  }

  .preview-frame {
    min-height: 280px;
  }
}
