:root {
  --primary: #0f766e;
  --primary-dark: #0d5f59;
  --primary-light: #14b8a6;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --bg: #f0fdfa;
  --card: #ffffff;
  --text: #134e4a;
  --text-muted: #5eead4;
  --border: #99f6e4;
  --shadow: 0 4px 12px rgba(15, 118, 110, 0.12);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: #f0fdfa;
  background-image:
    linear-gradient(rgba(240, 253, 250, 0.82), rgba(240, 253, 250, 0.82)),
    url('./bg-medical.jpg');
  background-size: auto, 420px auto;
  background-repeat: repeat;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ========== LOGIN ========== */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0f766e;
  background-image:
    linear-gradient(135deg, rgba(15,118,110,0.88) 0%, rgba(19,78,74,0.92) 100%),
    url('./bg-medical.jpg');
  background-size: auto, 380px auto;
  background-repeat: repeat;
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.login-card h1 {
  text-align: center;
  color: var(--primary);
  font-size: 1.8rem;
  margin-bottom: 6px;
}

.login-card .subtitle {
  text-align: center;
  color: #64748b;
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  font-size: 1rem;
  transition: border-color 0.2s;
  background: #f8fafc;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

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

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

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

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

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

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

.btn-sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
}

.error-msg {
  background: #fef2f2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  display: none;
}

/* ========== APP SHELL ========== */
#app {
  display: none;
  min-height: 100vh;
  padding-bottom: 80px;
}

.header {
  background: var(--primary);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.header .user-info {
  font-size: 0.8rem;
  opacity: 0.9;
}

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

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

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: #64748b;
  font-size: 0.7rem;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 10px;
  transition: all 0.2s;
}

.nav-item.active {
  color: var(--primary);
  background: #f0fdfa;
}

.nav-item .icon {
  font-size: 1.4rem;
}

/* ========== SCREENS ========== */
.screen {
  display: none;
  padding: 16px;
  animation: fadeIn 0.25s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== CARDS ========== */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid #e2e8f0;
}

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

.card-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-comprimidos { background: #dbeafe; color: #1d4ed8; }
.badge-capsulas { background: #fce7f3; color: #9d174d; }
.badge-ampollas { background: #fce7f3; color: #be185d; }
.badge-vial { background: #fce7f3; color: #9f1239; }
.badge-jarabe { background: #ccfbf1; color: #0f766e; }
.badge-crema { background: #fef3c7; color: #b45309; }
.badge-otico { background: #e0e7ff; color: #4338ca; }
.badge-oftalmologico { background: #e0f2fe; color: #0369a1; }
.badge-ovulos { background: #f3e8ff; color: #7e22ce; }
.badge-sobres { background: #e0e7ff; color: #3730a3; }
.badge-gotas { background: #e0f2fe; color: #0284c7; }
.badge-supositorios { background: #f3e8ff; color: #6b21a8; }
.badge-otros { background: #f1f5f9; color: #475569; }
.badge-stock { background: #d1fae5; color: #065f46; }
.badge-bajo { background: #fef3c7; color: #92400e; }
.badge-caducado { background: #fee2e2; color: #991b1b; }
.badge-proximo { background: #ffedd5; color: #9a3412; }

/* ========== DASHBOARD ========== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

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

.stat-card .number {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-card .label {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 4px;
}

.stat-card.alert .number { color: var(--danger); }
.stat-card.warning .number { color: var(--warning); }

/* ========== SEARCH ========== */
.search-box {
  position: relative;
  margin-bottom: 16px;
}

.search-box input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  font-size: 1rem;
  background: white;
}

.search-box .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: #94a3b8;
}

/* ========== MED LIST ========== */
.med-item {
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s;
}

.med-item:active {
  background: #f0fdfa;
}

.med-photo {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: #e2e8f0;
  flex-shrink: 0;
}

.med-photo.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #94a3b8;
}

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

.med-info .name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.med-info .principio {
  font-size: 0.85rem;
  color: #64748b;
}

.med-info .meta {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 2px;
}

/* ========== FORMS ========== */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 20px 0 12px;
  color: var(--text);
}

.section-title:first-child {
  margin-top: 0;
}

/* ========== SCANNER ========== */
#scanner-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto 16px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

#scanner-container video {
  width: 100% !important;
}

/* ========== PHOTO ========== */
.photo-preview {
  width: 100%;
  max-width: 200px;
  height: 150px;
  object-fit: cover;
  border-radius: 12px;
  margin: 10px 0;
  border: 2px dashed var(--border);
}

.photo-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ========== LOTES ========== */
.lote-item {
  background: #f8fafc;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  border-left: 4px solid var(--primary);
}

.lote-item.caducado {
  border-left-color: var(--danger);
  background: #fef2f2;
}

.lote-item.proximo {
  border-left-color: var(--warning);
  background: #fffbeb;
}

.lote-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
}

.lote-meta {
  font-size: 0.85rem;
  color: #64748b;
  margin-top: 4px;
}

/* ========== MOVIMIENTOS ========== */
.mov-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #e2e8f0;
}

.mov-item:last-child {
  border-bottom: none;
}

.mov-tipo {
  font-weight: 700;
  font-size: 0.9rem;
}

.mov-tipo.entrada { color: var(--success); }
.mov-tipo.salida { color: var(--danger); }

.mov-fecha {
  font-size: 0.8rem;
  color: #94a3b8;
}

/* ========== ALERTS LIST ========== */
.alert-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: white;
  border-radius: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 0;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: white;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.3rem;
}

.modal-close {
  background: #f1f5f9;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}

/* ========== EMPTY STATE ========== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #94a3b8;
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* ========== UTILITIES ========== */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.text-muted { color: #64748b; }
.text-sm { font-size: 0.85rem; }
.text-center { text-align: center; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* FAB */
.fab {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 1.8rem;
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.4);
  cursor: pointer;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab:active {
  transform: scale(0.95);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #134e4a;
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  opacity: 0;
  transition: all 0.3s;
  z-index: 300;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (min-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .modal {
    border-radius: 20px;
    margin-bottom: 40px;
  }
  .modal-overlay {
    align-items: center;
  }
}
