/* CSS Reset & Variable Definitions */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --secondary-hover: #475569;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition-fast: 0.2s ease;
  --max-width: 1000px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Layout Container */
.main-content {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* Header & Nav Styling */
.app-header {
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1rem 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 36px;
  height: 36px;
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav-tabs {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0 1rem;
  overflow-x: auto;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--primary);
  background-color: var(--primary-light);
  border-top-left-radius: var(--radius-sm);
  border-top-right-radius: var(--radius-sm);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Tab Panels */
.tab-panel {
  display: block;
  animation: fadeIn 0.25s ease-in-out;
}

.tab-panel.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Base Card Styling */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

/* Base Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-card);
  color: var(--text-main);
  transition: border-color var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-helper {
  font-size: 0.775rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-outline {
  background-color: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline:hover {
  background-color: var(--primary-light);
}

.btn-danger-outline {
  background-color: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger-outline:hover {
  background-color: #fef2f2;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.825rem;
}

.btn-block {
  width: 100%;
}

.flex-1 {
  flex: 1;
}

.hidden {
  display: none !important;
}

.icon {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

.icon-lg {
  width: 3rem;
  height: 3rem;
  color: var(--text-muted);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 9999px;
  background-color: var(--primary-light);
  color: var(--primary);
}

.badge-success {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-type {
  background-color: #e0e7ff;
  color: #3730a3;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background-color: #1e293b;
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideInRight 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(10px); }
}

/* SCANNER STYLING */
.scanner-header, .generator-header, .history-header {
  margin-bottom: 1.25rem;
}

.scanner-header h2, .generator-header h2, .history-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
}

.subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.scanner-modes {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  background-color: var(--bg-subtle);
  padding: 0.35rem;
  border-radius: var(--radius-md);
}

.btn-mode {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem;
  border: none;
  background: transparent;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-mode.active {
  background-color: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.camera-controls {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1rem;
}

.reader-container {
  position: relative;
  width: 100%;
  min-height: 280px;
  background-color: #0f172a;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader-viewport {
  width: 100%;
  max-width: 500px;
}

.camera-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: #94a3b8;
  padding: 2rem;
  text-align: center;
}

/* File Upload Drop Zone */
.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 3rem 1.5rem;
  text-align: center;
  background-color: var(--bg-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.drop-title {
  font-weight: 600;
  font-size: 1rem;
  margin-top: 0.5rem;
}

.drop-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.file-preview-container img {
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

/* Scan Result Quick Actions */
.result-card {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background-color: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.result-textarea {
  font-family: monospace;
  font-size: 0.95rem;
  background-color: var(--bg-card);
  resize: vertical;
}

.result-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

/* GENERATOR STYLING */
.generator-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.colors-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-card);
}

.color-picker-wrapper input[type="color"] {
  border: none;
  width: 28px;
  height: 28px;
  cursor: pointer;
  background: transparent;
}

.options-accordion {
  background-color: var(--bg-subtle);
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
}

.options-accordion h3 {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.generator-preview-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-box {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  position: relative;
}

.preview-label {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.code-output {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  overflow-x: auto;
  padding: 1rem;
  background-color: #ffffff;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.code-output canvas, .code-output svg, .code-output img {
  max-width: 100%;
  height: auto !important;
  display: block;
}

.error-box {
  background-color: #fef2f2;
  color: var(--danger);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  width: 100%;
}

.download-actions {
  display: flex;
  gap: 0.75rem;
}

/* HISTORY STYLING */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.history-actions-top {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.history-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.search-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.125rem;
  height: 1.125rem;
  color: var(--text-muted);
}

.search-wrapper input {
  padding-left: 2.5rem;
}

.filter-chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
}

.chip {
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.chip.active {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  gap: 1rem;
  transition: all var(--transition-fast);
}

.history-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow: hidden;
  flex: 1;
}

.history-item-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.history-item-content {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: monospace;
}

.history-item-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-item-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background-color: var(--border-color);
  color: var(--text-main);
}

.btn-icon.fav-active {
  color: var(--warning);
}

.empty-history {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

/* Footer Styling */
.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-card);
  margin-top: auto;
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .generator-grid {
    grid-template-columns: 1fr;
  }

  .camera-controls {
    flex-direction: column;
    align-items: stretch;
  }

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

  .history-actions-top {
    justify-content: flex-start;
  }
}
