/* ── Tokens ── */
:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --success: #2e7d32;
  --warn: #f9a825;
  --danger: #c62828;
  --bg: #fafafa;
  --card: #ffffff;
  --text: #212121;
  --text-muted: #757575;
  --border: #e0e0e0;
  --shadow: 0 1px 4px rgba(0,0,0,0.12);
  --radius: 10px;
  --touch: 44px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }

/* ── Layout ── */
#app { min-height: 100vh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; }

/* ── Top bar ── */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.topbar h1 { font-size: 17px; font-weight: 600; flex: 1; }
.topbar .role-badge { font-size: 12px; background: rgba(255,255,255,0.2); padding: 3px 10px; border-radius: 20px; }
.topbar .btn-icon { color: #fff; padding: 8px; min-width: var(--touch); min-height: var(--touch); display: flex; align-items: center; justify-content: center; }

/* ── Bottom tab bar ── */
.tabbar {
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 100;
  flex-shrink: 0;
}
.tabbar .tab {
  flex: 1;
  min-height: var(--touch);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 4px;
  border-top: 2px solid transparent;
}
.tabbar .tab.active { color: var(--primary); border-top-color: var(--primary); }
.tabbar .tab svg { width: 22px; height: 22px; }

/* ── PIN Gate ── */
.pin-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 24px;
}
.pin-screen .logo { width: 120px; height: 120px; object-fit: contain; border-radius: 50%; }
.pin-screen h2 { font-size: 20px; font-weight: 600; color: var(--text); }
.pin-screen p { color: var(--text-muted); font-size: 14px; text-align: center; }
.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 8px 0; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); background: var(--bg); transition: background .15s; }
.pin-dot.filled { background: var(--primary); border-color: var(--primary); }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; max-width: 280px; }
.numpad .key {
  height: 64px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 22px;
  font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  transition: background .1s;
}
.numpad .key:active { background: #e8f0fe; }
.numpad .key.del { font-size: 16px; color: var(--text-muted); }
.admin-link { font-size: 13px; color: var(--text-muted); margin-top: 8px; }
.admin-link a { color: var(--primary); }

/* ── Login Screen ── */
.login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  gap: 20px;
}
.login-screen h2 { font-size: 20px; font-weight: 600; }
.form-group { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.form-group select, .form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  background: var(--card);
  outline: none;
  transition: border-color .15s;
}
.form-group select:focus, .form-group input:focus { border-color: var(--primary); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch);
  padding: 0 20px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  transition: opacity .15s, background .15s;
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border: none; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; border: none; }
.btn-danger { background: var(--danger); color: #fff; border: none; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-full { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; }

/* ── Cards / Queue ── */
.screen-content { flex: 1; overflow-y: auto; padding: 12px; }
.section-heading { font-size: 15px; font-weight: 600; padding: 8px 4px; color: var(--text-muted); }
.card-list { display: flex; flex-direction: column; gap: 10px; }
.sample-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  padding: 12px;
  cursor: pointer;
  transition: box-shadow .15s;
  border: 1.5px solid transparent;
}
.sample-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.15); }
.sample-card .thumb {
  width: 80px; height: 80px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--border);
  border: 1px solid var(--border);
  overflow: hidden;
}
.sample-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.sample-card .thumb svg { width: 36px; height: 36px; }
.card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.card-sku { font-size: 11px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .5px; }
.card-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-state { font-size: 12px; color: var(--text-muted); }
.card-note { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }

