:root {
  --green-900: #14331f;
  --green-700: #1f6b3b;
  --green-600: #2e8b57;
  --green-500: #3aa564;
  --green-100: #e6f4ec;
  --green-50: #f2faf5;
  --ink: #1a2230;
  --ink-soft: #46505f;
  --muted: #6b7686;
  --line: #e4e8ee;
  --bg: #f6f8fa;
  --white: #ffffff;
  --amber-100: #fef3c7;
  --amber-700: #b45309;
  --red-100: #fde8e8;
  --red-600: #d64545;
  --blue-100: #e6f0fb;
  --blue-700: #1d4ed8;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 18px 40px rgba(16, 24, 40, 0.16);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 .25rem; }
h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }

.muted { color: var(--muted); }
.link { color: var(--green-700); font-weight: 600; font-size: .9rem; }
code { background: var(--green-50); padding: .1rem .35rem; border-radius: 6px; font-size: .85em; }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  flex: 1;
}
.container.narrow { max-width: 800px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: .7rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand { display: flex; align-items: center; gap: .65rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--green-600), var(--green-700));
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: .95rem; letter-spacing: .03em;
  box-shadow: var(--shadow-sm);
}
.brand-mark-lg { width: 56px; height: 56px; font-size: 1.35rem; border-radius: 14px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: .98rem; }
.brand-text small { color: var(--muted); font-size: .76rem; }

.topnav { display: flex; gap: .35rem; margin-left: .5rem; flex: 1; }
.topnav a {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: .9rem;
  padding: .45rem .7rem;
  border-radius: 8px;
}
.topnav a:hover { background: var(--green-50); color: var(--green-700); text-decoration: none; }

.nav-toggle {
  display: none;
  margin-left: auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-shrink: 0;
}
.nav-toggle:hover { background: var(--green-50); border-color: var(--green-100); }
.nav-toggle-bar {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink-soft);
  transition: transform .2s ease, opacity .2s ease;
}
.topbar.is-nav-open .nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.topbar.is-nav-open .nav-toggle-bar:nth-child(2) { opacity: 0; }
.topbar.is-nav-open .nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .35);
  z-index: 40;
  pointer-events: none;
}
.topbar.is-nav-open .nav-backdrop {
  display: block;
  pointer-events: auto;
}
.topbar.is-nav-open .topbar-inner {
  position: relative;
  z-index: 51;
  background: var(--white);
}

.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .75rem; flex-shrink: 0; }
.user-chip { display: flex; align-items: center; gap: .5rem; }
.user-name { font-weight: 600; font-size: .9rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-dept {
  background: var(--green-100); color: var(--green-700);
  font-weight: 700; font-size: .72rem;
  padding: .12rem .45rem; border-radius: 999px;
}
.logout-form { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem;
  font-family: inherit; font-weight: 600; font-size: .92rem;
  padding: .6rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: .38rem .7rem; font-size: .83rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--green-600); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--green-700); }
.btn-ghost { background: var(--white); color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--green-50); color: var(--green-700); border-color: var(--green-100); }
.btn-danger-ghost { background: transparent; color: var(--red-600); border-color: transparent; }
.btn-danger-ghost:hover { background: var(--red-100); }

/* ---------- Auth ---------- */
.auth-wrap {
  flex: 1;
  display: grid; place-items: center;
  padding: 2rem 1.25rem;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--green-100), transparent),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 2.25rem 2rem;
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand .brand-mark-lg { margin: 0 auto .9rem; }
.auth-brand h1 { font-size: 1.35rem; }
.auth-sub { color: var(--muted); font-size: .9rem; margin: .15rem 0 0; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-help { font-size: .82rem; color: var(--muted); margin-top: 1.25rem; text-align: center; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: .35rem; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.field-hint { font-size: .78rem; color: var(--muted); }
.field input, .field textarea, .field select, .select-sm, input[type="search"] {
  font-family: inherit; font-size: .95rem; color: var(--ink);
  padding: .65rem .8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus, input[type="search"]:focus {
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px var(--green-100);
}
textarea { resize: vertical; }
.inline-field { flex-direction: column; }

/* ---------- Alerts ---------- */
.alert { padding: .8rem 1rem; border-radius: 10px; font-size: .9rem; margin-bottom: 1rem; }
.alert-error { background: var(--red-100); color: var(--red-600); }
.alert-info { background: var(--blue-100); color: var(--blue-700); }
.alert a { color: inherit; text-decoration: underline; }

/* ---------- Search ---------- */
.searchbox { min-width: 260px; flex: 0 1 340px; }

/* ---------- Chapters / article grid ---------- */
.chapter { margin-bottom: 2.25rem; }
.chapter-title {
  font-size: .92rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--green-700); font-weight: 700;
  padding-bottom: .5rem; margin-bottom: 1rem;
  border-bottom: 2px solid var(--green-100);
}
.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: .85rem;
}
.article-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex; flex-direction: column; gap: .55rem;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s;
}
.article-card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--green-100);
}
.article-card-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.article-num { font-weight: 800; color: var(--green-700); font-size: .9rem; }
.article-num-lg { font-size: 1.15rem; }
.article-detail-title { display: block; line-height: 1.3; max-width: 100%; }
.article-detail-head { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; }
.article-snippet { margin: 0; font-size: .88rem; color: var(--ink-soft); }
.pill {
  font-size: .72rem; font-weight: 700;
  padding: .15rem .5rem; border-radius: 999px;
  background: var(--green-100); color: var(--green-700);
  white-space: nowrap;
}
.no-results { text-align: center; color: var(--muted); padding: 2rem; }

