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

:root {
  --primary: #0066cc;
  --primary-dark: #004fa3;
  --success: #16a34a;
  --danger: #dc2626;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --header-bg: #1a1a2e;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; color: var(--text); background: var(--bg); }

/* ── Screens ──────────────────────────────────────────────────────────── */
.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ── Login ────────────────────────────────────────────────────────────── */
#screen-login {
  background: linear-gradient(160deg, #1a1a2e 0%, #0f3460 60%, #0066cc 100%);
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.login-container {
  background: var(--surface);
  border-radius: 20px;
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.login-logo { margin-bottom: 12px; }

.login-container h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--header-bg);
  margin-bottom: 4px;
  line-height: 1.3;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.app-header {
  background: var(--header-bg);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.header-title { font-weight: 700; font-size: 16px; }

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

.header-user { font-size: 13px; opacity: .8; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-icon {
  background: rgba(255,255,255,.15);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,.25); }

/* ── Capture content ──────────────────────────────────────────────────── */
.capture-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

/* ── Quick actions ────────────────────────────────────────────────────── */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quick-btn {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
  transition: border-color .15s, background .15s;
}
.quick-btn:active { background: #f0f7ff; border-color: var(--primary); }

.quick-icon { font-size: 22px; }

/* ── Form sections ────────────────────────────────────────────────────── */
.form-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--primary);
  margin-bottom: 12px;
}

.field-group { display: flex; flex-direction: column; gap: 4px; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.field-row:last-child { margin-bottom: 0; }

.field-group + .field-group { margin-top: 10px; }

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.req { color: var(--danger); }

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
input::placeholder, textarea::placeholder { color: #b0b7c3; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
textarea { resize: none; }

.input-with-btn { display: flex; gap: 6px; }
.input-with-btn input { flex: 1; }
.btn-inline {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── GPS ──────────────────────────────────────────────────────────────── */
.gps-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

.btn-gps {
  background: #f0f7ff;
  color: var(--primary);
  border: 1.5px solid #c7dfff;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-gps:disabled { opacity: .6; }

.gps-status { font-size: 12px; color: var(--text-muted); }
.gps-status.ok { color: var(--success); font-weight: 600; }
.gps-status.error { color: var(--danger); }

/* ── Toggles ──────────────────────────────────────────────────────────── */
.toggles-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #f9fafb;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 500;
}

.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 24px;
  transition: background .2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ── Photos ───────────────────────────────────────────────────────────── */
.photos-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-remove {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }

.btn-secondary {
  background: #f3f4f6;
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-full { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

.btn-save { margin-top: 4px; padding: 16px; font-size: 16px; }

/* ── Errors ───────────────────────────────────────────────────────────── */
.error-msg {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 8px;
}

/* ── Success screen ───────────────────────────────────────────────────── */
#screen-success {
  background: var(--bg);
  justify-content: center;
  align-items: center;
  padding: 32px;
}

.success-container {
  text-align: center;
  max-width: 320px;
}

.success-icon {
  width: 72px; height: 72px;
  background: var(--success);
  color: white;
  border-radius: 50%;
  font-size: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.success-container h2 { font-size: 22px; margin-bottom: 10px; }

.success-detail {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
  min-height: 20px;
}

/* ── Modals ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: flex-end;
  z-index: 500;
}
.modal[hidden] { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  font-weight: 700;
  font-size: 16px;
}
.modal-header button {
  background: #f3f4f6;
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
}

.modal-actions { display: flex; gap: 10px; padding: 12px 16px 16px; }
.modal-actions .btn-secondary, .modal-actions .btn-primary { flex: 1; }

.barcode-modal .field-group { padding: 0 16px 8px; }

.camera-container { position: relative; }
.camera-container video { width: 100%; max-height: 60vh; object-fit: cover; }
.camera-actions { display: flex; gap: 10px; padding: 12px 16px; }
.camera-actions .btn-secondary, .camera-actions .btn-primary { flex: 1; }

/* ── Responsive (wider screens) ───────────────────────────────────────── */
@media (min-width: 500px) {
  .capture-content { max-width: 480px; margin: 0 auto; }
  .modal-content { max-width: 480px; margin: 0 auto; border-radius: 20px; margin-bottom: 40px; }
  .modal { align-items: center; }
  #screen-login { padding: 32px; }
}