/* ── Days badge ── */
.days-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.days-green { background: #e8f5e9; color: var(--success); }
.days-amber { background: #fff8e1; color: #e65100; }
.days-red { background: #ffebee; color: var(--danger); }

/* ── Status badge ── */
.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: capitalize;
}
.status-active { background: #e8f0fe; color: var(--primary); }
.status-pending_approval { background: #fff8e1; color: #e65100; }
.status-approved { background: #e8f5e9; color: var(--success); }
.status-rejected { background: #ffebee; color: var(--danger); }

/* ── Sample Detail ── */
.detail-header { padding: 16px; background: var(--card); border-bottom: 1px solid var(--border); }
.detail-sku { font-size: 12px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .5px; }
.detail-name { font-size: 20px; font-weight: 700; margin: 4px 0 8px; }
.detail-brief { font-size: 14px; color: var(--text-muted); margin-top: 8px; line-height: 1.6; }

.timeline { padding: 12px; display: flex; flex-direction: column; gap: 16px; }
.event-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.event-header { display: flex; align-items: center; gap: 10px; }
.event-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}
.ev-created { background: #e8f0fe; color: var(--primary); }
.ev-ping_out { background: #fff3e0; color: #e65100; }
.ev-ping_return { background: #e8f5e9; color: var(--success); }
.ev-submit_approval { background: #f3e5f5; color: #7b1fa2; }
.ev-approved { background: #e8f5e9; color: var(--success); }
.ev-rejected { background: #ffebee; color: var(--danger); }

.event-meta { flex: 1; }
.event-type-label { font-size: 13px; font-weight: 700; }
.event-route { font-size: 12px; color: var(--text-muted); }
.event-time { font-size: 11px; color: var(--text-muted); }
.event-delta { font-size: 11px; color: var(--text-muted); font-style: italic; }
.event-notes { font-size: 13px; background: var(--bg); padding: 8px 10px; border-radius: 6px; line-height: 1.5; }
.event-reject { background: #ffebee; border-left: 3px solid var(--danger); padding: 8px 10px; border-radius: 0 6px 6px 0; font-size: 13px; color: var(--danger); }

/* Photo gallery */
.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.photo-strip img { width: 80px; height: 80px; border-radius: 6px; object-fit: cover; flex-shrink: 0; cursor: pointer; }

/* Voice playback */
.voice-player { display: flex; align-items: center; gap: 8px; }
.voice-player audio { flex: 1; height: 36px; }

/* ── Action bar (sticky bottom of detail) ── */
.action-bar {
  position: sticky;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 50;
}
.action-bar .btn { flex: 1; min-width: 130px; font-size: 13px; }

/* ── Admin tabs ── */
.admin-tabs {
  display: flex;
  overflow-x: auto;
  background: var(--primary);
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
.admin-tabs .atab {
  flex-shrink: 0;
  padding: 0 18px;
  height: 46px;
  display: flex;
  align-items: center;
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.admin-tabs .atab.active { color: #fff; border-bottom-color: #fff; }
.badge { display: inline-flex; align-items: center; justify-content: center; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; border-radius: 10px; min-width: 18px; padding: 1px 5px; margin-left: 5px; }

/* ── All Active table ── */
.all-active-list { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.active-row {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  gap: 12px;
  cursor: pointer;
}
.active-row .thumb { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: var(--bg); flex-shrink: 0; border: 1px solid var(--border); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.active-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.active-row-body { flex: 1; min-width: 0; }
.active-row-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.active-row-sku { font-size: 11px; font-weight: 700; color: var(--primary); }
.active-row-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.holders { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.holder-chip { font-size: 11px; font-weight: 600; background: #e8f0fe; color: var(--primary); padding: 2px 8px; border-radius: 12px; }

/* ── Search / filter bar ── */
.filter-bar { padding: 8px 12px; display: flex; gap: 8px; background: var(--card); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.filter-bar input { flex: 1; padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 14px; }
.filter-bar select { padding: 8px 10px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 14px; background: var(--card); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex; align-items: flex-end;
}
.modal-sheet {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-header h3 { flex: 1; font-size: 17px; font-weight: 700; }
.modal-header .btn-close { font-size: 22px; color: var(--text-muted); padding: 4px; min-width: 36px; min-height: 36px; display: flex; align-items: center; justify-content: center; }
.modal-body { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); }

/* ── Photo picker ── */
.photo-picker-area { display: flex; flex-direction: column; gap: 8px; }
.photo-pick-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  background: var(--bg);
}
.photo-pick-btn:hover { border-color: var(--primary); color: var(--primary); }
.photo-thumb-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-thumb-item { position: relative; width: 72px; height: 72px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb-item .rm-btn { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.6); color: #fff; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; display: flex; align-items: center; justify-content: center; cursor: pointer; }

/* ── Voice recorder ── */
.voice-recorder { background: var(--bg); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.recorder-controls { display: flex; align-items: center; gap: 10px; }
.rec-btn { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.rec-btn.idle { background: var(--danger); color: #fff; }
.rec-btn.recording { background: #ffebee; color: var(--danger); border: 2px solid var(--danger); animation: pulse 1s infinite; }
.rec-timer { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-muted); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* ── Reports ── */
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.report-stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.report-stat .stat-val { font-size: 32px; font-weight: 700; color: var(--primary); }
.report-stat .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-label { width: 90px; font-size: 12px; text-align: right; color: var(--text-muted); }
.bar-track { flex: 1; height: 20px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width .4s; min-width: 2px; }
.bar-val { font-size: 12px; font-weight: 700; width: 24px; }

/* ── Users table ── */
.users-list { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.user-row { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.user-name { flex: 1; font-weight: 600; }
.user-role { font-size: 12px; color: var(--text-muted); }
.user-inactive { opacity: 0.5; }

/* ── Forms ── */
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.form-field input, .form-field select, .form-field textarea {
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  background: var(--card);
  outline: none;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--primary); }
.form-field textarea { resize: vertical; min-height: 80px; }

/* ── Lightbox ── */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 300; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 95vw; max-height: 90vh; border-radius: 8px; }
.lightbox .close-lb { position: absolute; top: 16px; right: 16px; color: #fff; font-size: 28px; cursor: pointer; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #323232; color: #fff;
  padding: 10px 20px; border-radius: 24px;
  font-size: 14px; z-index: 500;
  pointer-events: none;
  animation: fadeInUp .2s ease;
}
@keyframes fadeInUp { from { opacity:0; transform: translate(-50%, 10px); } to { opacity:1; transform: translate(-50%, 0); } }

/* ── Spinner ── */
.spinner { display: flex; justify-content: center; padding: 32px; }
.spin { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Reference photo carousel ── */
.ref-carousel { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 8px; -webkit-overflow-scrolling: touch; }
.ref-carousel img { width: 120px; height: 120px; border-radius: 8px; object-fit: cover; flex-shrink: 0; cursor: pointer; border: 1px solid var(--border); }

/* ── Misc ── */
.divider { height: 1px; background: var(--border); margin: 8px 0; }
.text-danger { color: var(--danger); }
.mt-8 { margin-top: 8px; }
.p-16 { padding: 16px; }
