/* -----------------------------------------------------------
 * style.css – Refactored after design-review (v2.1)
 * -----------------------------------------------------------
 * Changelog v2.1 (fix-mobile-width)
 * • Container nutzt jetzt die komplette Viewport-Breite auf kleinen Geräten
 * • Body-Padding auf Smartphones deutlich reduziert (8 px)
 * • Buttons & Toggle erhalten kleinere Offsets, damit nichts abgeschnitten wird
 * Changelog v2.2 (mobile-spacing-fix)
 * • Body horizontal padding on mobile reduced to 0 for less space on sides.
 * Changelog v2.3 (mobile-full-width-fix)
 * • HTML and Body horizontal padding on mobile reduced to 0.
 * • Container margin explicitly set to 0 on mobile.
 * ----------------------------------------------------------- */

/* ============ 1. Design Tokens ============ */
:root {
  /* Light gradient background  */
  --bg-gradient-light: linear-gradient(
    73deg,
    #e9f1ff 10%,
    #f5efff 50%,
    #fff0f3 90%
  );
  --bg-gradient-dark: linear-gradient(
    73deg,
    #1a2a45 10%,
    #2a1f3d 50%,
    #3d1e23 90%
  );

  /* Typography & Base */
  --font-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --radius: 0.75rem;
  --ease: 150ms ease-in-out;

  /* Neutrals (light) */
  --gray-100: #f8f8f8;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-700: #374151;
  --gray-900: #1f2937;

  /* Neutrals (dark) */
  --gray-800: #2a2a2a;
  --gray-850: #303030;
  --gray-950: #0f172a;

  /* Brand */
  --violet-500: #7b4bff;
  --violet-600: #7040f4;
  --violet-700: #6335e8;
  --brand-gradient: linear-gradient(72deg, #7b4bff 0%, #9b72cb 100%);

  /* Feedback */
  --success-bg-light: #e8f5e9;
  --success-bg-dark: rgba(27, 94, 32, 0.8);
  --error-bg-light: #ffebee;
  --error-bg-dark: rgba(183, 28, 28, 0.8);
  --success-border-light: #a5d6a7;
  --success-border-dark: #2e7d32;
  --error-border-light: #ef9a9a;
  --error-border-dark: #c62828;
  --success-text-light: #1b5e20;
  --success-text-dark: #c8e6c9;
  --error-text-light: #b71c1c;
  --error-text-dark: #ffcdd2;
}

/* Dark mode overrides */
body.dark-mode {
  --bg-gradient: var(--bg-gradient-dark);
  --text-color: #f1f3f9;
  --container-bg: #414244;
  --input-bg: var(--gray-800);
  --input-border: var(--gray-700);
  --placeholder: #a5abb6;
  --button-bg: var(--gray-850);
  --button-border: #a5abb6;
  --reset-text: #a5abb6;
  --output-bg: var(--gray-800);
  --output-border: var(--gray-700);
  --copy-info: #bdbdbd;
  --toggle-bg: #414244;
  --toggle-icon: #f1f3f9;
}

/* Light mode defaults */
body {
  --bg-gradient: var(--bg-gradient-light);
  --text-color: var(--gray-900);
  --container-bg: #ffffff;
  --input-bg: var(--gray-100);
  --input-border: var(--gray-300);
  --placeholder: var(--gray-400);
  --button-bg: #e0e0e0;
  --button-border: var(--gray-300);
  --reset-text: var(--gray-700);
  --output-bg: var(--gray-100);
  --output-border: var(--gray-300);
  --copy-info: #666;
  --toggle-bg: #e0e0e0;
  --toggle-icon: var(--gray-900);
}

/* ============ 2. Global Layout ============ */
html,
body {
  margin: 0;
  padding: 20px; /* Default padding for larger screens, overridden on small screens */
  font-family: var(--font-base);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  background-size: cover;
  color: var(--text-color);
  transition: background-image var(--ease), color var(--ease);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  box-sizing: border-box;
  width: 100%; /* Ensure html and body attempt to use full viewport width */
  overflow-x: hidden; /* Prevent accidental horizontal scroll */
}

.container {
  background: var(--container-bg);
  width: 800px;
  max-width: 100%;
  box-sizing: border-box;
  padding: 24px 24px 28px;
  border-radius: var(--radius);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  backdrop-filter: saturate(150%) blur(4px);
  transition: background var(--ease), box-shadow var(--ease);
  margin: 0 auto; /* Center container on desktop */
}
body.dark-mode .container {
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.45);
}