/* ---------- Article detail ---------- */
.breadcrumb {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.25rem; font-size: .88rem;
}
.crumb-cap { color: var(--muted); }
.article-detail {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
}
.article-detail-head { margin-bottom: 1rem; }
.article-text p { margin: 0 0 .85rem; color: var(--ink); }
.article-text p:last-child { margin-bottom: 0; }
.article-pager {
  display: flex; justify-content: space-between; gap: 1rem;
  margin: 1.25rem 0 2rem;
}

/* ---------- Comments ---------- */
.comments { margin-top: 1rem; }
.comments h2 { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.count-badge {
  background: var(--green-600); color: #fff;
  font-size: .8rem; font-weight: 700;
  padding: .05rem .55rem; border-radius: 999px;
}
.comment-form {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.comment-form-actions { margin-top: .85rem; display: flex; justify-content: flex-end; }

.comment-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .85rem; }
.comment {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}
.comment-mine { border-color: var(--green-500); background: var(--green-50); }
.comment-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .45rem; }
.comment-author { font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.comment-dept {
  background: var(--green-100); color: var(--green-700);
  font-weight: 700; font-size: .7rem; padding: .1rem .45rem; border-radius: 999px;
}
.comment-date { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.comment-text { margin: 0; color: var(--ink); white-space: pre-wrap; }
.comment-actions { display: flex; gap: .5rem; margin-top: .6rem; align-items: center; }
.comment-edit-form:not([hidden]) { margin-top: .75rem; display: flex; flex-direction: column; gap: .6rem; }
.inline { display: inline; margin: 0; }

.badge { font-size: .68rem; font-weight: 700; padding: .1rem .45rem; border-radius: 999px; }
.badge-mine { background: var(--green-600); color: #fff; }
.badge-admin { background: var(--ink); color: #fff; }

/* ---------- My comments ---------- */
.my-comments { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .85rem; }
.my-comment {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.15rem;
}
.my-comment-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.my-comment-foot { display: flex; align-items: center; justify-content: space-between; margin-top: .7rem; }

/* ---------- Status pills ---------- */
.status { font-size: .74rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; text-transform: capitalize; }
.status-nuevo { background: var(--blue-100); color: var(--blue-700); }
.status-revisado { background: var(--amber-100); color: var(--amber-700); }
.status-aceptado { background: var(--green-100); color: var(--green-700); }
.status-rechazado { background: var(--red-100); color: var(--red-600); }

/* ---------- Stats ---------- */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem; margin-bottom: 1.75rem;
}
.stat-card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem 1.35rem;
  display: flex; flex-direction: column; gap: .15rem;
  box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 1.9rem; font-weight: 800; color: var(--green-700); letter-spacing: -0.02em; }
.stat-label { font-size: .82rem; color: var(--muted); font-weight: 600; }

/* ---------- Dashboard ---------- */
.dashboard-cols {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}
.dashboard-cols > .panel { min-width: 0; }
.panel {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.35rem; box-shadow: var(--shadow-sm);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.panel-head h2 { font-size: 1.05rem; }
.panel-head .muted { font-size: .8rem; }

.ranking { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .65rem; counter-reset: rank; }
.ranking-row { display: flex; align-items: center; gap: .85rem; padding: .65rem; border-radius: var(--radius-sm); transition: background .12s; }
.ranking-row:hover { background: var(--green-50); }
.ranking-pos { font-weight: 800; color: var(--muted); font-size: .85rem; min-width: 28px; }
.ranking-main { flex: 1; min-width: 0; }
.ranking-art { font-weight: 700; color: var(--ink); display: block; font-size: .95rem; }
.ranking-art:hover { color: var(--green-700); }
.ranking-snippet { display: block; font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; background: var(--green-100); border-radius: 999px; margin-top: .4rem; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--green-500), var(--green-700)); border-radius: 999px; }
.ranking-count { text-align: center; color: var(--ink); display: flex; flex-direction: column; line-height: 1.1; min-width: 70px; }
.ranking-count strong { font-size: 1.15rem; color: var(--green-700); }
.ranking-count small { font-size: .68rem; color: var(--muted); }
.ranking-count:hover { text-decoration: none; }

.recent-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .8rem; }
.recent-item { padding-bottom: .8rem; border-bottom: 1px solid var(--line); }
.recent-item:last-child { border-bottom: none; padding-bottom: 0; }
.recent-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: .3rem; }
.recent-text { margin: 0 0 .35rem; font-size: .88rem; color: var(--ink-soft); }
.recent-meta { display: flex; gap: .4rem; align-items: center; font-size: .78rem; color: var(--muted); flex-wrap: wrap; }
.recent-meta .dot { opacity: .5; }

