/* ============ KeyHome — sistema visual ============ */
:root {
  --green: #1B8B6D;
  --green-700: #167559;
  --green-50: #E7F4EF;
  --dark: #14504A;
  --gold: #D4AF37;
  --gold-50: #FBF5E1;
  --orange: #FF7A45;
  --orange-50: #FFEEE6;
  --orange-ink: #B4461A;
  --bg: #F4F1EA;
  --ink: #2B2B2B;
  --muted: #6B6F6A;
  --line: #E6E1D6;
  --white: #FFFFFF;

  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 1px 2px rgba(20, 80, 74, .06), 0 6px 20px rgba(20, 80, 74, .07);
  --shadow-lg: 0 10px 40px rgba(20, 80, 74, .18);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: #E9E4D8;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
  box-shadow: 0 0 60px rgba(20, 80, 74, .12);
}
.screen { padding-bottom: calc(96px + var(--safe-bottom)); animation: fadeIn .25s ease; }
.screen.no-nav { padding-bottom: calc(24px + var(--safe-bottom)); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.pad { padding: 0 20px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

h1, h2, h3 { margin: 0; color: var(--dark); letter-spacing: -.02em; }
h1 { font-size: 28px; font-weight: 800; line-height: 1.15; }
h2 { font-size: 20px; font-weight: 800; }
h3 { font-size: 16px; font-weight: 700; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 20px 12px; }
.section-title a, .link { color: var(--green); font-weight: 700; font-size: 14px; }

/* ---------- Marca ---------- */
.wordmark { font-weight: 800; letter-spacing: -.03em; color: var(--dark); }
.wordmark span { color: var(--orange); }
.brand-tile {
  display: grid; place-items: center;
  background: var(--green); border-radius: 28%;
  color: var(--gold);
}
.brand-tile svg { width: 82%; height: auto; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; min-height: 64px;
  background: rgba(244, 241, 234, .9);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.topbar .title { font-size: 17px; font-weight: 700; color: var(--dark); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--white); color: var(--dark); box-shadow: var(--shadow);
}
.icon-btn svg { width: 20px; height: 20px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  background: var(--gold-50); color: var(--dark); font-weight: 800; font-size: 15px;
}

/* ---------- Hero ---------- */
.hero {
  margin: 4px 16px 0; padding: 22px 20px 20px;
  border-radius: 28px;
  background: radial-gradient(120% 140% at 100% 0%, #25A582 0%, var(--green) 45%, var(--dark) 100%);
  color: var(--white); position: relative; overflow: hidden;
}
.hero h1 { color: var(--white); font-size: 25px; max-width: 72%; position: relative; }
.hero p { margin: 8px 0 0; opacity: .88; font-size: 14px; max-width: 72%; position: relative; }
.hero .hero-key {
  position: absolute; right: -34px; top: 16px; width: 132px;
  color: var(--gold); pointer-events: none;
}
.search {
  margin-top: 18px; display: flex; align-items: center; gap: 10px;
  background: var(--white); color: var(--muted);
  border-radius: 16px; padding: 14px 16px; font-size: 15px; position: relative;
  width: 100%; text-align: left;
}
.search svg { width: 20px; height: 20px; color: var(--green); flex: none; }

/* ---------- Rubros ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 0 16px; }
.cat-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 14px;
  padding: 16px; border-radius: var(--radius);
  background: var(--white); box-shadow: var(--shadow); text-align: left;
  transition: transform .15s ease, box-shadow .15s ease;
}
.cat-card:active { transform: scale(.97); }
.cat-card .cat-name { font-weight: 700; color: var(--dark); font-size: 15px; line-height: 1.2; }
.cat-card .cat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cat-card.wide { grid-column: span 2; flex-direction: row; align-items: center; }
.cat-icon {
  width: 48px; height: 48px; border-radius: 16px; flex: none;
  display: grid; place-items: center;
}
.cat-icon svg { width: 24px; height: 24px; }
.cat-icon.sm { width: 40px; height: 40px; border-radius: 13px; }
.cat-icon.sm svg { width: 20px; height: 20px; }

/* ---------- Tarjetas ---------- */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.urgent-banner {
  margin: 16px 16px 0; padding: 16px; border-radius: var(--radius);
  background: var(--orange-50); display: flex; align-items: center; gap: 14px;
  border: 1px solid #FFD9C7; text-align: left; width: calc(100% - 32px);
}
.urgent-banner .ub-icon {
  width: 44px; height: 44px; border-radius: 14px; flex: none;
  display: grid; place-items: center; background: var(--orange); color: var(--white);
}
.urgent-banner .ub-icon svg { width: 22px; height: 22px; }
.urgent-banner b { color: var(--orange-ink); display: block; font-size: 15px; }
.urgent-banner span { color: #7A4A35; font-size: 13px; }

.trust { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0 16px; }
.trust div { background: var(--white); border-radius: 16px; padding: 14px 10px; text-align: center; box-shadow: var(--shadow); }
.trust svg { width: 22px; height: 22px; color: var(--green); }
.trust p { margin: 6px 0 0; font-size: 12px; font-weight: 600; color: var(--dark); line-height: 1.25; }

/* ---------- Pedidos ---------- */
.order-card { display: flex; gap: 14px; align-items: flex-start; width: 100%; text-align: left; }
.order-card .oc-body { flex: 1; min-width: 0; }
.order-card .oc-title { font-weight: 700; color: var(--dark); font-size: 15px; }
.order-card .oc-desc { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-card .oc-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.order-card .oc-meta span { display: inline-flex; align-items: center; gap: 4px; }
.order-card .oc-meta svg { width: 14px; height: 14px; }
.list { padding: 0 16px; }
.list > * + * { margin-top: 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.nuevo { background: var(--gold-50); color: #8A6D12; }
.pill.asignado { background: #E8F0FE; color: #2F5BB7; }
.pill.en_curso { background: var(--orange-50); color: var(--orange-ink); }
.pill.resuelto { background: var(--green-50); color: var(--green-700); }
.pill.cancelado { background: #EFEDE8; color: var(--muted); }
.tag-urgent {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: 8px; background: var(--orange); color: #3A1606;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
}

/* ---------- Chips / filtros ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 9px 14px; border-radius: 999px;
  background: var(--white); color: var(--dark); font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow);
}
.chip.active { background: var(--dark); color: var(--white); }
.chip .count { opacity: .6; margin-left: 4px; }

/* ---------- Métricas ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0 16px; }
.stat { background: var(--white); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; font-weight: 800; color: var(--dark); letter-spacing: -.03em; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat.hl { background: var(--dark); }
.stat.hl b { color: var(--gold); }
.stat.hl span { color: rgba(255,255,255,.75); }

/* ---------- Formularios ---------- */
.field { display: block; margin-top: 18px; }
.field > .label { display: block; font-weight: 700; color: var(--dark); font-size: 14px; margin-bottom: 8px; }
.field > .hint { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; }
.input, .select, .textarea {
  width: 100%; border: 1.5px solid var(--line); background: var(--white);
  border-radius: var(--radius-sm); padding: 14px 16px; font-size: 16px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(27, 139, 109, .14); }
.textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%2314504A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 44px; }
.input.invalid, .select.invalid, .textarea.invalid { border-color: #D9534F; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.seg {
  padding: 14px 12px; border-radius: var(--radius-sm);
  background: var(--white); border: 1.5px solid var(--line);
  text-align: left; transition: all .15s ease;
}
.seg b { display: block; color: var(--dark); font-size: 15px; }
.seg span { font-size: 12px; color: var(--muted); }
.seg.active { border-color: var(--green); background: var(--green-50); box-shadow: 0 0 0 3px rgba(27,139,109,.12); }
.seg.urgent.active { border-color: var(--orange); background: var(--orange-50); box-shadow: 0 0 0 3px rgba(255,122,69,.18); }
.seg.urgent.active b { color: var(--orange-ink); }
.seg.center { text-align: center; }

.selected-cat {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
}
.selected-cat .grow { flex: 1; }
.selected-cat b { color: var(--dark); display: block; }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 14px; font-size: 13px; line-height: 1.4;
  background: var(--gold-50); color: #6B5410; margin-top: 10px;
}
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 54px; padding: 0 22px; border-radius: 16px;
  font-weight: 800; font-size: 16px; letter-spacing: -.01em;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 20px; height: 20px; }
.btn.block { width: 100%; }
.btn-primary { background: var(--green); color: var(--white); box-shadow: 0 8px 20px rgba(27,139,109,.3); }
.btn-dark { background: var(--dark); color: var(--white); }
.btn-accent { background: var(--orange); color: #3A1606; box-shadow: 0 8px 20px rgba(255,122,69,.32); }
.btn-soft { background: var(--green-50); color: var(--green-700); }
.btn-ghost { background: var(--white); color: var(--dark); box-shadow: var(--shadow); }
.btn-wa { background: #25D366; color: #06331A; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.sm { min-height: 42px; padding: 0 16px; font-size: 14px; border-radius: 12px; }

.sticky-cta {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 30;
  width: 100%; max-width: 480px;
  padding: 14px 16px calc(14px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, rgba(244,241,234,0));
}

/* ---------- Navegación inferior ---------- */
.bottom-nav {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 30;
  width: 100%; max-width: 480px;
  display: flex; justify-content: space-around;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px; border-radius: 14px;
  font-size: 11px; font-weight: 700; color: #8C918B;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--green); }
.nav-item.active .nav-dot { background: var(--green-50); }
.nav-dot { padding: 4px 16px; border-radius: 999px; display: grid; place-items: center; transition: background .15s; }
.nav-item.fab .nav-dot { background: var(--orange); color: #3A1606; border-radius: 16px; padding: 8px 16px; margin-top: -4px; box-shadow: 0 6px 16px rgba(255,122,69,.4); }

/* ---------- Detalle ---------- */
.detail-head { padding: 4px 20px 0; }
.detail-head .row { align-items: flex-start; }
.kv { display: grid; grid-template-columns: 24px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; padding-bottom: 0; }
.kv:first-child { padding-top: 0; }
.kv svg { width: 20px; height: 20px; color: var(--green); margin-top: 2px; }
.kv small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.kv div > span { color: var(--dark); font-weight: 600; font-size: 15px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 34px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: 9px; top: 22px; bottom: -2px; width: 2px; background: var(--line);
}
.timeline li:last-child::before { display: none; }
.timeline .dot {
  position: absolute; left: 0; top: 0; width: 20px; height: 20px; border-radius: 50%;
  background: var(--white); border: 2px solid var(--line); display: grid; place-items: center;
}
.timeline .dot svg { width: 12px; height: 12px; color: var(--white); }
.timeline li.done .dot { background: var(--green); border-color: var(--green); }
.timeline li.done::before { background: var(--green); }
.timeline li.current .dot { border-color: var(--orange); box-shadow: 0 0 0 5px rgba(255,122,69,.18); }
.timeline b { display: block; color: var(--dark); font-size: 15px; }
.timeline li:not(.done):not(.current) b { color: #A3A7A1; }
.timeline span { font-size: 12px; color: var(--muted); }

.provider-card { display: flex; align-items: center; gap: 12px; }
.provider-card .grow { flex: 1; min-width: 0; }
.provider-card b { color: var(--dark); display: block; }
.rating { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; color: var(--muted); font-weight: 600; }
.rating svg { width: 14px; height: 14px; color: var(--gold); }
.badge-ok { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--green-700); }
.badge-ok svg { width: 14px; height: 14px; }

/* ---------- Bienvenida ---------- */
.welcome {
  min-height: 100dvh; display: flex; flex-direction: column;
  background: radial-gradient(130% 80% at 50% 0%, #25A582 0%, var(--green) 38%, var(--dark) 100%);
  color: var(--white); padding: 0 24px calc(28px + var(--safe-bottom));
}
.welcome .w-top { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding-top: 48px; }
.welcome .w-key { width: 220px; color: var(--gold); animation: floatKey 5s ease-in-out infinite; }
@keyframes floatKey { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.welcome .wordmark { font-size: 44px; color: var(--white); margin-top: 26px; }
.welcome .wordmark span { color: var(--orange); }
.welcome .tagline { font-size: 17px; opacity: .9; margin-top: 6px; font-weight: 500; }
.welcome .w-actions > * + * { margin-top: 10px; }
.role-btn {
  width: 100%; display: flex; align-items: center; gap: 14px;
  padding: 16px; border-radius: 20px; text-align: left;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); color: var(--white);
}
.role-btn.primary { background: var(--white); color: var(--dark); border-color: var(--white); }
.role-btn .ri { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none; background: rgba(255,255,255,.14); }
.role-btn.primary .ri { background: var(--green-50); color: var(--green); }
.role-btn .ri svg { width: 22px; height: 22px; }
.role-btn b { display: block; font-size: 16px; }
.role-btn span { font-size: 13px; opacity: .78; }
.role-btn .chev { margin-left: auto; width: 20px; height: 20px; opacity: .6; }
.demo-note { text-align: center; font-size: 12px; opacity: .6; margin-top: 16px; }

/* ---------- Éxito ---------- */
.success { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px; text-align: center; }
.success .s-badge {
  width: 132px; height: 132px; margin: 0 auto 24px; border-radius: 40px;
  background: var(--green); display: grid; place-items: center; color: var(--gold);
  box-shadow: 0 20px 50px rgba(27,139,109,.35); animation: pop .5s cubic-bezier(.2,1.4,.4,1);
}
.success .s-badge svg { width: 100px; }
.success .s-badge.warn { background: var(--orange-50); color: var(--orange-ink); box-shadow: none; }
.success .s-badge.warn svg { width: 56px; height: 56px; }
.avatar svg { width: 20px; height: 20px; }
.role-btn.loading { opacity: .6; pointer-events: none; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.success p { color: var(--muted); line-height: 1.5; max-width: 320px; margin: 10px auto 0; }
.success .code { display: inline-block; margin-top: 16px; padding: 8px 14px; border-radius: 12px; background: var(--white); font-weight: 800; color: var(--dark); letter-spacing: .06em; box-shadow: var(--shadow); }

/* ---------- Hoja inferior ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(20, 40, 36, .45); z-index: 50; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 51;
  width: 100%; max-width: 480px; max-height: 86dvh; overflow-y: auto;
  background: var(--bg); border-radius: 28px 28px 0 0;
  padding: 10px 16px calc(20px + var(--safe-bottom));
  animation: slideUp .28s cubic-bezier(.2,.9,.3,1);
}
@keyframes slideUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: #CFC9BB; margin: 0 auto 14px; }
.sheet h2 { margin: 0 4px 4px; }
.sheet .sub { margin: 0 4px 14px; color: var(--muted); font-size: 14px; }
.option {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 14px; border-radius: 18px; background: var(--white); box-shadow: var(--shadow);
  border: 2px solid transparent;
}
.option + .option { margin-top: 10px; }
.option.selected { border-color: var(--green); }
.option .grow { flex: 1; min-width: 0; }
.option b { color: var(--dark); display: block; }
.option .sm { font-size: 12px; color: var(--muted); }
.option.dim { opacity: .55; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 60; max-width: 420px; width: calc(100% - 40px);
  background: var(--dark); color: var(--white); padding: 14px 16px; border-radius: 16px;
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px; animation: fadeIn .2s ease;
}
.toast svg { width: 20px; height: 20px; color: var(--gold); flex: none; }

.empty { text-align: center; padding: 40px 24px; color: var(--muted); }
.empty .e-icon { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 24px; background: var(--white); display: grid; place-items: center; color: var(--green); box-shadow: var(--shadow); }
.empty .e-icon svg { width: 32px; height: 32px; }
.empty b { color: var(--dark); display: block; font-size: 16px; margin-bottom: 4px; }

@media (min-width: 520px) {
  body { padding: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
