/* QR Code Tools - style.css */
/* Mobile-first, dark mode, responsive */

:root {
  --bg: #ffffff;
  --bg-card: #f8fafc;
  --bg-hover: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --border: #e2e8f0;
  --border-focus: #2563eb;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-sm: 4px;
  --transition: 150ms ease;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #1e3a5f;
    --border: #334155;
    --border-focus: #3b82f6;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -2px rgba(0,0,0,0.2);
  }
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Header */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}

.header h1 { margin: 0; font-size: 1.125rem; font-weight: 600; }

.theme-toggle {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text); transition: all var(--transition);
}
.theme-toggle:hover { background: var(--bg-hover); }
.theme-toggle:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.theme-toggle svg { width: 20px; height: 20px; }
.icon-sun { display: none; }
.icon-moon { display: block; }
.light .icon-sun { display: block; }
.light .icon-moon { display: none; }

/* Main */
.main {
  flex: 1; padding: 16px; max-width: 1200px; margin: 0 auto; width: 100%;
  display: grid; gap: 16px;
}

@media (min-width: 769px) {
  .main { grid-template-columns: 1fr 320px; align-items: start; }
}
@media (min-width: 1025px) {
  .main { grid-template-columns: 280px 1fr 320px; }
}

/* Type Selector */
.type-selector { 
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px;
}
@media (min-width: 769px) { .type-selector { grid-column: 1 / -1; } }

#typeSelect {
  width: 100%; padding: 12px 16px; font-size: 1rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px;
}
#typeSelect:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-color: var(--border-focus); }

/* Form */
.data-form { 
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: grid; gap: 16px;
}
@media (min-width: 769px) { .data-form { grid-column: 1; } }
@media (min-width: 1025px) { .data-form { grid-column: 1; } }

.field-group { display: grid; gap: 12px; }
.field-group.hidden { display: none; }

.grid-2 { display: grid; gap: 12px; }
@media (min-width: 481px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.input-wrap { display: grid; gap: 6px; }
.input-wrap.full { grid-column: 1 / -1; }
.input-wrap label { font-size: 0.8125rem; font-weight: 500; color: var(--text-muted); }

.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row > input, .input-row > textarea { flex: 1; }

input, textarea, select {
  font: inherit; font-size: 1rem;
  padding: 12px 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--primary-light);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 0.7; }
textarea { resize: vertical; min-height: 80px; }

input[type="color"] { height: 44px; padding: 4px; cursor: pointer; }
input[type="range"] { accent-color: var(--primary); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.875rem; color: var(--text); }
.checkbox-wrap { align-items: end; }

.icon-btn {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0 16px; font-size: 1.125rem; cursor: pointer; color: var(--text);
  transition: background var(--transition);
  min-width: 44px; display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-hover); }
.icon-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

/* Preview */
.preview-section {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: grid; gap: 12px; text-align: center;
}
@media (min-width: 769px) { .preview-section { grid-column: 2; } }
@media (min-width: 1025px) { .preview-section { grid-column: 2; } }

.preview-container {
  min-height: 256px; display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  position: relative; overflow: hidden;
}

.qr-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: var(--text-muted); padding: 24px;
}
.qr-placeholder svg { width: 64px; height: 64px; opacity: 0.4; }
.qr-placeholder p { margin: 0; font-size: 0.875rem; }

.qr-canvas { display: none; }
.qr-canvas:not(:empty) { display: block; }
.qr-canvas canvas, .qr-canvas svg { max-width: 100%; height: auto; }

.qr-meta { font-size: 0.75rem; color: var(--text-muted); min-height: 1.25rem; }

/* Options */
.options {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: grid; gap: 12px;
}
@media (min-width: 769px) { .options { grid-column: 2; } }
@media (min-width: 1025px) { .options { grid-column: 2; } }

.option-row { display: grid; gap: 8px; align-items: center; }
.option-row label { font-size: 0.8125rem; font-weight: 500; color: var(--text-muted); min-width: 90px; }
@media (min-width: 481px) {
  .option-row { grid-template-columns: auto 1fr; }
}

.color-text {
  width: 80px; font-family: var(--mono); font-size: 0.8125rem; text-transform: uppercase;
  padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text);
}

.btn-primary, .btn-secondary, .btn-danger {
  padding: 12px 24px; font-size: 0.875rem; font-weight: 500; border-radius: var(--radius);
  border: none; cursor: pointer; transition: all var(--transition);
  min-height: 44px; min-width: 44px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }
.btn-secondary:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-danger:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }

.actions-primary, .actions-secondary {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
@media (min-width: 769px) { .actions-primary, .actions-secondary { grid-column: 2; } }
@media (min-width: 1025px) { .actions-primary, .actions-secondary { grid-column: 2; } }

/* Footer */
.footer { text-align: center; padding: 16px; color: var(--text-muted); font-size: 0.75rem; border-top: 1px solid var(--border); margin-top: auto; }
@media (min-width: 769px) { .footer { grid-column: 1 / -1; } }

/* Modals */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  opacity: 0; visibility: hidden; transition: opacity var(--transition), visibility var(--transition);
}
.modal:not(.hidden) { opacity: 1; visibility: visible; }

.modal-content {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg: 12px);
  width: 100%; max-width: 480px; max-height: 90vh; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  transform: scale(0.95); transition: transform var(--transition);
}
.modal:not(.hidden) .modal-content { transform: scale(1); }

.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 1.125rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); padding: 4px; line-height: 1; }
.modal-close:hover { color: var(--text); }

.modal-body { padding: 16px; overflow-y: auto; display: grid; gap: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px; border-top: 1px solid var(--border); }

.progress { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; height: 8px; position: relative; }
.progress-bar { height: 100%; background: var(--primary); width: 0%; transition: width 200ms ease; }
.progress-text { position: absolute; right: 8px; top: -20px; font-size: 0.75rem; color: var(--text-muted); }

.hint { font-size: 0.75rem; color: var(--text-muted); margin: 0; }

.preset-list { display: grid; gap: 8px; }
.preset-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.preset-item button { padding: 6px 12px; font-size: 0.75rem; }

/* History */
#historyList { display: grid; gap: 8px; max-height: 400px; overflow-y: auto; }
.history-item { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: background var(--transition); }
.history-item:hover { background: var(--bg-hover); }
.history-item:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.history-qr { width: 48px; height: 48px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 4px; }
.history-info { flex: 1; min-width: 0; }
.history-type { font-weight: 500; font-size: 0.875rem; }
.history-data { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-time { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; }

/* Toast */
.toast-container { position: fixed; bottom: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 12px; min-width: 280px; max-width: 400px; animation: slideIn 200ms ease; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { border-left: 4px solid #16a34a; }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }
.toast-dismiss { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; font-size: 1.25rem; line-height: 1; }

/* Print sheet */
@media print {
  .header, .type-selector, .data-form, .options, .actions-primary, .actions-secondary, .footer, .modal { display: none !important; }
  .main { padding: 0; display: block; }
  .preview-section { border: none; box-shadow: none; padding: 0; }
  .preview-container { min-height: auto; border: none; }
  body { background: white; color: black; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* High contrast */
@media (prefers-contrast: high) {
  :root { --border: currentColor; --border-focus: currentColor; }
}

/* Focus visible polyfill */
:focus:not(:focus-visible) { outline: none; }

/* Custom scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }