/* =========================================================
   Cerox Logistics · Aplicación de gestión y portal de clientes
   ========================================================= */
:root {
  --blue: #0041FC;
  --blue-600: #0036D6;
  --navy: #061A5C;
  --side: #071340;
  --ink: #0B1020;
  --text: #2B3245;
  --muted: #667085;
  --line: #E4E8F2;
  --bg: #F4F6FB;
  --card: #FFFFFF;
  --ok: #0B7A48;   --ok-bg: #E7F8EF;
  --warn: #9A5B00; --warn-bg: #FFF4E0;
  --bad: #B42318;  --bad-bg: #FEECEB;
  --info: #0040C9; --info-bg: #E8EEFF;
  --mute: #4A5468; --mute-bg: #EEF1F6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px -6px rgba(16,24,40,.10);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Montserrat', 'Inter', system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); margin: 0 0 .6em; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
.ic { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; letter-spacing: .02em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.inline-form { display: inline-flex; gap: 6px; }
.tbl select { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: #fff; }
:focus-visible { outline: 3px solid #8AA8FF; outline-offset: 2px; border-radius: 6px; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: linear-gradient(180deg, #0A1B5C 0%, var(--side) 60%); color: rgba(255,255,255,.75); padding: 22px 14px; overflow-y: auto; }
.side-brand { padding: 4px 10px 6px; }
.side-brand img { width: 140px; height: auto; }
.side-role { display: block; padding: 0 10px 18px; font-size: .7rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #7E9BFF; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: rgba(255,255,255,.78); font-weight: 500; transition: background .15s, color .15s; }
.side-nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.side-nav a.on { background: var(--blue); color: #fff; box-shadow: 0 8px 20px -10px rgba(0,65,252,.9); }
.side-nav .count { margin-left: auto; background: #FF6B3D; color: #fff; font-size: .72rem; padding: 1px 7px; border-radius: 999px; }
.side-nav hr { border: 0; border-top: 1px solid rgba(255,255,255,.1); margin: 10px 8px; }
.side-foot { border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; margin-top: 14px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: #fff; }
.side-user:hover, .side-user.on { background: rgba(255,255,255,.07); text-decoration: none; }
.side-user strong { display: block; font-size: .88rem; }
.side-user small { display: block; font-size: .75rem; color: rgba(255,255,255,.55); overflow: hidden; text-overflow: ellipsis; max-width: 160px; white-space: nowrap; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--blue); display: grid; place-items: center; font-weight: 700; flex: none; }
.side-logout { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; color: rgba(255,255,255,.65); padding: 10px 12px; border-radius: 10px; cursor: pointer; text-align: left; }
.side-logout:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-backdrop { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px; padding: 16px 32px; background: rgba(244,246,251,.88); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.3rem; margin: 0; flex: 1; min-width: 0; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--ink); }
.menu-btn .ic { width: 24px; height: 24px; }
.content { padding: 28px 32px 56px; max-width: 1320px; width: 100%; }

/* ---------- Componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 22px; align-items: start; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 600; font-size: .9rem; cursor: pointer; background: #fff; color: var(--ink); border-color: var(--line); transition: background .15s, box-shadow .15s; white-space: nowrap; }
.btn:hover { text-decoration: none; background: #F7F9FD; }
.btn .ic { width: 16px; height: 16px; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-600); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 6px 11px; font-size: .82rem; }
.btn-block { width: 100%; padding: 12px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info, .badge-brand { background: var(--info-bg); color: var(--info); }
.badge-mute { background: var(--mute-bg); color: var(--mute); }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-size: .92rem; border: 1px solid transparent; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: #BDEBD3; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: #FBDDA8; }
.alert-bad { background: var(--bad-bg); color: var(--bad); border-color: #F8C9C5; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #C8D6FF; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; color: inherit; }
a.kpi:hover { text-decoration: none; border-color: #BCCBFF; }
.kpi-ic { width: 44px; height: 44px; border-radius: 12px; background: var(--info-bg); color: var(--blue); display: grid; place-items: center; flex: none; }
.kpi-ic .ic { width: 22px; height: 22px; }
.kpi strong { display: block; font-family: var(--display); font-style: italic; font-weight: 900; font-size: 1.7rem; color: var(--ink); line-height: 1.1; }
.kpi span { color: var(--muted); font-size: .84rem; }

/* Tablas */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr[data-href] { cursor: pointer; }
.tbl tbody tr:hover td { background: #F8FAFF; }
.tbl .sub { display: block; font-size: .8rem; color: var(--muted); }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.empty .ic { width: 36px; height: 36px; margin: 0 auto 10px; color: #B4BED3; }

/* Filtros */
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filters input, .filters select { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 12px; min-width: 0; }
.filters input[type="search"] { flex: 1 1 240px; }
.filters select { flex: 0 1 200px; }

/* Formularios */
.form-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .84rem; font-weight: 600; color: var(--ink); min-width: 0; }
.field b { color: var(--bad); }
.field-wide { grid-column: 1 / -1; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #D5DBE8; border-radius: 10px; padding: 10px 12px; background: #fff; font-weight: 400; transition: border-color .15s, box-shadow .15s; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(0,65,252,.12); }
.field input[readonly] { background: #F4F6FA; color: var(--muted); }
.field textarea { resize: vertical; }
.form-section { font-size: .76rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--blue); grid-column: 1 / -1; margin: 10px 0 -4px; padding-top: 10px; border-top: 1px solid var(--line); }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: .9rem; }
.stack { display: grid; gap: 14px; }
.errors { margin: 0 0 18px; padding: 12px 16px 12px 34px; background: var(--bad-bg); color: var(--bad); border-radius: 10px; font-size: .9rem; }

/* Notificaciones */
.no-margin { margin: 0; }
.vars { font-size: .82rem; color: var(--muted); margin: 0; line-height: 2; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82em; background: var(--info-bg); color: var(--info); padding: 2px 6px; border-radius: 6px; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { position: relative; width: 44px; height: 24px; border-radius: 999px; background: #CBD2E0; transition: background .2s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid #8AA8FF; outline-offset: 2px; }

/* Detalle */
.dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; margin: 0; }
.dl dt { font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.dl dd { margin: 3px 0 0; color: var(--ink); word-break: break-word; }
.dl .wide { grid-column: 1 / -1; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 18px 12px; }
.timeline li::before { content: ''; position: absolute; left: -26px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--blue); }
.timeline li:first-child::before { background: var(--blue); }
.timeline time { display: block; font-size: .78rem; color: var(--muted); }
.timeline p { margin: 4px 0 0; font-size: .88rem; }
.timeline .priv { font-size: .72rem; color: var(--warn); font-weight: 600; }

/* Casillero */
.mailbox { position: relative; overflow: hidden; border-radius: var(--radius); padding: 26px; background: linear-gradient(135deg, #0041FC 0%, #002BA8 60%, #061A5C 100%); color: #fff; margin-bottom: 22px; }
.mailbox::after { content: ''; position: absolute; right: -30px; bottom: -40px; width: 300px; height: 190px; background: url('../img/logo-x-white.svg') no-repeat center / contain; opacity: .1; }
.mailbox h2 { color: #fff; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; opacity: .85; }
.mailbox address { font-style: normal; font-size: 1.15rem; line-height: 1.6; position: relative; z-index: 1; }
.mailbox address strong { font-family: var(--display); font-style: italic; font-weight: 900; font-size: 1.5rem; }
.mailbox .btn { margin-top: 14px; position: relative; z-index: 1; }
.mailbox p { position: relative; z-index: 1; opacity: .8; font-size: .88rem; margin: 12px 0 0; max-width: 560px; }

/* Paginador */
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 36px; padding: 7px 10px; border-radius: 8px; text-align: center; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: .88rem; }
.pager a.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.pager a:hover { text-decoration: none; border-color: var(--blue); }
.pager span { border: 0; background: none; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(900px 600px at 80% 0%, #2F66FF 0%, transparent 60%), linear-gradient(160deg, #0041FC 0%, #061A5C 100%); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 20px; padding: 36px 32px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.45); }
.auth-logo { width: 170px; margin: 0 auto 22px; }
.auth-card h1 { font-size: 1.35rem; text-align: center; margin-bottom: 4px; }
.auth-card > p { text-align: center; margin: 0 0 22px; }
.auth-foot { margin-top: 20px; text-align: center; font-size: .85rem; color: var(--muted); }
.auth-foot a { font-weight: 600; }
.secure-note { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 16px; font-size: .78rem; color: var(--muted); }
.secure-note .ic { width: 14px; height: 14px; color: var(--ok); }

.auth-card-wide { max-width: 560px; }
.auth-card-wide h1, .auth-card-wide > p { text-align: left; }
.auth-request { margin-top: 14px; background: var(--info-bg); border-color: #C8D6FF; color: var(--info); white-space: normal; text-align: center; }
.auth-request:hover { background: #DCE5FF; }
.auth-done { text-align: center; }
.auth-done h1 { margin-top: 12px; }
.auth-done p { margin: 8px 0 22px; }
.auth-done-ic { width: 64px; height: 64px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--ok-bg); color: var(--ok); }
.auth-done-ic .ic { width: 32px; height: 32px; }
.auth-done-bad { background: var(--bad-bg); color: var(--bad); }
/* Campo trampa anti-bots: invisible para personas, accesible solo a bots */
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.field-error { margin: -4px 0 0; color: var(--bad); font-size: .85rem; font-weight: 600; }
.pass-rules { margin: 0; padding-left: 20px; font-size: .82rem; color: var(--muted); display: grid; gap: 2px; }
.tabs-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.tab-pill { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600; font-size: .88rem; }
.tab-pill:hover { text-decoration: none; border-color: var(--blue); }
.tab-pill.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.tab-pill b { margin-left: 4px; padding: 0 7px; border-radius: 999px; background: rgba(0,0,0,.08); font-size: .78rem; }
.tab-pill.on b { background: rgba(255,255,255,.25); }
.check input[type="radio"] { width: 16px; height: 16px; accent-color: var(--blue); }

/* Integraciones */
.integ-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 22px; margin-bottom: 22px; }
.integ { display: flex; flex-direction: column; margin: 0; }
.integ .form-actions { margin-top: auto; padding-top: 18px; }
.integ-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 48px; margin-bottom: 10px; }
.integ-head img { max-height: 42px; max-width: 170px; width: auto; }
.integ-api { font-weight: 600; color: var(--ink); margin: 0 0 6px; font-size: .9rem; }
.integ-help { font-size: .85rem; margin: 0 0 14px; }
.text-bad { color: var(--bad); font-weight: 600; }
.text-warn { color: var(--warn); }

/* ---------- Perfiles y permisos ---------- */
fieldset.ro { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.ro[disabled] input, fieldset.ro[disabled] select, fieldset.ro[disabled] textarea { opacity: .75; cursor: not-allowed; }
.tbl .center { text-align: center; }
.perm-tbl td.center { width: 120px; }
.perm-tbl input[type="radio"] { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; }
.perm-mod { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); }
.perm-mod .ic { width: 18px; height: 18px; color: var(--blue); }
.perm-chips .badge { margin: 2px 4px 2px 0; }
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-main, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 272px; z-index: 40; transform: translateX(-100%); transition: transform .25s ease; }
  .side-open .side { transform: none; }
  .side-open .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(5,12,40,.5); z-index: 30; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .topbar h1 { font-size: 1.1rem; }
  .content { padding: 18px 16px 48px; }
  .form-cols, .form-cols-3, .dl { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  .table-wrap { margin: 0 -18px; padding: 0 18px; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; }
}
@media print {
  .side, .topbar, .form-actions, .no-print { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; border: 0; }
}
