:root {
  --brand: #d9791a;
  --brand-dark: #a85a0c;
  --brand-soft: #fbeedd;
  --ochre: #b8872b;
  --bg: #f7f4ef;
  --card: #ffffff;
  --text: #2b2320;
  --muted: #7a7168;
  --border: #e7e0d8;
  --ok: #2e7d32;
  --ok-soft: #e6f4ea;
  --warn: #a8700a;
  --warn-soft: #fff1d6;
  --danger: #c62828;
  --danger-soft: #fde8e8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

a { color: var(--brand-dark); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px 28px; width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.06); text-align: center;
}
.login-card img.logo { max-width: 240px; width: 100%; margin-bottom: 20px; }
.login-card h1 { font-size: 17px; margin: 0 0 22px; color: var(--muted); font-weight: 500; }
.login-card .by { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* ---------- Formularios y botones ---------- */
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 16px; font-family: inherit; background: #fff; margin-bottom: 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label.field { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
button, .btn {
  cursor: pointer; border: none; border-radius: 8px; background: var(--brand); color: #fff;
  padding: 10px 16px; font-size: 14px; font-weight: 600; text-decoration: none; display: inline-block; font-family: inherit;
}
button:hover, .btn:hover { background: var(--brand-dark); }
button:disabled { opacity: .55; cursor: wait; }
.btn.secondary, button.secondary { background: #fff; color: var(--brand-dark); border: 1px solid var(--brand); }
.btn.secondary:hover, button.secondary:hover { background: var(--brand-soft); }
.btn.danger, button.danger { background: #fff; color: var(--danger); border: 1px solid var(--danger); }
.btn.danger:hover, button.danger:hover { background: var(--danger-soft); }
.btn.small, button.small { padding: 6px 11px; font-size: 13px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.login-card button[type=submit] { width: 100%; padding: 12px; font-size: 16px; }

/* ---------- Estructura ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 24px; background: #fff;
  border-bottom: 3px solid var(--brand); position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.topbar img.logo { height: 38px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: 8px;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--brand-soft); color: var(--brand-dark); }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }

.container { max-width: 1100px; margin: 0 auto; padding: 22px 16px 60px; }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title h1 { font-size: 22px; margin: 0; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { text-decoration: none; }
.lead { color: var(--muted); margin: 0 0 18px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* ---------- Tarjetas de inicio ---------- */
.tile {
  display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-left: 6px solid var(--brand);
  border-radius: 14px; padding: 20px; min-height: 150px; transition: box-shadow .15s, transform .15s;
}
.tile:hover { box-shadow: 0 6px 18px rgba(217,121,26,.18); transform: translateY(-2px); }
.tile .icon { font-size: 34px; line-height: 1; }
.tile .name { font-size: 18px; font-weight: 700; }
.tile .count { color: var(--muted); font-size: 14px; }
.tile .alerts { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; min-height: 24px; }
.tile.add { border-style: dashed; background: transparent; align-items: center; justify-content: center; text-align: center; color: var(--brand-dark); cursor: pointer; font: inherit; font-weight: 700; }

/* ---------- Badges / semaforo ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.por_vencer { background: var(--warn-soft); color: var(--warn); }
.badge.vigente { background: var(--ok-soft); color: var(--ok); }
.badge.vencido { background: var(--danger-soft); color: var(--danger); }
.badge.sin_vencimiento, .badge.neutral { background: #eee9e3; color: var(--muted); }

/* ---------- Filtros y listas ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip:hover { background: var(--brand-soft); }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.doc { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.doc:last-child { border-bottom: none; }
.doc .info { flex: 1; min-width: 220px; }
.doc .title { font-weight: 700; font-size: 16px; word-break: break-word; }
.doc .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.doc .actions { display: flex; gap: 6px; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table-wrap { overflow-x: auto; }

/* ---------- Modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(30,20,10,.5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 460px; max-height: 92vh; overflow-y: auto; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal .hint { font-size: 13px; color: var(--muted); margin: -4px 0 12px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2b2320; color: #fff;
  padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 60; max-width: 90vw;
}
.toast.err { background: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar img.logo { height: 32px; }
  .nav { order: 3; flex-basis: 100%; gap: 2px; }
  .nav a { padding: 6px 10px; font-size: 13px; }
  .who { margin-left: auto; }
  .grid.tiles { grid-template-columns: 1fr; }
  .tile { min-height: 0; }
  .doc .actions { width: 100%; }
  .doc .actions .btn, .doc .actions button { flex: 1; text-align: center; }
}

/* ---------- Logo (JPG cuadrado con fondo oscuro) ---------- */
img.logo { border-radius: 10px; }
.login-card img.logo { max-width: 220px; border-radius: 14px; }
.login-wrap { background: #33332e; }
.login-card { border: none; }
