/* ===== Reset & Variables ===== */
:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-elevated: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --border: #334155;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ===== App Container ===== */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 80px;
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 0 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.header-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), #1d4ed8);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.header-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-sub {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.header-badge {
  margin-left: auto;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.3s;
}

.header-badge.active {
  background: var(--accent);
  color: white;
}

/* ===== Selectors ===== */
.selectors {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.selector-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.selector-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.custom-select {
  position: relative;
}

.select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.select-trigger:active {
  background: var(--bg-elevated);
}

.select-trigger.open {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.select-trigger span {
  font-size: 15px;
  color: var(--text-secondary);
  flex: 1;
}

.select-trigger .arrow {
  transition: transform 0.2s;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.select-trigger.open .arrow {
  transform: rotate(180deg);
}

.select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s;
  opacity: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}

.select-dropdown.open {
  max-height: 320px;
  opacity: 1;
  overflow-y: auto;
}

.dropdown-search {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
}

.dropdown-search input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.dropdown-search input:focus {
  border-color: var(--accent);
}

.dropdown-options {
  padding: 4px;
}

.dropdown-option {
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.dropdown-option:hover,
.dropdown-option:active {
  background: var(--bg-elevated);
}

.dropdown-option.selected {
  background: rgba(59,130,246,0.15);
  color: var(--accent);
  font-weight: 500;
}

/* ===== Camera ===== */
.camera-section {
  margin-bottom: 16px;
}

.camera-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.camera-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.camera-preview video.active {
  display: block;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-secondary);
}

.camera-placeholder p {
  font-size: 14px;
}

.capture-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.capture-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.capture-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.capture-btn.uploading {
  background: var(--warning);
  pointer-events: none;
}

/* ===== Queue ===== */
.queue-section {
  margin-bottom: 16px;
}

.queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.queue-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.queue-count {
  font-size: 13px;
  color: var(--text-secondary);
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.queue-item-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.queue-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.queue-item-info {
  flex: 1;
  min-width: 0;
}

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

.queue-item-info .meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.queue-item-status {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  flex-shrink: 0;
}

.queue-item-status.pending {
  background: rgba(245,158,11,0.15);
  color: var(--warning);
}

.queue-item-status.uploading {
  background: rgba(59,130,246,0.15);
  color: var(--accent);
}

.queue-item-status.done {
  background: rgba(34,197,94,0.15);
  color: var(--success);
}

.queue-item-status.error {
  background: rgba(239,68,68,0.15);
  color: var(--error);
}

/* ===== Recent ===== */
.recent-section {
  margin-bottom: 16px;
}

.recent-header {
  margin-bottom: 10px;
}

.recent-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recent-item {
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
}

.recent-item-info .type {
  font-size: 14px;
  font-weight: 500;
}

.recent-item-info .meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ===== Permission Overlay ===== */
.permission-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.permission-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.permission-card {
  background: var(--bg-card);
  padding: 32px 24px;
  border-radius: var(--radius);
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: var(--shadow);
}

.permission-icon {
  margin-bottom: 16px;
}

.permission-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.permission-card p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.permission-btn {
  padding: 12px 32px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

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

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s;
  z-index: 50;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

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

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

/* ===== Safe Area ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  .header {
    padding-top: calc(20px + env(safe-area-inset-top));
  }
  #app {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}
