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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --primary: #e94560;
  --text: #eee;
  --text-dim: #999;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  text-align: center;
  padding: 24px 16px 16px;
}

header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 4px;
}

#permission-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  min-height: 50vh;
}

.permission-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

#permission-screen h2 {
  font-size: 1.3rem;
  margin-bottom: 12px;
}

#permission-screen p {
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 340px;
}

.permission-error {
  color: #e74c3c;
  font-size: 0.85rem;
  margin-top: 16px;
  padding: 12px;
  background: rgba(231,76,60,0.1);
  border-radius: 8px;
  max-width: 340px;
  line-height: 1.4;
}

#camera-section {
  padding: 16px;
}

#camera-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  aspect-ratio: 3/4;
}

#video, #canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#camera-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.guide-corner {
  position: absolute;
  width: 50px;
  height: 50px;
  border-color: rgba(255,255,255,0.5);
  border-style: solid;
}

.guide-corner.top-left { top: 20px; left: 20px; border-width: 3px 0 0 3px; }
.guide-corner.top-right { top: 20px; right: 20px; border-width: 3px 3px 0 0; }
.guide-corner.bottom-left { bottom: 20px; left: 20px; border-width: 0 0 3px 3px; }
.guide-corner.bottom-right { bottom: 20px; right: 20px; border-width: 0 3px 3px 0; }

#camera-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 24px;
  border: none;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  min-width: 140px;
}

.btn:active {
  transform: scale(0.96);
}

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

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

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
}

.btn-capture {
  background: var(--primary);
  color: #fff;
  width: 160px;
}

.btn-flip {
  background: var(--surface2);
  color: var(--text);
}

.btn-danger {
  background: #c0392b;
  color: #fff;
  padding: 10px 16px;
  min-width: auto;
  font-size: 0.85rem;
}

.icon {
  font-size: 1.1rem;
}

#preview-section {
  margin-top: 16px;
  text-align: center;
}

#preview {
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

#preview-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

#loading {
  text-align: center;
  padding: 32px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--surface2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

#documents-section {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

#documents-section h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
}

.empty-msg {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  padding: 20px;
}

#documents-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.2s;
  overflow: hidden;
}

.doc-card:active {
  background: var(--surface2);
}

.doc-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
}

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

.doc-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.doc-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

@media (max-width: 400px) {
  .btn {
    padding: 12px 16px;
    font-size: 0.9rem;
    min-width: 120px;
  }
  #camera-controls {
    flex-direction: column;
    align-items: center;
  }
}
