:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --bg-alt: #f1f3f5;
  --sidebar: #17212b;
  --sidebar-text: #d7e0e8;
  --text: #17212b;
  --muted: #687684;
  --border: #dbe1e7;
  --btn-bg: #eef1f4;
  --green: #16734a;   --green-bg: #e8f5ee;   --green-border: #a9d8be;
  --yellow: #8a6200;  --yellow-bg: #fff7df;  --yellow-border: #e7cc83;
  --blue: #175fa8;    --blue-bg: #eaf2fb;    --blue-border: #a9c8e8;
  --orange: #956113;  --orange-bg: #fff5e6;  --orange-border: #e9c58b;
  --red: #b4232f;     --red-bg: #fcebed;     --red-border: #e3a6ad;
  --err: #b4232f;
  --focus: rgba(23, 95, 168, 0.18);
}
[data-theme="dark"] {
  --bg: #111820;
  --surface: #18222c;
  --bg-alt: #202c37;
  --sidebar: #0d151d;
  --sidebar-text: #d7e0e8;
  --text: #e8edf1;
  --muted: #9aa8b4;
  --border: #33414d;
  --btn-bg: #263440;
  --green: #62c58d;   --green-bg: #17372a;   --green-border: #286847;
  --yellow: #e6c45e;  --yellow-bg: #3b3118;  --yellow-border: #836f2b;
  --blue: #78b3eb;    --blue-bg: #172e45;    --blue-border: #315f8d;
  --orange: #e9b86b;  --orange-bg: #3c2e19;  --orange-border: #8a652e;
  --red: #ef8b95;     --red-bg: #3f2026;     --red-border: #8b3d48;
  --err: #ef8b95;
  --focus: rgba(120, 179, 235, 0.25);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}
a { color: var(--blue); }

