:root {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --border: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

/* Header */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--text);
  color: white;
}
#app-header h1 { font-size: 18px; font-weight: 600; }
.icon-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.icon-btn:active { background: rgba(255,255,255,0.15); }

/* Screens */
.screen { display: none; padding: 16px; }
.screen.active { display: block; }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }

/* Input group */
.input-group {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.input-group input {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.input-group input:focus { border-color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:not(:disabled):active { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:active { background: var(--border); }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-lg { width: 100%; padding: 14px; font-size: 16px; font-weight: 600; margin-top: 16px; }

/* Scanner */
#scanner-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 4px;
  display: none;
}
#scanner-container.active { display: block; }
#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#scanner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scan-region {
  width: 70%;
  height: 40%;
  border: 2px solid rgba(255,255,255,0.7);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.4);
}
#btn-toggle-scanner { width: 100%; margin-top: 8px; }
#scanner-container.active + .input-group { margin-top: 8px; }

/* Form sections */
.form-section {
  margin-top: 16px;
}
.form-section label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

/* Chip group (claim types) */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
}
.chip.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* Media grid (photos) */
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.media-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}
.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.media-thumb .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Video preview */
#video-preview {
  width: 100%;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: #000;
}

/* Textarea */
textarea {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
textarea:focus { border-color: var(--primary); }

/* Order info display */
.order-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.order-row:last-child { border-bottom: none; }
.order-row .label { color: var(--text-secondary); }
.order-row .value { font-weight: 500; text-align: right; max-width: 60%; }

/* Recording screen */
.record-view {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
  display: flex;
  flex-direction: column;
}
#record-video-feed {
  flex: 1;
  width: 100%;
  object-fit: cover;
}
#record-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  gap: 8px;
  background: rgba(0,0,0,0.8);
}
#record-timer {
  font-size: 24px;
  font-weight: 700;
  color: #ef4444;
  font-variant-numeric: tabular-nums;
}
.btn-record-stop {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid white;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stop-icon {
  width: 24px;
  height: 24px;
  background: #ef4444;
  border-radius: 4px;
}
#record-label { color: white; font-size: 14px; }

/* History */
#history-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
#history-filters select {
  flex: 1;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: white;
}
.claim-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.claim-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.claim-card-header .awb { font-weight: 600; font-size: 14px; }
.status-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.status-badge.pending { background: #fef3c7; color: #92400e; }
.status-badge.filed { background: #dbeafe; color: #1e40af; }
.status-badge.approved { background: #d1fae5; color: #065f46; }
.status-badge.rejected { background: var(--danger-light); color: var(--danger); }
.claim-card-body { font-size: 13px; color: var(--text-secondary); }
.claim-card-body div { margin-bottom: 2px; }

/* Loading */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.9);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { font-size: 14px; color: var(--text-secondary); }

/* Toast */
#toast-container {
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: white;
  animation: slideUp 0.3s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }

.hidden { display: none !important; }

/* Select dropdown */
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}
