/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1a1a1a;
  --border: #222;
  --border-light: #2a2a2a;
  --text: #e5e5e5;
  --text-secondary: #737373;
  --text-tertiary: #525252;
  --accent: #3b82f6;
  --accent-dim: rgba(59, 130, 246, 0.12);
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  overscroll-behavior-y: none;
}

html {
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: fixed;
  width: 100%;
  overflow: hidden;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* (app shell defined above with html/body) */

/* ── Header ── */
.header {
  padding: calc(var(--safe-top) + 12px) 16px 10px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
}

.header-back {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  width: 36px;
}

.header-back:active {
  background: var(--surface-2);
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-action {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
}

.header-action:active {
  background: var(--surface-2);
  color: var(--text-secondary);
}

.version {
  font-family: var(--mono);
  font-size: 0.625rem;
  color: var(--text-tertiary);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

.logo {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
}

.logo-accent {
  color: var(--accent);
}

/* ── Settings Panel ── */
.settings-panel {
  margin-top: 10px;
  padding-bottom: 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideDown 0.2s ease;
}

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

.input-group label {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.input-group input {
  font-family: var(--mono);
  font-size: 0.875rem;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.input-group input::placeholder {
  color: var(--text-tertiary);
}

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

.btn-logout {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  text-align: left;
  transition: color 0.15s;
}

.btn-logout:active {
  color: var(--danger);
}

/* ── Views ── */
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view-list {
  padding: 0;
  padding-bottom: calc(var(--safe-bottom) + 100px);
}

.view-detail {
  padding: 16px;
  padding-bottom: calc(var(--safe-bottom) + 24px);
  gap: 16px;
}

/* ── FAB (Floating Action Button) ── */
.fab {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 28px);
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-tertiary);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: transform 0.15s ease, background 0.15s ease;
}

.fab:active {
  transform: translateX(-50%) scale(0.92);
  background: var(--border);
}

/* ── Empty State ── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 60px 20px;
}

.empty-icon {
  color: var(--text-tertiary);
  opacity: 0.4;
  margin-bottom: 4px;
}

.empty-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.empty-hint {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}

/* ── History List (iOS Mail style) ── */
.history-list {
  display: flex;
  flex-direction: column;
}

.history-row {
  position: relative;
  overflow: hidden;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg);
  position: relative;
  z-index: 1;
  will-change: transform;
}

.history-item:active {
  background: var(--surface);
}

.swipe-delete-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background: var(--danger);
  color: #fff;
  border: none;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 0;
}

.swipe-delete-btn:active {
  opacity: 0.8;
}

.history-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
}

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

.thumb-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: 0.625rem;
  font-weight: 600;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg);
}

.history-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-top-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.history-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.history-date {
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.history-summary {
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-chevron {
  color: var(--text-tertiary);
  flex-shrink: 0;
  opacity: 0.5;
}

/* ── Preview ── */
.preview-section {
  animation: fadeIn 0.25s ease;
}

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

.section-label {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

/* ── Preview Strip ── */
.preview-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.preview-strip::-webkit-scrollbar {
  height: 3px;
}

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

.preview-thumb {
  flex-shrink: 0;
  width: 200px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  scroll-snap-align: start;
}

.preview-thumb--single {
  width: 100%;
}

.preview-thumb img {
  width: 100%;
  display: block;
  max-height: 300px;
  object-fit: contain;
}

.preview-count {
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--text-tertiary);
}

/* ── Process Button ── */
.btn-process {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  animation: fadeIn 0.25s ease;
}

.btn-process:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn-process:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ── Progress ── */
.progress-section {
  animation: fadeIn 0.2s ease;
}

.progress-bar {
  height: 3px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.progress-label {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* ── Results ── */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.3s ease;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.btn-copy {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-dim);
  border: none;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-copy:active {
  opacity: 0.7;
}

.result-body {
  padding: 16px;
}

.result-body pre {
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.result-body p {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--text);
}

/* ── Lock Screen ── */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lock-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 260px;
}

.lock-logo {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
}

.lock-input-wrap {
  display: flex;
  width: 100%;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.lock-input-wrap input {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.875rem;
  padding: 12px 14px;
  background: transparent;
  border: none;
  color: var(--text);
  outline: none;
}

.lock-input-wrap input::placeholder {
  color: var(--text-tertiary);
}

.lock-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.15s;
}

.lock-btn:active {
  color: var(--accent);
}

.lock-error {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--danger);
  animation: fadeIn 0.2s ease;
}

/* ── Utilities ── */
.hidden {
  display: none !important;
}

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

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Detail Loading Spinner ── */
.detail-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
}

.detail-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

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

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