:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e3e7ee;
  --brand: #1F3864; --brand-2: #2f5597; --accent: #d9e2f3; --danger: #c00000; --ok: #2e7d32;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 Arial, "Segoe UI", system-ui, sans-serif; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
a { color: var(--brand-2); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 24px 0 10px; }
small { color: var(--muted); }

/* layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #fff; display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 18px; }
.brand small { display: block; color: #c9d4ea; font-size: 11px; }
.brand.big small { color: var(--muted); }
.logo { width: 34px; height: 34px; border-radius: 8px; background: #fff; color: var(--brand); font-weight: 700; display: grid; place-items: center; flex: none; }
.brand.big .logo { background: var(--brand); color: #fff; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { color: #e6ecf7; text-decoration: none; padding: 8px 10px; border-radius: 6px; }
nav a:hover { background: rgba(255,255,255,.08); }
nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 700; }
.me { margin-top: auto; padding: 10px 6px; border-top: 1px solid rgba(255,255,255,.15); display: flex; flex-direction: column; gap: 2px; }
.me small { color: #c9d4ea; }
.me .btn.link { color: #fff; padding: 4px 0; text-align: left; }
.main { padding: 22px 26px 60px; min-width: 0; }

/* cards & tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.kpi { border-left: 6px solid var(--c, var(--accent)); cursor: pointer; }
.kpi .n { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.two { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.three { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 700; background: #f8f9fb; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #f8fafc; }
tfoot td { font-weight: 700; background: #f8f9fb; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--panel); }
.table-wrap.tall { max-height: calc(100vh - 230px); }
tr.estado td:first-child { box-shadow: inset 6px 0 0 var(--c, transparent); }
tr.clickable { cursor: pointer; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--c, #eee); white-space: nowrap; }
.warn { color: var(--danger); font-weight: 700; }
.muted { color: var(--muted); }
.alert-list a { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.alert-list a:last-child { border: 0; }
.alert-list b { min-width: 28px; text-align: center; border-radius: 999px; padding: 0 8px; background: #eef1f6; }
.alert-list b.on { background: #ffc7ce; color: #9c0006; }
.bar { height: 8px; background: var(--brand-2); border-radius: 4px; min-width: 2px; }

/* forms */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.toolbar .grow { flex: 1; min-width: 180px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; padding-bottom: 7px; }
input, select, textarea { font: inherit; color: var(--ink); border: 1px solid #cfd5df; border-radius: 6px; padding: 6px 8px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9db6e4; border-color: var(--brand-2); }
input:disabled, select:disabled, textarea:disabled { background: #f3f4f6; color: #555; }
textarea { min-height: 70px; resize: vertical; }
.form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form .span2 { grid-column: span 2; } .form .span4 { grid-column: 1 / -1; }
td input, td select { width: 100%; padding: 4px 6px; }
td input.n { text-align: right; }
.btn { font: inherit; border: 1px solid #cfd5df; background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #f3f5f9; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; padding: 4px; color: var(--brand-2); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.head h1 { margin: 0; }
.summary { grid-template-columns: repeat(5, minmax(0,1fr)); }
.summary .v { font-size: 18px; font-weight: 700; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #ffc7ce; color: #9c0006; white-space: nowrap; }
.hist { font-size: 13px; }
.hist li { padding: 6px 0; border-bottom: 1px solid var(--line); list-style: none; }
.hist ul { padding: 0; margin: 0; }
.hist .diff { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: pre-wrap; }
.error { color: var(--danger); min-height: 1em; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1F3864, #2f5597); }
.login-card { background: #fff; padding: 28px; border-radius: 12px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.login-card #loginLocal { display: flex; flex-direction: column; gap: 12px; }
.login-card .btn { justify-content: center; }

.toast { position: fixed; right: 18px; bottom: 18px; background: #1d2433; color: #fff; padding: 10px 14px; border-radius: 8px; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; max-width: 420px; z-index: 50; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--danger); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .side .brand { padding: 0; } nav { flex-direction: row; flex-wrap: wrap; } .me { margin: 0; border: 0; flex-direction: row; align-items: center; gap: 8px; }
  .main { padding: 16px; }
  .form, .summary { grid-template-columns: 1fr 1fr; }
}

/* ajustes de detalle */
a.kpi { text-decoration: none; color: var(--ink); }
a.kpi:hover { border-color: #c5cfdf; }
td:first-child b { white-space: nowrap; }
td.mes { white-space: nowrap; }
select.st { min-width: 165px; }
.wide { grid-column: 1 / -1; }
.alert-list b { white-space: nowrap; align-self: center; }
table[data-l] td:first-child { width: 55%; }
table[data-l] td.actions, #tti td.actions { flex-wrap: nowrap; display: table-cell; white-space: nowrap; }
table[data-l] td.actions .btn + .btn { margin-left: 4px; }
.ajustes { grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); }
table[data-l] input[data-k=valor] { min-width: 210px; }

.side .cli { color: #c9d4ea; margin: 0 6px 14px; }
.side .cli select { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.25); }
.side .cli select option { color: #1d2433; }

td.nowrap { white-space: nowrap; }
.dir { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.dir small { font-size: 12px; }
#tu td.actions { display: table-cell; white-space: nowrap; }
#tu td.actions .btn + .btn { margin-left: 4px; }

/* marca y barra superior */
.logo-img { display: block; max-width: 170px; max-height: 40px; object-fit: contain; }
.brand { flex-direction: column; align-items: flex-start; gap: 8px; }
.brand .logo-img + .logo-fb + div strong { font-size: 13px; }
.layout { grid-template-columns: 220px 1fr; }
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 26px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.greet { font-size: 15px; color: var(--muted); } .greet b { color: var(--ink); }
.user { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.who { display: flex; flex-direction: column; line-height: 1.2; } .who small { font-size: 11px; }
.main { padding-top: 18px; }
.login-head { background: var(--brand); color: #fff; margin: -28px -28px 6px; padding: 22px 28px; border-radius: 12px 12px 0 0; display: flex; flex-direction: column; gap: 10px; }
.login-head small { color: #c9d4ea; display: block; } .login-head .logo { background: #fff; color: var(--brand); }
.logo-cfg { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.logo-prev { background: var(--brand); border-radius: 8px; padding: 14px 18px; min-width: 200px; min-height: 68px; display: grid; place-items: center; }
.logo-prev .logo { background: #fff; color: var(--brand); }
@media (max-width: 860px) { .topbar { padding: 10px 16px; } .who small { display: none; } }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); font-weight: 700; border-bottom-color: var(--brand); }
.alm-info { color: var(--muted); font-size: 12px; line-height: 1.35; min-height: 1em; }
#talm td input { min-width: 110px; }

/* avisos de fecha */
.fecha { padding: 2px 6px; border-radius: 4px; display: inline-block; }
.av-naranja { background: #F8B26A; color: #4a2500; font-weight: 700; }
.av-amarillo { background: #FFE066; color: #4a3b00; font-weight: 700; }
.av-rojo { background: #E5484D; color: #fff; font-weight: 700; }
.leyenda { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; font-size: 12px; }
/* observaciones enriquecidas */
.obs-wrap { display: flex; flex-direction: column; gap: 4px; }
.obs-wrap .lbl { font-size: 12px; color: var(--muted); }
.obs-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.obs { min-height: 90px; max-height: 480px; overflow: auto; border: 1px solid #cfd5df; border-radius: 6px; padding: 8px 10px; background: #fff; line-height: 1.45; }
.obs:focus { outline: 2px solid #9db6e4; border-color: var(--brand-2); }
.obs.ro { background: #f3f4f6; }
.obs img { max-width: 100%; max-height: 360px; border-radius: 4px; display: block; margin: 6px 0; }
/* adjuntos */
.adj.drag { outline: 2px dashed var(--brand-2); background: #f3f7ff; }
.adj-drop { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.adj-list { list-style: none; margin: 0; padding: 0; }
.adj-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.adj-list li:last-child { border-bottom: 0; }
.adj-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); flex: none; }
.adj-ico { width: 44px; height: 44px; border-radius: 4px; background: var(--accent); color: var(--brand); font-size: 11px; font-weight: 700; display: grid; place-items: center; flex: none; }
.adj-info { flex: 1; min-width: 0; display: flex; flex-direction: column; } .adj-info a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===================== CAU ===================== */
.side .nuevo { justify-content: center; margin: 0 6px 12px; background: #fff; color: var(--brand); border-color: #fff; font-weight: 700; }
.side .nuevo:hover { background: #e9eef8; }
.nav-t { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #9fb0d0; padding: 12px 10px 4px; }
nav a { display: flex; justify-content: space-between; align-items: center; }
nav a b { font-size: 11px; background: rgba(255,255,255,.16); border-radius: 999px; padding: 0 7px; min-width: 22px; text-align: center; }
nav a b:empty { display: none; }
nav a b.rojo { background: #E5484D; }
.mailst { margin-top: auto; font-size: 11px; color: #c9d4ea; padding: 10px 6px 0; border-top: 1px solid rgba(255,255,255,.15); }
.mailst .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #9fb0d0; margin-right: 5px; }
.mailst .dot.ok { background: #4ade80; } .mailst .dot.ko { background: #f87171; }
.buscar { flex: 1; max-width: 520px; } .buscar input { width: 100%; }

/* bandeja */
.vista-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 10px; }
.vista-tools label { min-width: 130px; }
.tk-list { display: flex; flex-direction: column; gap: 6px; }
.tk { display: grid; grid-template-columns: 38px 1fr 150px 130px 150px; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); border-left: 4px solid var(--pc, #cfd5df); }
.tk:hover { border-color: #b9c4d8; border-left-color: var(--pc, #cfd5df); background: #fbfcfe; }
.tk .av { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #334; background: var(--ac, #e8edf6); font-size: 13px; }
.tk .tit { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tk .tit span { color: var(--muted); font-weight: 400; }
.tk .sub { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.tk .tags { display: flex; gap: 4px; margin-bottom: 3px; flex-wrap: wrap; }
.tk .col { font-size: 12px; display: flex; flex-direction: column; gap: 3px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 4px; white-space: nowrap; font-weight: 700; }
.tag.nuevo { background: #dcfce7; color: #166534; } .tag.vencido { background: #fee2e2; color: #b91c1c; }
.tag.pronto { background: #fef3c7; color: #92400e; } .tag.resp { background: #dbeafe; color: #1e40af; } .tag.gris { background: #eef1f6; color: #4b5563; }
.prio { display: inline-flex; align-items: center; gap: 5px; } .prio::before { content: ''; width: 9px; height: 9px; border-radius: 2px; background: var(--pc); }
.est { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--ec, #eee); width: fit-content; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.vacio { padding: 40px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ficha */
.ficha { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.ficha-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; flex-wrap: wrap; }
.ficha-head h1 { margin: 0 0 6px; font-size: 19px; } .ficha-head h1 small { font-weight: 400; color: var(--muted); font-size: 15px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; border-left: 4px solid #cfd5df; }
.msg.respuesta { border-left-color: var(--brand-2); } .msg.nota { background: #fffbea; border-left-color: #f5b400; }
.msg-h { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px 0; }
.msg-h .av { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: #e8edf6; flex: none; }
.msg.respuesta .av { background: var(--brand); color: #fff; } .msg.nota .av { background: #f5b400; color: #fff; }
.msg-h .q { font-size: 12px; color: var(--muted); } .msg-h .q b { color: var(--ink); font-size: 13px; }
.msg-h .dest { font-size: 11px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.mail { padding: 8px 14px 12px 56px; overflow-x: auto; line-height: 1.5; word-wrap: break-word; }
.mail img { max-width: 100%; height: auto; } .mail p { margin: 0 0 .6em; } .mail table { width: auto; background: transparent; } .mail td { border: 0; padding: 2px 4px; }
.mail blockquote { margin: 0 0 0 8px; padding-left: 10px; border-left: 2px solid var(--line); color: var(--muted); }
.cita-btn { margin-left: 56px; margin-bottom: 8px; } .cita { display: none; color: var(--muted); border-top: 1px dashed var(--line); } .cita.on { display: block; }
.adjs { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 14px 12px 56px; }
.adjs a { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px 4px 4px; text-decoration: none; color: var(--ink); font-size: 12px; max-width: 260px; background: #fff; }
.adjs a img, .adjs a .ext { width: 52px; height: 52px; object-fit: cover; border-radius: 4px; flex: none; }
.adjs a .ext { background: var(--accent); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 11px; }
.adjs a span { overflow: hidden; text-overflow: ellipsis; display: flex; flex-direction: column; } .adjs a small { font-size: 11px; }
.composer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin-top: 14px; }
.composer.nota { background: #fffbea; }
.composer .tabs { margin-bottom: 10px; }
.composer .dest { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.editor { min-height: 140px; max-height: 420px; overflow: auto; border: 1px solid #cfd5df; border-radius: 6px; padding: 8px 10px; background: #fff; line-height: 1.5; }
.editor:focus { outline: 2px solid #9db6e4; border-color: var(--brand-2); }
.editor:empty::before { content: attr(data-ph); color: #9aa3b2; }
.ed-tools { display: flex; gap: 4px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.ed-tools .btn { padding: 3px 9px; }
.ed-tools select { max-width: 260px; }
.files { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.files span { background: #eef1f6; border-radius: 4px; padding: 2px 8px; font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.files span button { border: 0; background: none; cursor: pointer; color: var(--danger); padding: 0; }
.send { display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.send .grp { display: flex; gap: 6px; align-items: center; }
.props { position: sticky; top: 74px; display: flex; flex-direction: column; gap: 12px; }
.props .card { padding: 12px 14px; } .props h3 { font-size: 13px; margin: 0 0 8px; }
.props form { display: flex; flex-direction: column; gap: 8px; }
.sla-box div { display: flex; flex-direction: column; font-size: 12px; padding: 4px 0; } .sla-box b { font-size: 13px; }
.sla-box .ok { color: var(--ok); } .sla-box .ko { color: var(--danger); } .sla-box .pr { color: #b45309; }
.otros a { display: block; font-size: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-mini { font-size: 12px; max-height: 260px; overflow: auto; } .hist-mini div { padding: 4px 0; border-bottom: 1px solid var(--line); } .hist-mini small { display: block; }
.visor { position: fixed; inset: 0; background: rgba(10,15,30,.85); display: grid; place-items: center; z-index: 60; padding: 30px; }
.visor img { max-width: 95vw; max-height: 88vh; border-radius: 6px; background: #fff; } .visor button { position: fixed; top: 16px; right: 16px; }

/* panel */
.barras { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 10px; }
.barras div { flex: 1; display: flex; gap: 1px; align-items: flex-end; height: 100%; position: relative; }
.barras i { flex: 1; background: var(--brand-2); border-radius: 2px 2px 0 0; min-height: 1px; } .barras i.r { background: #4ade80; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
@media (max-width: 1100px) { .ficha { grid-template-columns: 1fr; } .props { position: static; } .tk { grid-template-columns: 38px 1fr; } .tk .col { display: none; } }

.tag.ext { background: #ede9fe; color: #5b21b6; }
.aviso-ext { margin: 0 14px 8px 56px; font-size: 12px; color: #92400e; background: #fef3c7; border-radius: 4px; padding: 4px 8px; width: fit-content; }
