:root {
  --color-bg: #f0f7fc;
  --color-surface: #ffffff;
  --color-primary: #0369a1;
  --color-primary-dark: #0c4a6e;
  --color-accent: #b45309;
  --color-success: #15803d;
  --color-danger: #b91c1c;
  --color-warn: #b45309;
  --color-text: #0f172a;
  --color-muted: #64748b;
  --color-line: #dbe7f0;
  --font-display: "Sora", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(12, 74, 110, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--color-text);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #e0f2fe 0%, transparent 50%),
    var(--color-bg);
  min-height: 100vh;
}

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-line);
}
.brand {
  display: flex; align-items: center; gap: .75rem;
  text-decoration: none; color: inherit; min-width: 210px;
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #0284c7, #0c4a6e);
  color: #fff; font-size: 1.2rem;
}
.brand strong {
  display: block; font-family: var(--font-display); font-size: .95rem;
}
.brand small { color: var(--color-muted); font-size: .75rem; }
.topnav { display: flex; gap: .35rem; flex: 1; flex-wrap: wrap; }
.topnav a {
  text-decoration: none; color: var(--color-muted);
  padding: .45rem .85rem; border-radius: 999px; font-weight: 600; font-size: .9rem;
}
.topnav a.is-active, .topnav a:hover {
  background: #e0f2fe; color: var(--color-primary-dark);
}
.topbar-meta { display: flex; align-items: center; gap: .4rem; }
.user-chip {
  font-size: .85rem; color: var(--color-muted);
  background: #f8fafc; border: 1px solid var(--color-line);
  border-radius: 999px; padding: .35rem .7rem;
}
.btn-ghost {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; color: var(--color-muted); text-decoration: none;
  border: 1px solid transparent;
}
.btn-ghost:hover { background: #f1f5f9; color: var(--color-text); }
.btn-portal {
  white-space: nowrap;
  padding: .45rem .75rem !important;
  font-size: .85rem !important;
}
@media (max-width: 720px) {
  .btn-portal span, .btn-portal { font-size: .8rem !important; }
  .topbar-meta .user-chip { display: none; }
}

.page { width: min(1180px, calc(100% - 2rem)); margin: 1.25rem auto 3rem; }
.page-foot {
  text-align: center; color: #94a3b8; font-size: .8rem; padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
}

.hero {
  display: grid; gap: .35rem; margin-bottom: 1.25rem;
  animation: rise .45s ease both;
}
.hero h1 {
  margin: 0; font-family: var(--font-display); font-size: clamp(1.45rem, 2.4vw, 2rem);
  letter-spacing: -.02em;
}
.hero p { margin: 0; color: var(--color-muted); max-width: 60ch; }

.grid-cards {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem;
}
.action-card {
  background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: var(--radius); padding: 1.2rem; text-decoration: none;
  color: inherit; box-shadow: var(--shadow);
  transition: transform .2s ease, border-color .2s ease;
  animation: rise .5s ease both;
}
.action-card:nth-child(2) { animation-delay: .05s; }
.action-card:nth-child(3) { animation-delay: .1s; }
.action-card:hover { transform: translateY(-3px); border-color: #7dd3fc; }
.action-card .icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  background: #e0f2fe; color: var(--color-primary); font-size: 1.3rem; margin-bottom: .8rem;
}
.action-card h2 { margin: 0 0 .35rem; font-family: var(--font-display); font-size: 1.1rem; }
.action-card p { margin: 0; color: var(--color-muted); font-size: .92rem; }

.panel {
  background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
  margin-bottom: 1rem; animation: rise .4s ease both;
}
.panel h2, .panel h3 {
  margin: 0 0 .85rem; font-family: var(--font-display); font-size: 1.05rem;
}

.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .75rem; margin-bottom: 1rem;
}
.stat {
  background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: var(--radius); padding: .9rem 1rem;
}
.stat b { display: block; font-family: var(--font-display); font-size: 1.4rem; }
.stat span { color: var(--color-muted); font-size: .82rem; }

