:root {
  --primary: #FF5C39;
  --primary-dark: #e04828;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1a1a1a;
  --sub: #666;
  --border: #e0e0e0;
  --danger: #e53935;
  --success: #43a047;
  --warning: #fb8c00;
}

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

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

/* SCREENS */
.screen { min-height: 100dvh; }

/* AUTH */
#s-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #fff5f3 0%, #fff 100%);
}
.auth-box {
  background: white;
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
.logo-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.logo-wrap h1 { font-size: 26px; font-weight: 800; color: var(--text); }
.logo-wrap h1 span { color: var(--primary); }

/* NAV */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-title { font-weight: 700; font-size: 17px; color: var(--primary); }
.nav-actions { display: flex; align-items: center; gap: 8px; }
.nav-user { font-size: 13px; color: var(--sub); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-btn { background: none; border: none; cursor: pointer; font-size: 18px; padding: 6px; min-width: 36px; min-height: 36px; touch-action: manipulation; }

/* TABS */
.tabs {
  display: flex;
  background: white;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
}
.tab {
  flex: 1;
  padding: 14px 8px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--sub);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  min-height: 48px;
  transition: color .2s;
}
.tab.active { color: var(--primary); border-bottom: 2px solid var(--primary); margin-bottom: -2px; }

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

/* HEADERS */
.tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.tab-header h2 { font-size: 20px; }

/* CARDS */
.list-container { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: white;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-info { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 13px; color: var(--sub); margin-top: 3px; }
.card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.card-actions button { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; touch-action: manipulation; min-height: 36px; }
.card-actions button:hover { border-color: var(--primary); color: var(--primary); }

/* BADGES */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-borrador { background: #f0f0f0; color: #666; }
.badge-enviada { background: #e3f2fd; color: #1565c0; }
.badge-pagada { background: #e8f5e9; color: #2e7d32; }
.badge-cancelada { background: #ffebee; color: #c62828; }
.badge-activo { background: #e8f5e9; color: #2e7d32; }
.badge-caducado { background: #ffebee; color: #c62828; }
.badge-inactivo { background: #f0f0f0; color: #666; }

/* CAMPOS */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--sub); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: white;
  -webkit-appearance: none;
  transition: border-color .2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* BOTONES */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 22px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0,0,0,0.08);
  transition: all .2s;
  width: 100%;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #f0f0f0; color: var(--text); }
.btn-secondary:active { background: #e0e0e0; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { width: auto; padding: 8px 16px; min-height: 36px; font-size: 14px; }

/* MENSAJES */
.msg-error { background: #ffebee; color: var(--danger); padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.switch-link { text-align: center; margin-top: 16px; font-size: 14px; color: var(--sub); }
.switch-link a { color: var(--primary); text-decoration: none; font-weight: 600; }
.sub { color: var(--sub); font-size: 14px; margin-bottom: 20px; }
h2 { font-size: 20px; margin-bottom: 6px; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-box {
  background: white;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--sub); min-width: 36px; min-height: 36px; touch-action: manipulation; }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-footer .btn { flex: 1; }

/* LINEAS FACTURA */
.linea-row {
  display: grid;
  grid-template-columns: 1fr 70px 90px 30px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.linea-row input { padding: 9px 10px; font-size: 14px; }
.linea-del { background: none; border: none; color: var(--danger); font-size: 18px; cursor: pointer; min-height: 36px; touch-action: manipulation; }

/* TOTALES */
.totales { background: #f9f9f9; border-radius: 12px; padding: 16px; margin: 16px 0; }
.total-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 15px; }
.total-final { font-weight: 800; font-size: 18px; border-top: 2px solid var(--border); margin-top: 8px; padding-top: 10px; color: var(--primary); }

/* VOZ */
.voz-container { padding: 24px 20px; max-width: 500px; margin: 0 auto; }
.voz-container h2 { margin-bottom: 6px; }
.mic-area { display: flex; flex-direction: column; align-items: center; gap: 16px; margin: 32px 0; }
.mic-btn {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0,0,0,0.08);
  box-shadow: 0 4px 20px rgba(255,92,57,0.4);
  transition: transform .15s, box-shadow .15s;
}
.mic-btn:active { transform: scale(0.95); }
.mic-btn.grabando {
  animation: pulse 1s infinite;
  background: #e53935;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,57,53,0.4); }
  50% { box-shadow: 0 0 0 16px rgba(229,57,53,0); }
}
.mic-status { font-size: 15px; color: var(--sub); font-weight: 500; }
.transcript-box {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 16px;
  min-height: 60px;
}
.voz-resultado { background: white; border-radius: 14px; padding: 16px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.voz-resultado h3 { margin-bottom: 12px; }
.voz-dato { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.voz-dato:last-child { border: none; }
.voz-dato span:first-child { color: var(--sub); font-weight: 600; }
.voz-resultado .btn { margin-top: 12px; }
.voz-tips { background: #f9f9f9; border-radius: 14px; padding: 16px; }
.voz-tips p { font-size: 13px; color: var(--sub); margin-bottom: 8px; line-height: 1.5; }
.voz-tips strong { color: var(--text); }

/* ADMIN */
.admin-container { padding: 16px; }
.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: 14px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.stat-card .stat-num { font-size: 28px; font-weight: 800; color: var(--primary); }
.stat-card .stat-label { font-size: 13px; color: var(--sub); margin-top: 4px; }

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

@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-box { border-radius: 20px; max-height: 85dvh; }
}