/* layout */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  gap: 5px;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 14px; font-weight: 650; padding: 2px 10px 26px; letter-spacing: -0.01em; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: #3b82b6; color: #fff; font-size: 10px; letter-spacing: .04em; }
.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.sidebar .nav-item:hover { background: rgba(255,255,255,.08); }
.sidebar .nav-item.active { background: #243b4d; color: #fff; font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .nav-foot { padding: 4px 10px; font-size: 12px; color: var(--muted); }
.main { flex: 1; min-width: 0; overflow-y: auto; padding: 34px 38px 44px; }

/* header de contenido */
.content-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 25px; gap: 16px; flex-wrap: wrap; }
.content-head h1 { font-size: 24px; line-height: 1.2; letter-spacing: -0.03em; margin: 0; }
.page-subtitle { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.content-actions { display: flex; align-items: center; gap: 8px; }
.content-actions button { margin: 0; }

/* botones */
button {
  border-radius: 5px;
  padding: 8px 13px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.small { padding: 5px 9px; font-size: 12px; }
.btn-primary { background: #1d6b9e; color: #fff; }
.btn-primary:hover { background: #185b88; }
.btn-secondary, .btn-theme, .btn-logout { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary:hover, .btn-theme:hover, .btn-logout:hover { background: var(--btn-bg); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }

/* métricas */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 12px; margin-bottom: 10px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 15px 17px;
  box-shadow: 0 1px 2px rgba(19, 34, 48, .04);
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 25px; font-weight: 650; margin-top: 6px; letter-spacing: -0.03em; }
.stat.m-green  { border-top: 3px solid var(--green); }
.stat.m-yellow { border-top: 3px solid var(--yellow); }
.stat.m-blue   { border-top: 3px solid var(--blue); }
.stat.m-orange { border-top: 3px solid var(--orange); }
.stat.m-red    { border-top: 3px solid var(--red); }
.metric-details { display: flex; flex-wrap: wrap; gap: 18px; color: var(--muted); font-size: 12px; margin: 0 0 7px; }
.metric-details strong { color: var(--text); font-weight: 650; margin-right: 3px; }
.last-run { font-size: 12px; color: var(--muted); margin: 0 0 22px; }

/* filtros */
.filters { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filter-bar { padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.filters select, .filters input {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 13px;
}
.filters label { font-size: 12px; color: var(--muted); }

/* tabla y tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; box-shadow: 0 1px 2px rgba(19, 34, 48, .04); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 17px; border-bottom: 1px solid var(--border); background: var(--surface); }
.card-head h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-alt); color: var(--muted); font-weight: 600; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
tbody tr:hover { background: rgba(23, 95, 168, .025); }
td:first-child { min-width: 245px; }
td:nth-child(2) { min-width: 160px; }
td:nth-child(7) { min-width: 250px; }
td:last-child { min-width: 125px; }
tr:last-child td { border-bottom: none; }

.badge { display: inline-block; font-size: 10px; padding: 3px 7px; border-radius: 4px; border: 1px solid var(--border); background: var(--btn-bg); color: var(--text); font-weight: 600; white-space: nowrap; }
/* tipos */
.type-forum, .type-form, .type-latex, .type-pdf_template, .type-email,
.type-presentation, .type-reading, .type-mixed_activity { color: var(--muted); border-color: var(--border); background: var(--bg-alt); }
.type-file_submission { color: var(--muted); }
.type-unknown      { color: var(--muted); }
/* estados documento: verde completado, amarillo pendiente, azul generado, naranja superseded, rojo error */
.st-generated { color: var(--blue);   border-color: var(--blue-border);   background: var(--blue-bg); }
.st-approved  { color: var(--green);  border-color: var(--green-border);  background: var(--green-bg); }
.st-superseded{ color: var(--orange); border-color: var(--orange-border); background: var(--orange-bg); }
.st-discarded { color: var(--red);    border-color: var(--red-border);    background: var(--red-bg); }
.st-failed    { color: var(--red);    border-color: var(--red-border);    background: var(--red-bg); }
/* entrega */
.sub-pendiente { color: var(--yellow); border-color: var(--yellow-border); background: var(--yellow-bg); }
.sub-entregada { color: var(--blue);   border-color: var(--blue-border);   background: var(--blue-bg); }
.sub-calificada{ color: var(--green);  border-color: var(--green-border);  background: var(--green-bg); }

/* documentos compactos */
.docs-list { display: flex; flex-direction: column; gap: 6px; min-width: 235px; }
.doc-line { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; min-height: 24px; }
.doc-version { color: var(--text); font-size: 12px; font-weight: 650; min-width: 29px; }
.doc-links { display: inline-flex; flex-wrap: wrap; gap: 9px; font-size: 11px; }
.doc-links a { text-decoration: none; }
.doc-links a:hover { text-decoration: underline; }
.more-btn { align-self: flex-start; font-size: 11px; padding: 2px 0; background: transparent; color: var(--blue); border: none; }
.more-btn:hover { text-decoration: underline; }

/* acciones de fila */
.row-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.action-menu { position: relative; }
.action-menu summary { list-style: none; cursor: pointer; color: var(--blue); font-size: 12px; font-weight: 600; }
.action-menu summary::-webkit-details-marker { display: none; }
.action-menu summary::after { content: " ▾"; font-size: 10px; color: var(--muted); }
.action-menu[open] summary::after { content: " ▴"; }
.action-menu-panel { position: absolute; z-index: 10; right: 0; top: calc(100% + 7px); width: 220px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(19, 34, 48, .16); }
.action-group { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 3px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.action-group:last-child { border-bottom: none; }
.action-version { grid-column: 1 / -1; color: var(--muted); font-size: 10px; margin-bottom: 3px; }
.action-version .badge { margin-left: 4px; }
.menu-action { padding: 5px 3px; background: transparent; border: none; color: var(--muted); font-size: 11px; text-align: left; }
.menu-action:hover { background: var(--bg-alt); color: var(--text); }
.menu-action.approve:hover { color: var(--green); }
.menu-action.regenerate:hover { color: var(--blue); }
.menu-action.discard:hover { color: var(--red); }
.row-moodle { color: var(--muted); font-size: 11px; }

/* foro como entregable */
.forum-line { font-size: 12px; }

.attachments { color: var(--muted); font-size: 12px; }
.empty { padding: 22px 16px; color: var(--muted); font-size: 13px; }

/* logs */
.logs-panel { height: 100%; }
.logs {
  margin: 0;
  padding: 12px 16px;
  height: calc(100vh - 200px);
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* páginas dedicadas */
.page-wrap { padding: 18px 22px; }
.viewer-embed { width: 100%; height: calc(100vh - 120px); border: 1px solid var(--border); border-radius: 8px; background: var(--bg-alt); }
.doc-msg-wrap { max-width: 860px; }
.doc-msg-wrap textarea, .doc-msg-wrap .msg-box {
  width: 100%; background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  font-size: 14px; line-height: 1.6; font-family: inherit; resize: vertical;
}
.msg-box { min-height: 120px; white-space: pre-wrap; }
.editor-wrap { display: flex; gap: 14px; height: calc(100vh - 130px); }
.editor-pane { flex: 1; display: flex; flex-direction: column; }
.editor-pane textarea {
  flex: 1; width: 100%; resize: none;
  background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5;
}
.preview-pane { flex: 1; }
.preview-pane iframe { width: 100%; height: 100%; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.editor-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.compile-status { font-size: 12px; color: var(--muted); }
.compile-status.err { color: var(--red); }
.compile-status.ok { color: var(--green); }

/* toast */
.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25); z-index: 50;
}
.hidden { display: none !important; }

@media (max-width: 900px) {
  .sidebar { width: 188px; }
  .main { padding: 26px 20px 34px; }
  .metrics { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .editor-wrap { flex-direction: column; }
}

@media (max-width: 620px) {
  .app { display: block; height: auto; min-height: 100vh; }
  .sidebar { width: 100%; height: auto; display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  .sidebar .brand { flex: 1 0 100%; padding: 0 0 10px; }
  .sidebar .nav-item { width: auto; padding: 8px 9px; }
  .sidebar .spacer { display: none; }
  .main { padding: 22px 12px 30px; }
  .content-head { margin-bottom: 18px; }
  .content-actions { width: 100%; }
  .content-actions button { flex: 1; }
  .metrics { gap: 8px; }
  .stat { padding: 12px; }
  .filter-bar { align-items: stretch; }
  .filters label { display: flex; flex-direction: column; gap: 4px; flex: 1 1 130px; }
  .filters input, .filters select { width: 100%; }
  th, td { padding: 11px 10px; }
  .action-menu-panel { position: fixed; right: 12px; top: auto; }
}
