:root {
  --primary: #0056b3;
  --primary-dark: #004494;
  --secondary: #f0f2f5;
  --danger: #dc3545;
  --success: #28a745;
  --warning: #ffc107;
  --text: #333;
  --text-light: #666;
  --bg: #f5f6f8;
  --white: #ffffff;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  margin: 0;
  padding: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  padding-bottom: 90px;
}

/* Login */
.login-box {
  max-width: 360px;
  margin: 40px auto;
  background: var(--white);
  padding: 35px 25px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.logo {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 5px;
}

.logo-small {
  font-size: 16px;
  font-weight: 800;
  color: var(--primary);
  background: rgba(0,86,179,0.1);
  padding: 4px 10px;
  border-radius: 6px;
  margin-right: 8px;
}

.login-box h1 {
  font-size: 22px;
  margin: 0 0 6px;
  color: var(--text);
}

.subtitle {
  color: var(--text-light);
  font-size: 14px;
  margin: 0 0 28px;
}

input, textarea, button, select {
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  border-radius: 10px;
  border: 1px solid #ddd;
  font-size: 16px;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,86,179,0.1);
}

button {
  cursor: pointer;
  border: none;
  font-weight: 600;
  transition: background 0.15s, transform 0.05s;
}

button:active { transform: scale(0.98); }

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

.btn-primary:hover { background: var(--primary-dark); }

.btn-primary:disabled {
  background: #8ab4e0;
  cursor: not-allowed;
}

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

.btn-secondary:hover { background: #e2e6ea; }

.btn-icon {
  width: auto;
  padding: 8px 12px;
  background: rgba(255,255,255,0.15);
  color: white;
  border-radius: 8px;
  font-size: 18px;
  margin: 0;
}

.error { color: var(--danger); font-size: 14px; margin-top: -4px; }
.success { color: var(--success); font-size: 14px; }
.status {
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 12px;
  word-break: break-word;
}
.status.info { background: #e7f3ff; color: #004085; }
.status.success { background: #d4edda; color: #155724; }
.status.error { background: #f8d7da; color: #721c24; }
.status.warning { background: #fff3cd; color: #856404; }

.network-status {
  margin-top: 15px;
  font-size: 13px;
  color: var(--text-light);
}

/* Header */
header {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  min-height: 56px;
}

.header-title {
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 18px;
  padding-top: 4px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  padding-top: 4px;
}

/* Main content */
main {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.card-section {
  background: var(--white);
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-section h3 {
  margin: 0 0 14px;
  font-size: 16px;
  color: var(--text);
}

.card-section p {
  font-size: 14px;
  color: var(--text-light);
  line-height: 1.5;
  margin: 0;
}

/* Camera */
.camera-container {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

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

.camera-overlay {
  color: white;
  text-align: center;
  padding: 20px;
}

.camera-icon { font-size: 48px; margin-bottom: 10px; }

.btn-capture {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: white;
  color: #333;
  font-size: 32px;
  border: 4px solid rgba(255,255,255,0.5);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
}

#preview-image {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 8px;
  background: #f0f0f0;
  margin-bottom: 12px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.form-actions button { flex: 1; margin-bottom: 0; min-width: 120px; }

/* Cards Tab */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-mini {
  background: var(--white);
  padding: 14px 8px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
}

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.filter-btn {
  flex: 0 0 auto;
  padding: 10px 14px;
  background: var(--white);
  color: var(--text-light);
  font-size: 13px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 0;
}

.filter-btn.active {
  background: var(--primary);
  color: white;
}

.cards-list { display: flex; flex-direction: column; gap: 12px; }

.card-item {
  background: var(--white);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
}

.card-item .card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.card-item h4 {
  margin: 0 0 4px;
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}

.card-item .company {
  color: var(--primary);
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 8px;
}

.card-item p {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--text-light);
}

.card-item .meta {
  font-size: 12px;
  color: #999;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

.badge-pending { background: var(--warning); color: #333; }
.badge-synced { background: var(--success); color: white; }

.empty {
  text-align: center;
  color: #999;
  padding: 40px 20px;
  font-size: 14px;
}

/* Sync */
.sync-card {
  text-align: center;
}

.sync-header {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  margin-bottom: 14px;
}

.sync-icon { font-size: 40px; }

.sync-header h3 { margin: 0 0 4px; }

.sync-header p {
  margin: 0;
  font-size: 14px;
  color: var(--text-light);
}

.sync-progress {
  background: var(--secondary);
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-bar {
  background: var(--primary);
  height: 100%;
  width: 0%;
  transition: width 0.3s;
}

.sync-history { display: flex; flex-direction: column; gap: 10px; }

.sync-history-item {
  background: var(--secondary);
  padding: 12px;
  border-radius: 10px;
  font-size: 13px;
}

.btn-block { margin-top: 10px; margin-bottom: 0; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  background: transparent;
  color: var(--text-light);
  padding: 6px;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0;
}

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

.nav-btn.active { color: var(--primary); }

.nav-btn.active .nav-icon { transform: scale(1.1); }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

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

.network-status { font-size: 13px; margin-top: 10px; padding: 8px; border-radius: 6px; }
.network-status.online { background: #d4edda; color: #155724; }
.network-status.offline { background: #f8d7da; color: #721c24; }

.toast {
  position: fixed;
  bottom: calc(100px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 12px 20px;
  border-radius: 25px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; }

.camera-guide {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  pointer-events: none;
  z-index: 5;
}

.camera-guide .guide-frame {
  width: 86%;
  height: 56%;
  border: 2px dashed rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
}

.camera-guide .guide-text {
  margin-top: 14px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  background: rgba(0,0,0,0.4);
  padding: 6px 14px;
  border-radius: 20px;
}

.btn-small {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
  width: auto;
  margin: 0;
}

/* Password toggle */
.input-with-toggle {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.input-with-toggle input {
  margin-bottom: 0;
  padding-right: 48px;
}

.toggle-password {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
}

.toggle-password:active {
  background: #eee;
  transform: translateY(-50%) scale(0.95);
}

/* Cropper Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior: none;
  touch-action: none;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #111;
  color: white;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.crop-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 10px;
  position: relative;
  overscroll-behavior: none;
  touch-action: none;
}

.crop-wrapper img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: #111;
}

.modal-footer button {
  flex: 1;
  margin: 0;
}
