/* ProForge · estilos base (sin dependencias) */
:root {
  --bg: #f5f7fb; --surface: #fff; --surface-2: #f0f3f9; --border: #d9dfeb; --text: #1b2333; --muted: #5b6477;
  --primary: #1f3a68; --primary-600: #2a4f8f; --primary-50: #e9effa; --accent: #0f766e;
  --ok: #15803d; --ok-bg: #e8f6ed; --warn: #a15c07; --warn-bg: #fdf3e2; --err: #b42318; --err-bg: #fdecea; --info: #1d4ed8; --info-bg: #eaf1fe;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary-600); }
a:hover { color: var(--primary); }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.07rem; } h4 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
small, .muted { color: var(--muted); }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: #000; color: #fff; padding: .5rem 1rem; z-index: 99; }
.skip:focus { left: 0; }

/* Estructura */
.app { display: grid; grid-template-columns: 245px 1fr; min-height: 100vh; }
.sidebar { background: var(--primary); color: #dfe7f5; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; font-weight: 700; font-size: 1.2rem; text-decoration: none; padding: 1.1rem 1.1rem .6rem; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; background: #fff; color: var(--primary); font-weight: 800; }
.sidebar nav { display: flex; flex-direction: column; padding: .25rem .6rem 1rem; }
.sidebar nav a { color: #dfe7f5; text-decoration: none; padding: .42rem .6rem; border-radius: 6px; font-size: .95rem; }
.sidebar nav a:hover { background: rgba(255,255,255,.09); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav-group { text-transform: uppercase; font-size: .7rem; letter-spacing: .08em; color: #9fb2d4; margin: .9rem .6rem .25rem; }
.sidebar-user { margin-top: auto; padding: .9rem 1.1rem; border-top: 1px solid rgba(255,255,255,.12); font-size: .9rem; }
.sidebar-user a { color: #fff; text-decoration: none; }
.sidebar-user small { color: #b6c4dd; }
.sidebar .btn-link { color: #b6c4dd; padding: 0; margin-top: .3rem; }
.main { padding: 1.6rem 2rem 3rem; min-width: 0; max-width: 1400px; }
.auth-wrap { max-width: 460px; margin: 6vh auto; padding: 0 1rem; }

/* Cabeceras de página */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.page-head .sub { color: var(--muted); margin: .15rem 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.breadcrumb { font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
.breadcrumb a { color: var(--muted); }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; margin-bottom: .7rem; 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)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: .85rem; }

/* Botones */
.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .45rem .85rem; border-radius: 6px; font: inherit; font-size: .93rem; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); color: #fff; }
.btn-danger { color: var(--err); border-color: #f1b8b2; }
.btn-danger:hover { background: var(--err-bg); color: var(--err); }
.btn-sm { padding: .25rem .55rem; font-size: .85rem; }
.btn-link { background: none; border: 0; color: var(--primary-600); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }

/* Formularios */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.field { margin-bottom: .9rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .83rem; margin-top: .2rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: .48rem .6rem; border: 1px solid #c3cbdb; border-radius: 6px; font: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 110px; resize: vertical; }
textarea.tall { min-height: 220px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary-600); outline: 2px solid var(--primary-50); }
.checkbox { display: flex; gap: .45rem; align-items: flex-start; font-weight: 400; }
.checkbox input { margin-top: .25rem; }
.form-row { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .3rem; }
.form-actions { display: flex; gap: .6rem; margin-top: .6rem; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0 .3rem; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--surface); }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; font-size: .93rem; }
th { background: var(--surface-2); font-weight: 600; font-size: .85rem; color: #334061; }
tr:hover td { background: #fafbfe; }
td.num, th.num { text-align: right; white-space: nowrap; }
table.compact td, table.compact th { padding: .3rem .45rem; }
.doc-table { margin-bottom: 1rem; }
.doc-table.small td, .doc-table.small th { font-size: .84rem; }
.doc-table.kv th { width: 30%; }

/* Insignias y avisos */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: #334061; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-err { background: var(--err-bg); color: var(--err); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-ia { background: #f3e8ff; color: #6b21a8; }
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: var(--ok-bg); border-color: #b7e2c4; color: #14532d; }
.alert-error { background: var(--err-bg); border-color: #f5c2bd; color: #7a1a12; }
.alert-warning { background: var(--warn-bg); border-color: #f2d4a3; color: #6b3d05; }
.alert-info { background: var(--info-bg); border-color: #c4d6fb; color: #1e3a8a; }
.inc { display: flex; gap: .6rem; padding: .5rem .2rem; border-bottom: 1px solid var(--border); }
.inc:last-child { border-bottom: 0; }
.inc .badge { flex-shrink: 0; min-width: 92px; text-align: center; }

/* Pestañas de programación */
.prog-head { margin-bottom: .7rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .15rem; border-bottom: 2px solid var(--border); margin-bottom: 1.2rem; }
.tabs a { padding: .5rem .75rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; font-size: .93rem; border-radius: 6px 6px 0 0; }
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tabs .count { font-size: .72rem; margin-left: .2rem; }

/* Progreso */
.progress { height: 9px; background: #e5e9f2; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.progress.warn > span { background: #d97706; }
.progress.err > span { background: var(--err); }

/* Árbol RA/CE */
.ra-block { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .8rem; background: var(--surface); }
.ra-block > summary, .ra-title { padding: .65rem .9rem; font-weight: 600; cursor: pointer; background: var(--surface-2); border-radius: var(--radius); list-style-position: inside; }
.ra-block[open] > summary { border-radius: var(--radius) var(--radius) 0 0; border-bottom: 1px solid var(--border); }
.ra-block .ce-list { padding: .4rem .9rem .7rem; }
.ce-item { display: grid; grid-template-columns: 2.4rem 1fr auto; gap: .5rem; padding: .35rem 0; border-bottom: 1px dashed #e3e7ef; align-items: start; }
.ce-item:last-child { border-bottom: 0; }
.ce-code { font-weight: 700; color: var(--primary); }
.ce-picker { max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: .5rem .7rem; background: #fff; }
.ce-picker .ra-name { font-weight: 700; margin: .5rem 0 .2rem; font-size: .9rem; }
.ce-picker .ra-name:first-child { margin-top: 0; }
.ce-picker label { font-weight: 400; display: flex; gap: .4rem; font-size: .88rem; margin: .1rem 0; }

/* Matriz */
.matrix td.miss { background: var(--err-bg); }
.matrix td.part { background: var(--warn-bg); }
.cell-ok { color: var(--ok); font-weight: 700; }
.cell-miss { color: var(--err); font-weight: 700; }

/* Calendario */
.cal { width: 100%; }
.cal th { text-align: center; }
.cal td { text-align: center; font-size: .8rem; padding: .3rem; height: 44px; }
.cal td.off { color: #b3bacb; background: #fafafa; }
.cal td.excl { background: #f3f4f6; color: #9ca3af; }
.cal td.ses { background: #eef6f5; }
.cal .d { display: block; font-size: .72rem; color: var(--muted); }
.cal .ut { display: inline-block; background: var(--primary); color: #fff; border-radius: 4px; padding: 0 .3rem; font-size: .72rem; margin: 1px; }

/* Documento (vista previa) */
.doc-preview { background: #fff; border: 1px solid var(--border); padding: 2rem 2.5rem; max-width: 980px; box-shadow: var(--shadow); }
.doc-preview h2 { color: var(--primary); } .doc-preview h3 { color: var(--primary); border-bottom: 1px solid var(--border); padding-bottom: .2rem; margin-top: 1.6rem; }
.doc-small { font-size: .85rem; color: #444; } .doc-muted { color: var(--muted); }
.doc-note { background: var(--err-bg); border-left: 4px solid var(--err); padding: .5rem .8rem; color: var(--err); font-weight: 600; }
.doc-break { border: 0; border-top: 2px dashed var(--border); margin: 2rem 0; }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.ia-note { border-left: 4px solid #7c3aed; background: #faf5ff; padding: .6rem .9rem; border-radius: 6px; color: #4c1d95; }
details.box { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 1rem; }
details.box > summary { padding: .7rem 1rem; cursor: pointer; font-weight: 600; }
details.box > .box-body { padding: 0 1rem 1rem; }
.diff-old { background: var(--err-bg); } .diff-new { background: var(--ok-bg); }
.pre { white-space: pre-wrap; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; } .mt-1 { margin-top: 1rem; }
.handle { cursor: grab; color: var(--muted); user-select: none; }
tr.dragging { opacity: .5; }

@media (max-width: 1000px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 1rem; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .tabs, .actions, .skip, .btn { display: none !important; }
  .app { display: block; } .main { padding: 0; }
  .card { box-shadow: none; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
details > summary.btn-link { display: inline; list-style: none; }