.form-row {
  display: grid; grid-template-columns: 1.2fr .7fr auto; gap: .6rem; align-items: end;
}
.form-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .6rem;
  align-items: end;
}
.tipo-tabs {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .25rem;
}
.tipo-tab {
  appearance: none;
  border: 1px solid var(--color-line);
  background: #fff;
  color: var(--color-muted);
  border-radius: 10px;
  padding: .7rem 1.1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.tipo-tab:hover { border-color: #7dd3fc; color: var(--color-primary-dark); }
.tipo-tab.is-active {
  background: #e0f2fe;
  border-color: #38bdf8;
  color: var(--color-primary-dark);
}
@media (max-width: 1100px) {
  .form-grid-5 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .form-grid-5 { grid-template-columns: 1fr; }
}
.field { display: grid; gap: .3rem; }
.field label { font-size: .8rem; font-weight: 600; color: var(--color-muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--color-line); border-radius: 8px;
  padding: .65rem .75rem; font: inherit; background: #fff;
}
.field textarea {
  font-family: ui-monospace, Consolas, monospace; font-size: .88rem; line-height: 1.45;
  resize: vertical; min-height: 140px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid #bae6fd; border-color: #38bdf8;
}

.btn {
  appearance: none; border: 0; border-radius: 8px; cursor: pointer;
  font: inherit; font-weight: 600; padding: .65rem 1rem;
  display: inline-flex; align-items: center; gap: .4rem; text-decoration: none;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-outline {
  background: #fff; color: var(--color-primary-dark);
  border: 1px solid #7dd3fc;
}
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-lg { padding: .9rem 1.2rem; font-size: 1.05rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.table-wrap { overflow: auto; border: 1px solid var(--color-line); border-radius: 8px; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td {
  padding: .7rem .75rem; border-bottom: 1px solid var(--color-line); text-align: left; vertical-align: middle;
}
table.data th {
  background: #f8fafc; color: var(--color-muted); font-size: .78rem;
  text-transform: uppercase; letter-spacing: .04em;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tr.is-done td { background: #f0fdf4; }
table.data tr.is-pending td { background: #fff; }

.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  border-radius: 999px; padding: .2rem .55rem; font-size: .75rem; font-weight: 700;
}
.badge-armado { background: #e2e8f0; color: #334155; }
.badge-lista { background: #e0f2fe; color: #075985; }
.badge-pt { background: #fef3c7; color: #92400e; }
.badge-despacho { background: #ffedd5; color: #9a3412; }
.badge-completa { background: #dcfce7; color: #166534; }
.badge-guia { background: #ede9fe; color: #5b21b6; }
.badge-pendiente { background: #fee2e2; color: #991b1b; }
.badge-warn { background: #ffedd5; color: #9a3412; }
.badge-ok { background: #dcfce7; color: #166534; }

.progress {
  height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden;
}
.progress > span {
  display: block; height: 100%; background: linear-gradient(90deg, #0284c7, #15803d);
  transition: width .35s ease;
}

.search-results {
  margin-top: .5rem; border: 1px solid var(--color-line); border-radius: 8px;
  max-height: 240px; overflow: auto; background: #fff;
}
.search-results button {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--color-line);
  background: transparent; padding: .7rem .8rem; cursor: pointer; font: inherit;
}
.search-results button:hover { background: #f0f9ff; }
.search-results button:last-child { border-bottom: 0; }
.search-results strong { display: block; }
.search-results small { color: var(--color-muted); }

/* Tablet modo pistola */
.tablet-shell { width: min(820px, 100%); margin: 0 auto; }
.scan-box {
  background: linear-gradient(160deg, #0c4a6e, #0369a1);
  color: #fff; border-radius: 16px; padding: 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.scan-box h2 { margin: 0 0 .35rem; font-family: var(--font-display); }
.scan-box p { margin: 0 0 .9rem; opacity: .9; }
.scan-input {
  width: 100%; font-size: 1.35rem; padding: 1rem 1.1rem; border-radius: 12px;
  border: 0; font-family: var(--font-body); font-weight: 600;
}
.scan-feedback {
  min-height: 1.4rem; margin-top: .75rem; font-weight: 600;
}
.scan-feedback.ok { color: #bbf7d0; }
.scan-feedback.err { color: #fecaca; }
.big-progress {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  margin-bottom: .5rem;
}
.big-progress b { font-family: var(--font-display); font-size: 1.6rem; }
.mueble-tap {
  display: flex; justify-content: space-between; gap: .75rem; align-items: center;
  width: 100%; text-align: left; border: 1px solid var(--color-line);
  background: #fff; border-radius: 10px; padding: .85rem 1rem; margin-bottom: .5rem;
  cursor: pointer; font: inherit;
}
.mueble-tap.is-done {
  background: #f0fdf4; border-color: #86efac; cursor: default;
}
.mueble-tap.is-locked {
  opacity: .55;
  cursor: not-allowed;
  background: #f8fafc;
}
.mueble-tap code {
  font-weight: 700; color: var(--color-primary-dark); font-size: .95rem;
}

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%); background: #fff; border: 1px solid var(--color-line);
  border-radius: 16px; padding: 1.5rem; box-shadow: var(--shadow);
}
.login-card h1 { font-family: var(--font-display); margin: 0 0 .25rem; font-size: 1.4rem; }
.login-card .hint { color: var(--color-muted); margin: 0 0 1rem; font-size: .9rem; }
.login-card .stack { display: grid; gap: .75rem; }
.alert {
  padding: .7rem .85rem; border-radius: 8px; margin-bottom: .85rem; font-size: .9rem;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-ok { background: #dcfce7; color: #166534; }
.alert-info { background: #e0f2fe; color: #075985; }

.print-only { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .grid-cards, .stats { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .brand { min-width: 0; }
  .topnav { order: 3; width: 100%; }
}

@media print {
  body { background: #fff; }
  .topbar, .page-foot, .no-print { display: none !important; }
  .page { width: 100%; margin: 0; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  .print-only { display: block; }
}
