/* ═══════════════════════════════════════════════════════════
 * Decaria · styles.css
 * PWA mobile-first · Tema oscuro · Botones 48px táctil
 * ═══════════════════════════════════════════════════════════ */

:root{
  /* Paleta */
  --bg:        #0F0F0F;
  --bg-2:      #1A1A1A;
  --bg-3:      #222222;
  --surface:   #1E1E1E;
  --surface-2: #262626;
  --border:    #2A2A2A;
  --border-2:  #353535;
  --text:      #F5F5F5;
  --text-2:    #B5B5B5;
  --text-3:    #8A8A8A;
  --text-4:    #5F5F5F;
  --gold:      #C9A84C;
  --gold-2:    #D8B65A;
  --gold-dark: #8B6914;
  --gold-soft: rgba(201,168,76,.15);
  --success:   #3FB778;
  --error:     #E04C4C;
  --warn:      #E0A24C;
  --info:      #4C90E0;

  /* Sistema */
  --radius:    12px;
  --radius-s:  8px;
  --radius-xs: 6px;
  --tap:       48px;
  --ease:      cubic-bezier(.2,.7,.2,1);
  --shadow:    0 8px 24px rgba(0,0,0,.4);
  --shadow-s:  0 4px 12px rgba(0,0,0,.25);
  --ff:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Layout */
  --topbar-h:  56px;
  --tabbar-h:  64px;
  --safe-t:    env(safe-area-inset-top);
  --safe-b:    env(safe-area-inset-bottom);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body{
  font-family: var(--ff);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  min-height: 100dvh;
}

button { font-family: inherit; }

/* ── Utilidades ──────────────────────────────────────────── */
.visually-hidden{
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.hidden { display: none !important; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar{
  position: fixed; top: var(--safe-t); left: 0; right: 0;
  height: var(--topbar-h); z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.brand-mark{
  font-weight: 700; letter-spacing: .08em;
  font-size: 1.05rem; color: var(--text);
}
.brand-mark span{ color: var(--gold); }
.brand-mark--xl{ font-size: 2rem; letter-spacing: .12em; }

.topbar-right{
  display: flex; align-items: center; gap: .8rem;
}
.icon-btn{
  width: 40px; height: 40px;
  background: transparent; border: none; color: var(--text);
  font-size: 1.4rem; cursor: pointer;
  border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  transition: background .2s var(--ease);
}
.icon-btn:hover{ background: var(--surface); }
.icon-btn:active{ transform: scale(.95); }

.status-dot{
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--success); box-shadow: 0 0 8px var(--success);
  transition: background .3s var(--ease), box-shadow .3s var(--ease);
}
.status-dot.offline{
  background: var(--error); box-shadow: 0 0 8px var(--error);
}

.badge-credits{
  font-size: .75rem; font-weight: 600;
  padding: .3rem .65rem;
  background: var(--gold-soft);
  color: var(--gold);
  border: 1px solid rgba(201,168,76,.3);
  border-radius: 999px;
  letter-spacing: .04em;
}

/* ── Side menu lateral ──────────────────────────────────── */
.side-menu{
  position: fixed; top: 0; right: -320px; bottom: 0;
  width: 300px; max-width: 85vw;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  z-index: 80;
  padding: calc(var(--safe-t) + 1.25rem) 1.25rem 1.25rem;
  display: flex; flex-direction: column;
  transition: right .3s var(--ease);
  box-shadow: -8px 0 24px rgba(0,0,0,.3);
}
.side-menu.is-open{ right: 0; }
.side-menu-header{
  display: flex; align-items: center; gap: .9rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.avatar{
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem;
  flex-shrink: 0;
}
.side-menu-name{
  font-weight: 600; color: var(--text); font-size: .95rem;
}
.side-menu-role{
  font-size: .72rem; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .14em;
  margin-top: .15rem;
}
.side-menu-nav{
  display: flex; flex-direction: column; gap: .25rem; flex: 1;
}
.side-link{
  display: block; width: 100%;
  padding: .85rem 1rem;
  font-size: .95rem; color: var(--text-2);
  text-decoration: none; text-align: left;
  background: transparent; border: none; cursor: pointer;
  border-radius: var(--radius-s);
  transition: background .2s var(--ease), color .2s var(--ease);
}
.side-link:hover{ background: var(--surface); color: var(--text); }
.side-link.is-active{ color: var(--gold); background: var(--gold-soft); }
.side-link--danger{ color: var(--error); margin-top: 1rem; }
.side-menu-foot{
  border-top: 1px solid var(--border); padding-top: 1rem;
  font-size: .7rem; color: var(--text-4); letter-spacing: .04em;
}
.overlay{
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
}

/* ── Contenedor de vistas ───────────────────────────────── */
.app{
  min-height: 100dvh;
  padding-top: calc(var(--topbar-h) + var(--safe-t) + 1rem);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 1rem);
}
.app.no-topbar{ padding-top: var(--safe-t); }
.app.no-tabbar{ padding-bottom: var(--safe-b); }

.view{
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.25rem;
  animation: viewIn .3s var(--ease);
}
@keyframes viewIn{
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.view-head{
  margin-bottom: 1.25rem;
}
.view-title{
  font-size: 1.6rem; font-weight: 700;
  color: var(--text); letter-spacing: -.01em;
  line-height: 1.2;
}
.view-subtitle{
  font-size: .9rem; color: var(--text-3);
  margin-top: .2rem;
}
.section-h{
  font-size: .75rem; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-3); margin: 1.5rem 0 .75rem;
}

/* ── Form / inputs ──────────────────────────────────────── */
.form{ display: flex; flex-direction: column; gap: 1rem; }
.field{ display: flex; flex-direction: column; gap: .5rem; }
.label{
  font-size: .75rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-3);
}
.input, .textarea{
  width: 100%; min-height: var(--tap);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: .85rem 1rem;
  font: inherit; font-size: 1rem;
  outline: none;
  transition: border-color .2s var(--ease), background .2s var(--ease);
  -webkit-appearance: none; appearance: none;
}
.input:focus, .textarea:focus{
  border-color: var(--gold);
  background: var(--surface-2);
}
.input::placeholder, .textarea::placeholder{ color: var(--text-4); }
.textarea{ resize: vertical; min-height: 100px; line-height: 1.55; }

/* ── Botones base ───────────────────────────────────────── */
.btn{
  min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  gap: .6rem; padding: .85rem 1.2rem;
  border-radius: var(--radius-s);
  border: 1px solid transparent;
  font-size: 1rem; font-weight: 600;
  cursor: pointer; user-select: none;
  -webkit-user-select: none; touch-action: manipulation;
  transition: transform .12s var(--ease), background .2s var(--ease),
              border-color .2s var(--ease), opacity .2s var(--ease);
}
.btn:active{ transform: scale(.98); }
.btn:disabled{ opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary{
  background: var(--gold); color: #111;
  font-weight: 700; letter-spacing: .04em;
  width: 100%;
  box-shadow: 0 6px 16px rgba(201,168,76,.18);
}
.btn-primary:hover:not(:disabled){ background: var(--gold-2); }
.btn-primary.is-sending{ background: var(--bg-3); color: var(--text-2); box-shadow: none; }
.btn-primary.is-success{ background: var(--success); color: #0A1F12; }
.btn-primary.is-error{ background: var(--error); color: #fff; }

.btn-ghost{
  background: transparent; color: var(--text-2);
  border-color: var(--border); width: 100%;
}
.btn-ghost:hover{ color: var(--text); border-color: var(--text-3); }

.btn-capture{
  background: var(--surface); color: var(--text);
  border-color: var(--border); width: 100%;
}
.btn-capture:hover{ border-color: var(--gold); }
.btn-capture .icon{ font-size: 1.25rem; }

/* ── Alertas ────────────────────────────────────────────── */
.alert{
  padding: .8rem 1rem; border-radius: var(--radius-s);
  font-size: .9rem; border: 1px solid;
  animation: fadeIn .25s var(--ease);
}
.alert.is-error{   background: rgba(224,76,76,.08);  border-color: var(--error);   color: #FFB3B3; }
.alert.is-success{ background: rgba(63,183,120,.08); border-color: var(--success); color: #A8E6C2; }
.alert.is-warn{    background: rgba(224,162,76,.08); border-color: var(--warn);    color: #F0CE9A; }
.alert.is-info{    background: rgba(76,144,224,.08); border-color: var(--info);    color: #B3D1FF; }
@keyframes fadeIn{ from{opacity:0;transform:translateY(-4px)} to{opacity:1;transform:translateY(0)} }

/* ── Spinner ────────────────────────────────────────────── */
.spinner{
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25); border-top-color: var(--text);
  animation: spin .8s linear infinite; flex-shrink: 0;
}
@keyframes spin{ to{ transform: rotate(360deg) } }

/* ── Vista Login ────────────────────────────────────────── */
.view-login{
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding-top: 1rem;
}
.login-wrap{
  width: 100%; max-width: 380px;
  padding: 2rem 0;
}
.login-brand{
  text-align: center; margin-bottom: 2.5rem;
}
.login-claim{
  font-family: 'EB Garamond', Georgia, serif;
  font-style: italic; font-size: 1.05rem;
  color: var(--text-3); margin-top: 1rem;
  line-height: 1.5;
}
.login-hint{
  text-align: center; font-size: .8rem;
  color: var(--text-4); margin-top: .5rem;
}

/* ── Filtros / chips ────────────────────────────────────── */
.view-filters{
  display: flex; gap: .5rem; flex-wrap: wrap;
  margin-top: .8rem;
}
.chip{
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border);
  padding: .4rem .9rem; font-size: .8rem; font-weight: 500;
  border-radius: 999px; cursor: pointer;
  transition: all .2s var(--ease);
}
.chip:hover{ color: var(--text); border-color: var(--text-3); }
.chip.is-active{
  background: var(--gold-soft); color: var(--gold);
  border-color: var(--gold);
}

/* ── Lista de peritajes ────────────────────────────────── */
.inspections-list{ list-style: none; display: flex; flex-direction: column; gap: .65rem; }
.insp-card{
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
  display: grid; grid-template-columns: 1fr auto; gap: .75rem;
  cursor: pointer;
  transition: background .2s var(--ease), border-color .2s var(--ease), transform .12s var(--ease);
}
.insp-card:hover{ background: var(--surface-2); border-color: var(--border-2); }
.insp-card:active{ transform: scale(.99); }
.insp-card-plate{
  font-weight: 700; font-size: 1.05rem; letter-spacing: .05em;
  color: var(--text);
}
.insp-card-vehicle{ font-size: .85rem; color: var(--text-3); margin-top: .1rem; }
.insp-card-meta{
  font-size: .72rem; color: var(--text-4);
  margin-top: .35rem; letter-spacing: .04em;
  display: flex; gap: .8rem;
}
.insp-card-right{ display: flex; flex-direction: column; align-items: flex-end; gap: .35rem; }
.insp-card-progress{
  font-size: .72rem; color: var(--text-3); font-weight: 600;
}

/* ── Status pill ──────────────────────────────────────── */
.status-pill{
  display: inline-block;
  font-size: .65rem; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  padding: .25rem .65rem; border-radius: 999px;
  border: 1px solid;
}
.status-pill.s-draft       { color: var(--text-3); border-color: var(--border-2); }
.status-pill.s-assigned    { color: var(--info);   border-color: var(--info);   background: rgba(76,144,224,.08); }
.status-pill.s-in_progress { color: var(--gold);   border-color: var(--gold);   background: var(--gold-soft); }
.status-pill.s-completed   { color: var(--success); border-color: var(--success); background: rgba(63,183,120,.08); }
.status-pill.s-signed      { color: var(--success); border-color: var(--success); background: rgba(63,183,120,.15); }
.status-pill.s-archived    { color: var(--text-4); border-color: var(--border-2); }
.status-pill.s-rejected    { color: var(--error);  border-color: var(--error);  background: rgba(224,76,76,.08); }

/* ── Progress bar ─────────────────────────────────────── */
.progress{
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: .9rem 1rem;
}
.progress-meta{
  display: flex; justify-content: space-between;
  font-size: .8rem; color: var(--text-3);
  margin-bottom: .5rem;
}
.progress-meta strong{ color: var(--text); font-size: 1rem; }
.progress-track{
  height: 6px; background: var(--bg-3);
  border-radius: 3px; overflow: hidden;
}
.progress-fill{
  height: 100%; background: linear-gradient(90deg, var(--gold-dark), var(--gold));
  border-radius: 3px;
  transition: width .4s var(--ease);
}

/* ── Grid de 33 zonas ─────────────────────────────────── */
.zone-grid{
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .5rem;
  margin-bottom: 1.5rem;
}
.zone-cell{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  aspect-ratio: 1 / 1.1;
  padding: .5rem;
  display: flex; flex-direction: column; justify-content: space-between;
  cursor: pointer;
  transition: all .2s var(--ease);
  position: relative;
  overflow: hidden;
}
.zone-cell:hover{ border-color: var(--border-2); }
.zone-cell:active{ transform: scale(.96); }
.zone-cell-num{
  font-size: .65rem; font-weight: 700;
  color: var(--text-4); letter-spacing: .04em;
}
.zone-cell-name{
  font-size: .68rem; line-height: 1.2;
  color: var(--text-2); font-weight: 500;
}
.zone-cell-thumb{
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  opacity: .55; z-index: 0;
  border-radius: inherit;
}
.zone-cell.has-thumb .zone-cell-num,
.zone-cell.has-thumb .zone-cell-name{
  position: relative; z-index: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
  color: var(--text);
}
.zone-cell.s-captured{ border-color: var(--success); }
.zone-cell.s-flagged{
  border-color: var(--warn);
  background: rgba(224,162,76,.06);
}
.zone-cell.s-approved{ border-color: var(--success); background: rgba(63,183,120,.06); }
.zone-cell.s-rejected{ border-color: var(--error); background: rgba(224,76,76,.06); }

.zone-cell-badge{
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  z-index: 2;
}
.zone-cell.s-captured .zone-cell-badge{ background: var(--success); }
.zone-cell.s-flagged  .zone-cell-badge{ background: var(--warn); }
.zone-cell.s-rejected .zone-cell-badge{ background: var(--error); }

.inspection-actions{
  display: flex; gap: .75rem;
  margin-top: 1rem;
}
.inspection-actions .btn{ flex: 1; }

/* ── Captura por zona ─────────────────────────────────── */
.capture-area{
  display: flex; flex-direction: column; gap: 1rem;
}
.zone-preview{
  width: 100%; aspect-ratio: 4 / 3;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
}
.zone-preview img{
  width: 100%; height: 100%; object-fit: cover;
}
.zone-preview .placeholder{
  color: var(--text-4); font-size: .9rem;
}
.severity-row{
  display: grid; grid-template-columns: repeat(6, 1fr);
  gap: .4rem;
}
.severity-btn{
  height: var(--tap);
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  font-weight: 700; font-size: .95rem;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.severity-btn:hover{ border-color: var(--text-3); color: var(--text); }
.severity-btn.is-active{
  background: var(--gold); color: #111;
  border-color: var(--gold);
}
.severity-hint{
  font-size: .7rem; color: var(--text-4);
  margin-top: .35rem; letter-spacing: .03em;
}

.checkbox{
  display: flex; align-items: center; gap: .65rem;
  font-size: .9rem; color: var(--text-2);
  cursor: pointer; padding: .25rem 0;
}
.checkbox input{
  width: 20px; height: 20px;
  accent-color: var(--gold);
  cursor: pointer;
}

.capture-actions{
  display: flex; gap: .75rem; margin-top: .5rem;
}
.capture-actions .btn{ flex: 1; }

/* ── Mensajes / chat ─────────────────────────────────── */
.messages-list{
  display: flex; flex-direction: column; gap: .5rem;
  padding-bottom: 1rem;
}
.msg-bubble{
  max-width: 78%;
  padding: .7rem .95rem;
  border-radius: 14px;
  font-size: .92rem; line-height: 1.45;
  word-wrap: break-word;
}
.msg-bubble.is-mine{
  align-self: flex-end;
  background: var(--gold-soft);
  color: var(--text);
  border: 1px solid rgba(201,168,76,.3);
  border-bottom-right-radius: 4px;
}
.msg-bubble.is-theirs{
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-bubble.is-system{
  align-self: center; max-width: 90%;
  background: transparent;
  color: var(--text-4);
  border: 1px dashed var(--border-2);
  font-size: .8rem; text-align: center;
}
.msg-meta{
  font-size: .65rem; color: var(--text-4);
  margin-top: .25rem; letter-spacing: .04em;
}
.msg-bubble.is-mine .msg-meta{ text-align: right; }

.message-form{
  position: sticky;
  bottom: calc(var(--tabbar-h) + var(--safe-b));
  background: var(--bg);
  padding: .75rem 0;
  display: grid; grid-template-columns: 1fr auto;
  gap: .5rem;
}
.message-input{ min-height: var(--tap); margin: 0; }
.btn-send{
  width: var(--tap); height: var(--tap);
  background: var(--gold); color: #111;
  border: none; border-radius: var(--radius-s);
  font-size: 1.3rem; font-weight: 700; cursor: pointer;
  transition: background .2s var(--ease);
}
.btn-send:hover{ background: var(--gold-2); }
.btn-send:active{ transform: scale(.96); }

/* ── Créditos ──────────────────────────────────────────── */
.credits-balance{
  background: linear-gradient(135deg, var(--bg-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.8rem 1.25rem;
  text-align: center;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-s);
}
.credits-amount{
  display: block;
  font-size: 3.4rem; font-weight: 700;
  color: var(--gold); line-height: 1;
  letter-spacing: -.02em;
}
.credits-label{
  font-size: .8rem; color: var(--text-3);
  letter-spacing: .1em; text-transform: uppercase;
  margin-top: .5rem; display: block;
}
.credits-history{ list-style: none; display: flex; flex-direction: column; gap: .4rem; }
.credit-row{
  display: flex; justify-content: space-between; align-items: center;
  padding: .8rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
}
.credit-reason{ font-size: .85rem; color: var(--text-2); }
.credit-date{ font-size: .7rem; color: var(--text-4); margin-top: .15rem; }
.credit-delta{
  font-weight: 700; font-size: .95rem;
}
.credit-delta.is-positive{ color: var(--success); }
.credit-delta.is-negative{ color: var(--error); }

/* ── FAB ──────────────────────────────────────────────── */
.fab{
  position: fixed;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 1rem);
  right: 1rem; z-index: 40;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--gold); color: #111;
  border: none; cursor: pointer;
  font-size: 1.8rem; font-weight: 600; line-height: 1;
  box-shadow: 0 8px 20px rgba(201,168,76,.35);
  transition: transform .15s var(--ease), background .2s var(--ease);
}
.fab:hover{ background: var(--gold-2); }
.fab:active{ transform: scale(.94); }

/* ── Tab bar inferior ─────────────────────────────────── */
.tab-bar{
  position: fixed; left: 0; right: 0;
  bottom: 0; z-index: 50;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(3, 1fr);
}
.tab-item{
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .2rem;
  color: var(--text-3); text-decoration: none;
  font-size: .68rem; font-weight: 500;
  letter-spacing: .03em;
  position: relative;
  transition: color .2s var(--ease);
}
.tab-item:hover{ color: var(--text-2); }
.tab-item.is-active{ color: var(--gold); }
.tab-icon{ font-size: 1.2rem; }
.tab-badge{
  position: absolute; top: 8px; right: 30%;
  min-width: 18px; height: 18px;
  background: var(--error); color: #fff;
  border-radius: 9px;
  font-size: .68rem; font-weight: 700;
  padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
}

/* ── Empty state ──────────────────────────────────────── */
.empty-state{
  padding: 3rem 1rem; text-align: center;
  color: var(--text-4); font-size: .9rem;
}

/* ── Responsive desktop ──────────────────────────────── */
@media (min-width: 720px){
  .view{ padding-top: 1rem; }
  .zone-grid{ grid-template-columns: repeat(7, 1fr); }
}

/* ── Reduced motion ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
