/* =====================================================================
   Asesor Laboral — hoja de estilos
   ===================================================================== */
:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --border: #dfe3ea;
    --text: #1d2433;
    --muted: #64708a;
    --primary: #1f4e8c;
    --primary-2: #2c66b3;
    --primary-soft: #e6eefa;
    --sidebar: #14223a;
    --sidebar-text: #c8d3e6;
    --sidebar-active: #24406b;
    --red: #c62828;
    --red-soft: #fdecec;
    --orange: #d97706;
    --orange-soft: #fff4e5;
    --green: #2e7d32;
    --green-soft: #e9f6ea;
    --purple: #6d28d9;
    --purple-soft: #f1eafd;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14.5px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1.02rem; margin: 1rem 0 .5rem; }
h4 { font-size: .95rem; margin: .8rem 0 .4rem; }
pre { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .75rem; overflow: auto; white-space: pre-wrap; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
blockquote { margin: .5rem 0; padding: .5rem .9rem; border-left: 4px solid var(--primary); background: var(--primary-soft); border-radius: 0 8px 8px 0; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 1rem .6rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; padding: .3rem .6rem 1rem; color: #fff; font-weight: 700; font-size: 1.02rem; }
.brand .logo { width: 34px; height: 34px; border-radius: 8px; background: linear-gradient(135deg, #3b82f6, #1f4e8c); display: grid; place-items: center; font-size: 1.1rem; }
.brand small { display: block; font-weight: 400; color: var(--sidebar-text); font-size: .72rem; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7d8db0; padding: .9rem .7rem .3rem; }
.nav a { display: flex; align-items: center; gap: .55rem; padding: .45rem .7rem; color: var(--sidebar-text); border-radius: 7px; font-size: .9rem; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 999px; font-size: .7rem; padding: 0 .45rem; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: .6rem 1.4rem; position: sticky; top: 0; z-index: 20; }
.topbar form.search { flex: 1; max-width: 520px; }
.topbar .search input { width: 100%; }
.topbar .user { margin-left: auto; display: flex; align-items: center; gap: .8rem; font-size: .88rem; }
.content { padding: 1.3rem 1.4rem 3rem; max-width: 1500px; width: 100%; }
.menu-toggle { display: none; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- Tarjetas y rejillas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .6rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

/* Indicadores del panel principal */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; display: block; color: var(--text); box-shadow: var(--shadow); transition: transform .08s; }
.kpi:hover { text-decoration: none; transform: translateY(-1px); border-color: var(--primary-2); }
.kpi .icon { font-size: 1.25rem; }
.kpi .value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; margin-top: .2rem; }
.kpi .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi.red { border-left: 4px solid var(--red); }
.kpi.orange { border-left: 4px solid var(--orange); }
.kpi.green { border-left: 4px solid var(--green); }
.kpi.blue { border-left: 4px solid var(--primary-2); }
.kpi.purple { border-left: 4px solid var(--purple); }

/* Panel de plazos */
.deadline-board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; }
.deadline-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.deadline-col h3 { margin: 0; padding: .6rem .8rem; font-size: .9rem; border-bottom: 1px solid var(--border); }
.deadline-col.today h3, .deadline-col.urgent h3 { background: var(--red-soft); color: var(--red); }
.deadline-col.week h3 { background: var(--orange-soft); color: var(--orange); }
.deadline-col.month h3 { background: var(--green-soft); color: var(--green); }
.deadline-item { padding: .55rem .8rem; border-bottom: 1px solid var(--border); font-size: .86rem; }
.deadline-item:last-child { border-bottom: 0; }
.deadline-item.critical { background: #fff7f7; border-left: 4px solid var(--red); }
.deadline-item .meta { color: var(--muted); font-size: .78rem; }
.empty { color: var(--muted); padding: .8rem; font-size: .88rem; text-align: center; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.table tr:hover td { background: #fafbfd; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { font-weight: 700; background: var(--surface-2); }
.table.compact th, .table.compact td { padding: .3rem .45rem; }
.table tr.row-warn td { background: var(--orange-soft); }
.table tr.row-bad td { background: var(--red-soft); }

/* ---------- Formularios ---------- */
label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: .25rem; color: #39445c; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=datetime-local], input[type=search], input[type=tel], input[type=url], select, textarea {
    width: 100%; padding: .48rem .6rem; border: 1px solid #c9d0db; border-radius: 7px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary-2); }
textarea { min-height: 90px; resize: vertical; }
textarea.tall { min-height: 260px; }
textarea.editor { min-height: 560px; font-family: var(--mono); font-size: 13px; }
.field { margin-bottom: .8rem; }
.field .hint { color: var(--muted); font-size: .78rem; margin-top: .2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 1rem; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 500; }
.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .85rem; border-radius: 7px; border: 1px solid #c9d0db; background: #fff; color: var(--text); font: inherit; font-size: .88rem; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--red); border-color: #efb7b7; }
.btn.danger:hover { background: var(--red-soft); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ai { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.ai:hover { background: #7c3aed; }
.btn.small { padding: .22rem .55rem; font-size: .8rem; }
.btn.big { padding: .7rem 1.2rem; font-size: 1rem; font-weight: 600; }
.btn[disabled] { opacity: .55; cursor: wait; }
.inline-form { display: inline; }

/* ---------- Etiquetas ---------- */
.badge { display: inline-block; padding: .08rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 600; background: #eef1f6; color: #39445c; white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.tag { display: inline-block; font-size: .74rem; background: #eef1f6; border-radius: 4px; padding: 0 .4rem; margin: 0 .2rem .2rem 0; }

/* ---------- Avisos ---------- */
.alert { padding: .7rem .9rem; border-radius: 8px; margin-bottom: .9rem; border: 1px solid; font-size: .9rem; }
.alert.success { background: var(--green-soft); border-color: #b7dfb9; color: #1b5e20; }
.alert.error, .alert.danger { background: var(--red-soft); border-color: #f2b8b8; color: #8e1c1c; }
.alert.warning { background: var(--orange-soft); border-color: #f5d199; color: #8a4b00; }
.alert.info { background: var(--primary-soft); border-color: #bcd0ee; color: #173d70; }
.disclaimer { font-size: .78rem; color: var(--muted); border-top: 1px dashed var(--border); margin-top: .8rem; padding-top: .5rem; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .85rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-size: .88rem; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- Flujo del expediente ---------- */
.flow { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0 1rem; }
.flow span { font-size: .74rem; padding: .2rem .55rem; border-radius: 999px; background: #eef1f6; color: var(--muted); }
.flow span.done { background: var(--green-soft); color: var(--green); }
.flow span.current { background: var(--primary); color: #fff; font-weight: 600; }

/* Listas de definición */
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; font-size: .9rem; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; }

/* Cronología */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.2rem; border-left: 2px solid var(--border); margin-left: .4rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary-2); }
.timeline .when { font-size: .78rem; color: var(--muted); }

/* IA */
.ai-box { border: 1px solid #ddd0f7; background: #fcfaff; border-radius: var(--radius); padding: 1rem 1.1rem; }
.ai-box h2, .ai-box h3, .ai-box h4 { color: #4c1d95; }
.chat { display: flex; flex-direction: column; gap: .7rem; }
.chat .msg { border-radius: 10px; padding: .7rem .9rem; max-width: 100%; }
.chat .msg.user { background: var(--primary-soft); align-self: flex-end; max-width: 85%; }
.chat .msg.assistant { background: #fff; border: 1px solid var(--border); }
.chat .msg .who { font-size: .72rem; text-transform: uppercase; color: var(--muted); margin-bottom: .2rem; }
.loading-overlay { position: fixed; inset: 0; background: rgba(20,34,58,.45); display: none; align-items: center; justify-content: center; z-index: 100; }
.loading-overlay.show { display: flex; }
.loading-overlay .box { background: #fff; padding: 1.3rem 1.6rem; border-radius: 12px; text-align: center; max-width: 380px; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--purple-soft); border-top-color: var(--purple); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto .7rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cálculos */
.calc-block { border: 1px solid var(--border); border-radius: 8px; margin-bottom: .8rem; }
.calc-block h4 { margin: 0; padding: .45rem .8rem; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.calc-block .body { padding: .6rem .8rem; }
.calc-result { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.formula { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: .5rem .7rem; border-radius: 6px; }

/* Barras para estadísticas */
.bars { display: flex; flex-direction: column; gap: .35rem; }
.bar-row { display: grid; grid-template-columns: 210px 1fr 70px; gap: .6rem; align-items: center; font-size: .84rem; }
.bar-track { background: #eef1f6; border-radius: 4px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary-2); border-radius: 4px; }
.bar-row .v { text-align: right; font-variant-numeric: tabular-nums; }

/* Autenticación */
.auth-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(160deg, #14223a 0%, #24406b 100%); padding: 1rem; }
.auth-box { background: #fff; border-radius: 14px; padding: 2rem 2.1rem; width: 100%; max-width: 410px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-box h1 { text-align: center; margin-bottom: .2rem; }
.auth-box .sub { text-align: center; color: var(--muted); margin-bottom: 1.3rem; font-size: .9rem; }
.auth-box .btn { width: 100%; justify-content: center; }
.public-page { background: var(--bg); min-height: 100vh; padding: 1.5rem 1rem; }
.public-box { max-width: 760px; margin: 0 auto; }

.qr { display: inline-block; padding: 8px; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.hidden { display: none !important; }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-orange { color: var(--orange); }

/* Impresión (escritos, informes) */
.print-doc { background: #fff; max-width: 820px; margin: 0 auto; padding: 2.2cm 2cm; font-family: "Times New Roman", Times, serif; font-size: 12pt; line-height: 1.55; color: #000; }
.print-doc h2 { font-size: 13pt; } .print-doc h3 { font-size: 12.5pt; }
.print-doc table { border-collapse: collapse; width: 100%; } .print-doc td, .print-doc th { border: 1px solid #999; padding: 3px 6px; font-size: 10.5pt; }

@media print {
    .sidebar, .topbar, .no-print, .tabs, .page-head .actions { display: none !important; }
    .app { display: block; }
    .content { padding: 0; }
    body { background: #fff; }
    .card { box-shadow: none; border: 0; padding: 0; }
}

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .deadline-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -270px; width: 260px; z-index: 50; transition: left .2s; }
    .sidebar.open { left: 0; }
    .menu-toggle { display: inline-flex; }
    .grid-2, .grid-3, .grid-4, .deadline-board { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .content { padding: 1rem; }
    .bar-row { grid-template-columns: 120px 1fr 60px; }
    .topbar .user .name { display: none; }
}

/* Ajustes */
.grid > * { min-width: 0; }
.flow span.sep { background: none; padding: 0 .1rem; color: var(--muted); }
.flow form .btn { margin: 0; }