/* ---------- Tables ---------- */
.filters { display: flex; gap: .75rem; align-items: flex-end; margin-bottom: 1.25rem; flex-wrap: wrap; background: var(--white); padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); }
.filters .field { min-width: 140px; }
.table-wrap { overflow-x: auto; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table thead th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .8rem 1rem; border-bottom: 1px solid var(--line); background: var(--green-50); }
.table tbody td { padding: .8rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--green-50); }
.cell-user { display: flex; flex-direction: column; gap: .15rem; }
.cell-user .comment-dept { width: fit-content; }
.cell-comment { max-width: 380px; white-space: pre-wrap; }
.cell-date { white-space: nowrap; color: var(--muted); }
.cell-actions { white-space: nowrap; display: flex; gap: .4rem; align-items: center; }
.select-sm { width: auto; padding: .35rem .5rem; font-size: .82rem; border-radius: 8px; }

/* ---------- PDF viewer ---------- */
.pdf-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.pdf-frame-wrap {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  height: calc(100vh - 230px);
  min-height: 480px;
}
.pdf-object, .pdf-iframe { width: 100%; height: 100%; border: 0; display: block; }
.pdf-fallback { padding: 3rem 1.5rem; text-align: center; }
.pdf-fallback p { color: var(--muted); margin-bottom: 1rem; }

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center; padding: 3rem 1.5rem;
  background: var(--white); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty-state.small { padding: 1.5rem; }
.empty-state h1 { margin-bottom: .5rem; }
.empty-state .btn { margin-top: 1rem; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--white); margin-top: auto; }
.site-footer-inner {
  max-width: 1180px; margin: 0 auto; padding: 1.1rem 1.25rem;
  display: flex; justify-content: space-between; gap: 1rem;
  color: var(--muted); font-size: .82rem; flex-wrap: wrap;
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .dashboard-cols { grid-template-columns: 1fr; }

  .topbar-inner {
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-areas:
      "brand toggle user"
      "nav nav nav";
    gap: .65rem .75rem;
    align-items: center;
  }
  .brand { grid-area: brand; min-width: 0; }
  .nav-toggle {
    display: inline-flex;
    grid-area: toggle;
    margin-left: 0;
  }
  .topbar-user {
    grid-area: user;
    margin-left: 0;
    gap: .5rem;
  }

  .topnav {
    display: none;
    grid-area: nav;
    flex-direction: column;
    gap: .25rem;
    margin: 0;
    padding: .35rem 0 .15rem;
    border-top: 1px solid var(--line);
  }
  .topbar.is-nav-open .topnav { display: flex; }
  .topnav a {
    padding: .75rem .85rem;
    font-size: .95rem;
    border-radius: 10px;
  }

  body.nav-open { overflow: hidden; }
  .user-name { max-width: 90px; }
}
@media (max-width: 560px) {
  .page-head { flex-direction: column; align-items: stretch; }
  .searchbox { flex: 1; }
  .brand-text small { display: none; }
}
