/* ════════════════════════════════════════════════════════════════
   Petri Movers PWA · Mobile-first · iPhone Safari + Android Chrome
   ──────────────────────────────────────────────────────────────────
   Paleta: obsidiana + ascua (Petri OS brand)
   Safe-area: env(safe-area-inset-*) para iPhone X+ y Android con muesca
   ════════════════════════════════════════════════════════════════ */

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

:root {
  --bg:        #0F1219;
  --bg-card:   #1A1F2E;
  --bg-input:  #232938;
  --text:      #F1F5F9;
  --text-dim:  #94A3B8;
  --text-faint:#64748B;
  --accent:    #6366F1;    /* índigo Petri */
  --accent-hi: #818CF8;
  --success:   #10B981;
  --warn:      #F59E0B;
  --danger:    #EF4444;
  --border:    rgba(255,255,255,.08);
  --shadow:    0 4px 16px rgba(0,0,0,.4);

  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* iOS Safari status bar translucent: extiende fondo arriba */
body { padding-top: var(--safe-top); }

/* ── Screens ──────────────────────────────────────────────────── */
.screen {
  display: none;
  min-height: calc(100vh - var(--safe-top));
  min-height: calc(100dvh - var(--safe-top));
  flex-direction: column;
}
.screen.is-active { display: flex; }

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-left:  calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hi));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
  flex-shrink: 0;
}
.topbar-info { min-width: 0; }
.topbar-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.topbar-sub { font-size: 12px; color: var(--text-dim); line-height: 1.2; }
.topbar-title { font-weight: 600; font-size: 17px; }
.iconbtn {
  background: rgba(255,255,255,.06);
  border: none;
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s;
}
.iconbtn:active { background: rgba(255,255,255,.12); }

/* ── Main content ──────────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 20px 16px;
  padding-left:  calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  padding-bottom: calc(20px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.main-center {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 0 0 12px;
}

/* ── Login ─────────────────────────────────────────────────────── */
.screen-login {
  background: linear-gradient(180deg, var(--bg) 0%, #161B26 100%);
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  padding-top:    calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
  padding-left:   calc(16px + var(--safe-left));
  padding-right:  calc(16px + var(--safe-right));
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center;
  margin-bottom: 24px;
}
.login-logo img {
  width: 72px; height: 72px;
  border-radius: 18px;
  box-shadow: 0 8px 24px rgba(99,102,241,.35);
}
.login-logo h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 12px 0 4px;
  letter-spacing: -.01em;
}
.login-tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}
.login-foot {
  margin-top: 20px;
  text-align: center;
}
.login-foot .small {
  font-size: 12px;
  color: var(--text-faint);
  margin: 4px 0;
}

/* ── Form fields ───────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
}
.input {
  width: 100%;
  padding: 14px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;        /* >=16px evita zoom auto en iOS Safari */
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s, background .15s;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  background: #2A3145;
}
.input::placeholder { color: var(--text-faint); }
.textarea {
  resize: vertical;
  min-height: 80px;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform .1s, background .15s, opacity .15s;
  text-decoration: none;
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99,102,241,.35);
}
.btn-primary:active { background: var(--accent-hi); }
.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}
.btn-full { width: 100%; margin-top: 12px; }
.btn-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Action grid (home dashboard) ──────────────────────────────── */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.action-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 14px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  transition: transform .1s, border-color .15s;
  font-family: inherit;
}
.action-card:active { transform: scale(0.98); }
.action-card:disabled { opacity: .45; cursor: not-allowed; }
.action-card.action-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hi) 100%);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(99,102,241,.3);
}
.action-icon {
  font-size: 28px;
  margin-bottom: 8px;
  line-height: 1;
}
.action-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  margin-bottom: 2px;
}
.action-sub {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.3;
}
.action-primary .action-sub { color: rgba(255,255,255,.8); }

/* ── Hint card ─────────────────────────────────────────────────── */
.hint-card {
  margin-top: 24px;
  padding: 14px 16px;
  background: rgba(99,102,241,.08);
  border: 1px solid rgba(99,102,241,.18);
  border-radius: 12px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Éxito box (post-crear inventario) ─────────────────────────── */
.exito-box {
  text-align: center;
  max-width: 400px;
  margin: 0 auto;
}
.exito-icon { font-size: 56px; line-height: 1; margin-bottom: 12px; }
.exito-box h2 { font-size: 22px; margin: 0 0 8px; }
.lead { color: var(--text-dim); font-size: 15px; margin: 0 0 20px; }
.link-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  word-break: break-all;
  text-align: left;
}
.link-box code {
  font-size: 13px;
  color: var(--accent-hi);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.exito-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 999;
  max-width: calc(100vw - 32px);
}
.toast.toast-success { border-color: rgba(16,185,129,.4); }
.toast.toast-error { border-color: rgba(239,68,68,.4); }

/* ── Mensajes y links ──────────────────────────────────────────── */
.error-msg {
  color: var(--danger);
  font-size: 14px;
  text-align: center;
  margin: 8px 0 0;
}
.hint {
  color: var(--text-dim);
  font-size: 13px;
  margin: 12px 0;
}
.link { color: var(--accent-hi); text-decoration: none; }
.link:active { text-decoration: underline; }

/* ── Responsive: tabletas y up ─────────────────────────────────── */
@media (min-width: 600px) {
  .action-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .main { padding: 32px 24px; }
}
