/* ScanSnap - QR Code Scanner & Generator PWA */
/* Mobile-first responsive design with dark mode support */

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --accent: #d63050;
  --accent-hover: #c02845;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b8;
  --text-muted: #8b8ba0;
  --border: #2a2a4a;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #ef4444;
  --touch-target: 48px;
  --nav-height: 64px;
  --transition: 0.3s ease;
}

/* Light mode - prefers-color-scheme support */
@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-card: #e8e8ee;
    --text-primary: #1a1a2e;
    --text-secondary: #555566;
    --text-muted: #646475;
    --border: #d0d0d8;
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

/* ── App Layout ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

@media (min-width: 768px) {
  .app {
    max-width: 480px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  min-height: var(--touch-target);
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  border-radius: 12px;
  transition: background var(--transition);
}

.header-btn:hover {
  background: var(--bg-card);
}

/* ── Screens ── */
.screen {
  flex: 1;
  overflow-y: auto;
  display: none;
  padding-bottom: var(--nav-height);
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ── Scanner Screen ── */
.scanner-screen {
  position: relative;
  padding: 0;
  overflow: hidden;
}

.scanner-screen.active {
  display: flex;
}

.video-container {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

.video-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-frame {
  width: 240px;
  height: 240px;
  position: relative;
}

.scan-frame::before,
.scan-frame::after,
.scan-corner-bl,
.scan-corner-br {
  content: '';
  position: absolute;
  width: 40px;
  height: 40px;
  border-color: var(--accent);
  border-style: solid;
  border-width: 0;
}

.scan-frame::before {
  top: 0;
  left: 0;
  border-top-width: 3px;
  border-left-width: 3px;
  border-top-left-radius: 12px;
}

.scan-frame::after {
  top: 0;
  right: 0;
  border-top-width: 3px;
  border-right-width: 3px;
  border-top-right-radius: 12px;
}

.scan-corner-bl {
  bottom: 0;
  left: 0;
  border-bottom-width: 3px;
  border-left-width: 3px;
  border-bottom-left-radius: 12px;
}

.scan-corner-br {
  bottom: 0;
  right: 0;
  border-bottom-width: 3px;
  border-right-width: 3px;
  border-bottom-right-radius: 12px;
}

.scan-line {
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 2px;
  background: var(--accent);
  animation: scanLine 2s ease-in-out infinite;
  box-shadow: 0 0 8px var(--accent);
}

@keyframes scanLine {
  0%, 100% { top: 5%; }
  50% { top: 95%; }
}

.scanner-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
  color: var(--text-secondary);
}

.scanner-placeholder .icon {
  font-size: 48px;
  opacity: 0.5;
}

.scanner-error {
  background: var(--danger);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 300px;
}

/* ── Scan Result Card ── */
.scan-result {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 20px 16px;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 20;
  max-height: 60%;
  overflow-y: auto;
}

.scan-result.visible {
  transform: translateY(0);
}

.scan-result-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.scan-result-type {
  display: inline-block;
  padding: 4px 10px;
  background: var(--accent);
  color: white;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.scan-result-content {
  font-size: 16px;
  word-break: break-all;
  margin-bottom: 16px;
  line-height: 1.5;
  color: var(--text-primary);
}

.scan-result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  text-decoration: none;
}

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

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
}

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

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-icon {
  padding: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: 10px;
}

.btn-full {
  width: 100%;
}

/* ── History Screen ── */
.history-screen {
  padding: 0;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 5;
}

.history-header h2 {
  font-size: 20px;
}

.history-list {
  padding: 0 16px 16px;
}

.history-group-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 0;
  margin-top: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background var(--transition);
  min-height: var(--touch-target);
}

.history-item:hover {
  background: var(--bg-card);
}

.history-item-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-radius: 10px;
  font-size: 18px;
  flex-shrink: 0;
}

.history-item-body {
  flex: 1;
  min-width: 0;
}

.history-item-content {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.history-item-type {
  font-size: 11px;
  padding: 2px 6px;
  background: var(--accent);
  color: white;
  border-radius: 6px;
  text-transform: uppercase;
  font-weight: 600;
}

.history-item-time {
  font-size: 12px;
  color: var(--text-muted);
}

.history-item-delete {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
}

.history-item-delete:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 32px;
  text-align: center;
  color: var(--text-secondary);
  gap: 12px;
}

.empty-state .icon {
  font-size: 48px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.5;
}

/* ── Generator Screen ── */
.generator-screen {
  padding: 16px;
}

.gen-type-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.gen-type-btn {
  padding: 8px 16px;
  border: 2px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  min-height: 44px;
}

.gen-type-btn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.gen-input-group {
  margin-bottom: 16px;
}

.gen-input-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.gen-input-group input,
.gen-input-group textarea,
.gen-input-group select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  transition: border-color var(--transition);
  min-height: var(--touch-target);
}

.gen-input-group input:focus,
.gen-input-group textarea:focus,
.gen-input-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.gen-input-group textarea {
  resize: vertical;
  min-height: 80px;
}

.gen-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  background: var(--bg-secondary);
  border-radius: 16px;
  margin-bottom: 16px;
}

.gen-preview canvas,
.gen-preview svg {
  border-radius: 8px;
  max-width: 256px;
  max-height: 256px;
}

.gen-preview-placeholder {
  padding: 48px;
  color: var(--text-muted);
  font-size: 14px;
}

.gen-actions {
  display: flex;
  gap: 8px;
}

.gen-actions .btn {
  flex: 1;
}

/* ── Settings Sheet ── */
.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.settings-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.settings-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 20px 16px;
  z-index: 101;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  max-height: 70%;
  overflow-y: auto;
}

.settings-sheet.visible {
  transform: translateY(0);
}

.settings-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.settings-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  min-height: var(--touch-target);
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-label {
  font-size: 15px;
}

.setting-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Toggle Switch */
.toggle {
  position: relative;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  border-radius: 15px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 24px;
  width: 24px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* ── Bottom Navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  max-width: 480px;
  margin: 0 auto;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--transition);
  min-height: var(--touch-target);
}

.nav-item.active {
  color: var(--accent);
}

.nav-item .nav-icon {
  font-size: 22px;
}

/* ── Offline Indicator ── */
.offline-bar {
  display: none;
  padding: 6px 16px;
  background: var(--warning);
  color: #000;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
}

.offline-bar.visible {
  display: block;
}

/* ── Confirm Dialog ── */
.confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.confirm-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.confirm-dialog {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 24px;
  margin: 16px;
  max-width: 320px;
  width: 100%;
}

.confirm-dialog h3 {
  margin-bottom: 8px;
  font-size: 17px;
}

.confirm-dialog p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.4;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── WiFi Details ── */
.wifi-details {
  margin-bottom: 12px;
}

.wifi-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.wifi-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.wifi-value {
  font-size: 14px;
  font-weight: 500;
}

.copy-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.3s ease;
}

/* ── Detail view ── */
.detail-view {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 90;
  display: none;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
}

.detail-view.visible {
  display: flex;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  min-height: var(--touch-target);
}

.detail-header button {
  min-width: 44px;
  min-height: 44px;
}

.detail-body {
  flex: 1;
  padding: 20px 16px;
  overflow-y: auto;
}

.detail-type {
  display: inline-block;
  padding: 4px 10px;
  background: var(--accent);
  color: white;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.detail-content {
  font-size: 16px;
  line-height: 1.6;
  word-break: break-all;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 12px;
}

.detail-time {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
