*,*::before,*::after{box-sizing:border-box}
html,body{margin:0;height:100%;font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif}
html{width:100%;overflow-x:hidden;touch-action:manipulation;-webkit-text-size-adjust:100%}
body{background:var(--bg);color:var(--text);overflow-x:hidden;overflow-y:auto;max-width:100vw;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
input,textarea{-webkit-user-select:text;user-select:text;font-size:16px}

:root{
  --bg:#111213;
  --panel:#1a1b1d;
  --panel2:#232427;
  --text:#f2f3f5;
  --muted:#b4b7bf;
  --line:#2c2d31;
  --chip:#1f8f56;
  --accent:#0b57d0;
  --shadow:0 4px 16px rgba(0,0,0,.25)
}
body.light{
  --bg:#f5f7fb;
  --panel:#ffffff;
  --panel2:#eef2f7;
  --text:#101114;
  --muted:#5f6572;
  --line:#dde3ec;
  --chip:#dff7ea;
  --accent:#0b57d0;
  --shadow:0 4px 16px rgba(18,22,34,.10)
}

.app{
  min-height:100dvh;
  min-height:100vh;
  max-width:480px;
  width:100%;
  margin:0 auto;
  position:relative;
  background:var(--bg);
  padding:calc(12px + env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) calc(80px + env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
  display:flex;
  flex-direction:column;
  gap:10px;
  overflow-x:hidden
}

.topbar{
  display:grid;
  grid-template-columns:44px 1fr max-content;
  gap:8px;
  align-items:center
}
.icon-btn{
  width:40px;
  height:40px;
  border:0;
  border-radius:12px;
  background:transparent;
  display:grid;
  place-items:center;
  color:var(--text)
}
.icon-btn span{
  display:block;
  width:18px;
  height:2px;
  background:var(--text);
  margin:2px 0;
  border-radius:2px
}
.icon-btn.small{
  width:32px;
  height:32px;
  border-radius:8px
}

.searchbar{
  height:46px;
  border-radius:23px;
  background:var(--panel2);
  display:flex;
  align-items:center;
  padding:0 14px;
  gap:10px;
  box-shadow:var(--shadow)
}
.search-ico{
  width:18px;
  height:18px;
  fill:var(--muted);
  flex:0 0 auto
}
.searchbar input{
  flex:1;
  border:0;
  outline:none;
  background:transparent;
  color:var(--text);
  font-size:16px
}
.searchbar input::placeholder{color:var(--muted)}

.avatar{
  border:0;
  background:transparent;
  width:40px;
  height:40px;
  border-radius:50%;
  position:relative;
  padding:0
}
.avatar img{
  width:36px;
  height:36px;
  border-radius:50%;
  border:2px solid transparent;
  position:relative;
  z-index:2
}
.avatar-ring{
  position:absolute;
  inset:0;
  border-radius:50%;
  background:conic-gradient(#ea4335,#fbbc05,#34a853,#4285f4,#ea4335)
}

.section-title{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:2px 2px 0
}
.section-title h1{
  margin:0;
  font-size:15px;
  font-weight:600;
  letter-spacing:.1px
}
.chip{
  border:0;
  border-radius:999px;
  padding:6px 12px;
  background:var(--panel2);
  color:var(--muted);
  font-size:13px
}

.categories{
  display:flex;
  flex-direction:column;
  gap:6px
}
.category-card{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius:14px;
  background:transparent
}
.category-card.featured{
  background:linear-gradient(180deg,rgba(255,255,255,.02),rgba(255,255,255,0))
}
.cat-icon{
  width:38px;
  height:38px;
  border-radius:12px;
  display:grid;
  place-items:center;
  font-size:18px;
  color:#6ad39a;
  background:#163b2a
}
.cat-body{
  flex:1;
  min-width:0
}
.cat-title{
  font-size:15px;
  font-weight:700;
  line-height:1.1
}
.cat-subtitle{
  font-size:12px;
  color:var(--muted);
  margin-top:2px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis
}
.pill{
  background:#63d98e;
  color:#082414;
  padding:5px 12px;
  border-radius:999px;
  font-size:13px;
  white-space:nowrap;
  border:0
}

/* ========================
   LISTA DE RESULTADOS
   ======================== */
.list{
  overflow:auto;
  display:flex;
  flex-direction:column;
  gap:0;
  padding-top:2px;
  padding-bottom:8px
}
.item{
  display:grid;
  grid-template-columns:44px 1fr 52px;
  gap:10px;
  align-items:center;
  padding:10px 4px;
  border-bottom:1px solid color-mix(in srgb,var(--line) 60%, transparent)
}
.item:last-child{border-bottom:0}

.logo{
  width:44px;
  height:44px;
  border-radius:50%;
  background:var(--panel2);
  display:grid;
  place-items:center;
  overflow:hidden;
  flex-shrink:0
}
.logo span{
  font-size:14px;
  font-weight:700;
  color:#fff;
  letter-spacing:.5px
}
.logo img{
  width:100%;
  height:100%;
  object-fit:cover
}

.meta{
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:1px
}

/* 1ª línea: número de cédula */
.sender{
  font-size:15px;
  line-height:1.2;
  font-weight:700;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  display:flex;
  align-items:center;
  gap:4px
}

/* 2ª línea: destinatario */
.subject{
  font-size:13px;
  line-height:1.2;
  font-weight:600;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  color:var(--text)
}

/* 3ª línea: dirección */
.preview{
  font-size:12px;
  line-height:1.2;
  color:var(--muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis
}

.right{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:8px
}
.date{
  font-size:11px;
  color:var(--muted);
  font-weight:500;
  white-space:nowrap
}
.star{
  font-size:18px;
  line-height:1;
  color:var(--muted)
}

/* BADGES */
.badge{
  display:inline-block;
  padding:1px 6px;
  border-radius:999px;
  font-size:10px;
  font-weight:600;
  flex-shrink:0
}
.badge-urgente{
  background:#ff4b4b;
  color:#fff
}
.badge-habilitacion{
  background:#ffb347;
  color:#111
}

.fab-menu{
  position:fixed;
  right:16px;
  bottom:82px;
  z-index:20;
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:10px
}
.fab-actions{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:8px;
  opacity:0;
  pointer-events:none;
  transform:translateY(10px) scale(.98);
  transform-origin:bottom right;
  transition:opacity .18s ease, transform .18s ease
}
.fab-menu.open .fab-actions{
  opacity:1;
  pointer-events:auto;
  transform:translateY(0) scale(1)
}
.fab-action{
  min-height:42px;
  border:1px solid color-mix(in srgb,var(--line) 78%, transparent);
  background:var(--panel);
  color:var(--text);
  border-radius:16px;
  padding:8px 12px 8px 10px;
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap:8px;
  font-size:14px;
  font-weight:600;
  box-shadow:var(--shadow);
  white-space:nowrap
}
.fab-action-ico{
  width:26px;
  height:26px;
  border-radius:50%;
  display:grid;
  place-items:center;
  background:var(--panel2);
  font-size:14px;
  flex:0 0 auto
}
.fab{
  border:0;
  background:var(--accent);
  color:#fff;
  min-height:50px;
  padding:0 16px 0 14px;
  border-radius:18px;
  font-size:15px;
  font-weight:700;
  box-shadow:var(--shadow);
  display:flex;
  align-items:center;
  gap:6px
}
.fab-plus{
  display:inline-grid;
  place-items:center;
  width:22px;
  height:22px;
  font-size:20px;
  line-height:1;
  transition:transform .18s ease
}
.fab-menu.open .fab-plus{
  transform:rotate(45deg)
}

.bottom-nav{
  position:fixed;
  left:0;
  right:0;
  bottom:0;
  height:68px;
  background:rgba(24,25,28,.96);
  backdrop-filter:blur(18px);
  display:grid;
  grid-template-columns:1fr 1fr 1fr;
  align-items:center;
  border-top:1px solid var(--line)
}
body.light .bottom-nav{
  background:rgba(255,255,255,.92)
}
.nav-item{
  height:100%;
  border:0;
  background:transparent;
  color:var(--muted);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:3px;
  font-size:11px
}
.nav-item.active{color:var(--accent)}
.nav-ico{font-size:20px}

.drawer{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.44);
  opacity:0;
  pointer-events:none;
  transition:.2s
}
.drawer.open{
  opacity:1;
  pointer-events:auto
}
.drawer-panel{
  width:min(82vw,300px);
  height:100%;
  background:var(--panel);
  padding:16px;
  box-shadow:var(--shadow);
  transform:translateX(-100%);
  transition:.22s
}
.drawer.open .drawer-panel{
  transform:translateX(0)
}
.drawer-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:14px
}
.drawer-item{
  width:100%;
  border:0;
  background:var(--panel2);
  color:var(--text);
  padding:12px 14px;
  border-radius:12px;
  text-align:left;
  margin-bottom:8px;
  font-size:14px
}

@media (min-width:600px){
  body{
    display:grid;
    place-items:center
  }
  .app{
    height:100vh;
    border-left:1px solid var(--line);
    border-right:1px solid var(--line)
  }
}

.detail{
  position:absolute;
  inset:68px 0 80px;
  padding:0 16px 16px;
  overflow:auto;
  background:var(--bg);
  transform:translateX(100%);
  transition:.22s
}
.detail.open{
  transform:translateX(0)
}
.detail-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:8px 0
}
.icon-btn.back{
  width:36px;
  height:36px;
  border-radius:18px;
  background:var(--panel2);
  font-size:18px
}
.detail-actions{
  display:flex;
  gap:6px
}
.icon-pill{
  border:0;
  background:var(--panel2);
  color:var(--text);
  border-radius:999px;
  padding:8px 12px;
  font-size:14px
}
.detail-header h2{
  margin:6px 0 4px;
  font-size:20px;
  font-weight:700
}
.detail-header .badge{
  display:inline-flex;
  align-items:center;
  padding:3px 10px;
  border-radius:999px;
  background:var(--panel2);
  color:var(--muted);
  font-size:12px;
  margin-left:0
}
.detail-meta{
  margin-top:14px;
  border-radius:14px;
  background:var(--panel);
  padding:10px 12px;
  display:flex;
  flex-direction:column;
  gap:6px
}
.meta-row{
  display:flex;
  justify-content:space-between;
  font-size:13px
}
.meta-row span{color:var(--muted)}
.meta-row strong{font-weight:600}

.detail-drive{
  margin-top:14px
}
.detail-drive h3{
  margin:0 0 8px;
  font-size:14px
}
.drive-grid{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:8px
}
.drive-item{
  border:0;
  background:var(--panel2);
  color:var(--text);
  border-radius:14px;
  padding:12px 8px;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:4px;
  font-size:16px
}

.app.show-detail .list{
  filter:blur(3px);
  pointer-events:none
}
.app.show-detail .fab-menu,
.app.show-detail .bottom-nav{
  opacity:0;
  pointer-events:none
}

html,body,.app{overflow-x:hidden!important}
*{-webkit-tap-highlight-color:transparent}
img,svg{max-width:100%;height:auto}

.topbar{
  grid-template-columns:44px minmax(0,1fr) max-content!important
}
.theme-toggle,#themeToggle{
  justify-self:end;
  margin-right:env(safe-area-inset-right);
  flex:0 0 auto
}