h1 {
  margin-bottom: 24px;
  font-size: 1.6rem;
  font-weight: 700;
  background-image: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
}

/* ============ 3. Form Controls ============ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

label {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color);
}

textarea, input, select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--input-border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--input-bg);
  color: var(--text-color);
  font-size: 1rem;
  transition: border-color var(--ease), box-shadow var(--ease),
    background var(--ease);
  box-sizing: border-box;
}
textarea {
    min-height: 120px;
    resize: vertical;
}

textarea::placeholder, input::placeholder {
  color: var(--placeholder);
}
textarea:hover, input:hover, select:hover {
  border-color: var(--violet-500);
}
textarea:focus, input:focus, select:focus {
  border-color: var(--violet-500);
  outline: none;
  box-shadow: 0 0 0 3px rgba(155, 114, 203, 0.35);
}

/* ============ 4. Buttons ============ */
.button-container {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 24px 0;
  justify-content: center;
}
button {
  flex: 1 1 120px;
  max-width: 200px;
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  transition: background var(--ease), box-shadow var(--ease),
    transform var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  color: var(--text-color);
}
#download-btn {
  background: var(--brand-gradient);
  border: none;
  color: #fff;
  transition: all var(--ease);
}
#download-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(123, 75, 255, 0.3);
}
#download-btn:active {
  transform: scale(0.97);
}
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* ============ 5. Output Area ============ */
.main-content {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 24px;
    align-items: start;
}

#qrcode-preview-container {
  padding: 16px;
  border: 1px solid var(--output-border);
  border-radius: var(--radius);
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%), var(--output-bg);
  color: var(--text-color);
  transition: background var(--ease), border-color var(--ease),
    color var(--ease);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  position: relative; /* Needed for animation positioning */
}

#qrcode {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

#qrcode > canvas,
#qrcode > img {
    max-width: 100%;
    height: auto !important;
    object-fit: contain;
}

#no-input-text {
    font-size: 0.9rem;
    color: var(--placeholder);
}


/* ============ 6. Theme Toggle ============ */
#theme-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 46px;
  height: 46px;
  padding: 8px;
  border-radius: 50%;
  background: var(--toggle-bg);
  border: 1px solid var(--button-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease),
    transform var(--ease);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.22);
  z-index: 1000;
}
#theme-toggle:hover {
  transform: scale(1.08);
}
#theme-toggle:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(155, 114, 203, 0.45);
}
#theme-toggle svg {
  width: 24px;
  height: 24px;
  fill: var(--toggle-icon);
  transition: fill var(--ease);
}
.moon-icon { display: none; }
body.dark-mode .sun-icon { display: none; }
body.dark-mode .moon-icon { display: block; }


/* ============ 7. Responsiveness ============ */
@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    .container {
        width: 100%;
        padding: 20px 16px;
    }
}

@media (max-width: 480px) {
  html {
    padding: 0;
  }
  body {
    padding: 8px 0;
  }
  .container {
    width: 100%;
    margin: 0;
    border-radius: 0;
  }
  h1 {
    font-size: 1.35rem;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  #theme-toggle {
    bottom: 15px;
    right: 15px;
  }
}

/* ============ 8. History Section ============ */
#history-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--input-border);
}

#history-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
  color: var(--text-color);
}

#history-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  justify-content: center;
}

.history-item {
  background: var(--output-bg);
  border: 1px solid var(--output-border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all var(--ease);
}

.history-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
  border-color: var(--violet-500);
}

body.dark-mode .history-item:hover {
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.history-item canvas,
.history-item img {
  max-width: 100px;
  height: auto !important;
  border-radius: calc(var(--radius) - 4px);
}

.history-item p {
  font-size: 0.8rem;
  color: var(--placeholder);
  margin: 0;
  word-break: break-all;
  text-align: center;
  /* Truncate text to max 2 lines */
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

@media (max-width: 480px) {
  #history-container {
    grid-template-columns: repeat(2, 1fr);
  }
}