/* Buzón de facturas — hoja de estilo única, sin dependencias externas (CSP). */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --border: #e4e8ee;
  --border-strong: #d0d7e0;

  --text: #16202c;
  --text-soft: #5a6675;
  --text-faint: #8a94a3;

  --brand: #1155ff;
  --brand-soft: #eaf0ff;
  --brand-ink: #0b3fbf;

  --green: #10794a;
  --green-bg: #e4f5ec;
  --amber: #8a5b00;
  --amber-bg: #fdf1d8;
  --red: #b3251f;
  --red-bg: #fceceb;
  --slate: #5a6675;
  --slate-bg: #eef1f5;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 26, 40, 0.05), 0 4px 12px rgba(16, 26, 40, 0.04);
  --shadow-lift: 0 2px 4px rgba(16, 26, 40, 0.06), 0 12px 28px rgba(16, 26, 40, 0.09);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #171d26;
    --surface-2: #1c232e;
    --border: #262f3c;
    --border-strong: #35404f;

    --text: #e8edf4;
    --text-soft: #a3aebd;
    --text-faint: #78838f;

    --brand: #6b9bff;
    --brand-soft: #1a2540;
    --brand-ink: #a9c4ff;

    --green: #6ddba0;
    --green-bg: #122c20;
    --amber: #f0c368;
    --amber-bg: #2e2412;
    --red: #ff8b83;
    --red-bg: #331917;
    --slate: #a3aebd;
    --slate-bg: #222b37;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 12px 28px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Barra superior ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand svg { color: var(--brand); }

.topbar nav { display: flex; align-items: center; gap: 0.3rem; }

.navlink {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-weight: 500;
}
.navlink:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.navlink.is-active { background: var(--brand-soft); color: var(--brand-ink); }

.user-chip {
  margin-left: 0.5rem;
  padding-left: 0.9rem;
  border-left: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.85rem;
}

main { max-width: 1120px; margin: 1.75rem auto 4rem; padding: 0 1.5rem; }

/* ---------- Tipografía ---------- */

h1 {
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

h2 {
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 1.75rem 0 0.6rem;
}

.page-head { margin-bottom: 1.25rem; }
.page-head p { margin: 0; color: var(--text-soft); }

.muted { color: var(--text-soft); }
.faint { color: var(--text-faint); }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 0.85em; }

/* ---------- Avisos ---------- */

.flash {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  border: 1px solid transparent;
  animation: slide-in 0.25s ease;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.flash svg { flex-shrink: 0; margin-top: 2px; }
.flash-ok { background: var(--green-bg); color: var(--green); border-color: color-mix(in srgb, var(--green) 22%, transparent); }
.flash-error { background: var(--red-bg); color: var(--red); border-color: color-mix(in srgb, var(--red) 22%, transparent); }
.flash-info { background: var(--brand-soft); color: var(--brand-ink); border-color: color-mix(in srgb, var(--brand) 22%, transparent); }
.flash-warn { background: var(--amber-bg); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 25%, transparent); }

/* ---------- Tarjetas de resumen ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
a.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); text-decoration: none; }
.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--border-strong);
}
.card-num {
  display: block;
  font-size: 1.75rem;
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.card-label { color: var(--text-soft); font-size: 0.87rem; }
.card-red::before { background: var(--red); }
.card-red .card-num { color: var(--red); }
.card-amber::before { background: var(--amber); }
.card-amber .card-num { color: var(--amber); }
.card-slate::before { background: var(--slate); }
.card-slate .card-num { color: var(--slate); }
.card-brand::before { background: var(--brand); }

/* ---------- Formularios y botones ---------- */

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.inline-form { display: inline-flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0 0 1.25rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

input, select, button, textarea {
  font: inherit;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder { color: var(--text-faint); }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
input[type="file"] { border-style: dashed; cursor: pointer; padding: 0.4rem 0.6rem; }
input[type="date"] { color-scheme: light dark; }

.field { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--text-soft); font-size: 0.88rem; }

button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--brand);
  color: #fff;
  border-color: transparent;
  font-weight: 550;
  cursor: pointer;
}
button:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
button:active { transform: translateY(1px); }

.btn-ghost {
  background: var(--surface);
  color: var(--text-soft);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--red); }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 85%, #000); }

.btn-danger-ghost {
  background: transparent;
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 35%, transparent);
}
.btn-danger-ghost:hover { background: var(--red-bg); }

.btn-sm { padding: 0.3rem 0.55rem; font-size: 0.85rem; }
.btn-icon { padding: 0.35rem; border-radius: var(--radius-sm); }

/* ---------- Tabla ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-faint);
  font-size: 0.74rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td { padding: 0.7rem 0.9rem; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--surface-2); }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-actions { width: 1%; white-space: nowrap; }

.doc-link { font-weight: 600; white-space: nowrap; }
.supplier { display: block; max-width: 22ch; }
.supplier small { display: block; color: var(--text-faint); font-size: 0.78rem; }

/* ---------- Píldoras de estado ---------- */

.badge, .chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 550;
  white-space: nowrap;
}
.badge { background: var(--slate-bg); color: var(--slate); }

.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.chip-green { background: var(--green-bg); color: var(--green); }
.chip-yellow { background: var(--amber-bg); color: var(--amber); }
.chip-red { background: var(--red-bg); color: var(--red); font-weight: 650; }
.chip-expired { background: var(--slate-bg); color: var(--slate); }
.chip-red::before { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.deadline-note { display: block; font-size: 0.76rem; color: var(--text-faint); margin-top: 0.15rem; }

/* ---------- Estado vacío ---------- */

.empty {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
}
.empty svg { color: var(--text-faint); margin-bottom: 0.75rem; }
.empty h3 { margin: 0 0 0.4rem; font-size: 1.05rem; font-weight: 600; }
.empty p { margin: 0.2rem 0; color: var(--text-soft); }

/* ---------- Paginación ---------- */

.pager {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  color: var(--text-soft);
  font-size: 0.9rem;
}

/* ---------- Autenticación ---------- */

.auth-card {
  max-width: 400px;
  margin: 3.5rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow-lift);
}
.auth-card h1 { margin-bottom: 0.25rem; }
.auth-card .sub { color: var(--text-soft); margin: 0 0 1.5rem; }
.auth-card form { display: flex; flex-direction: column; gap: 0.9rem; }
.auth-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.88rem; font-weight: 500; }
.auth-card button { justify-content: center; padding: 0.6rem; margin-top: 0.3rem; }
.auth-foot { text-align: center; margin: 1.25rem 0 0; color: var(--text-soft); font-size: 0.9rem; }

/* ---------- Detalle de factura ---------- */

.detail-head {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.detail-head h1 { margin: 0; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-soft);
  font-size: 0.9rem;
  margin-bottom: 0.9rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
}
.detail-grid h2 { margin-top: 1.1rem; }
.detail-grid p { margin: 0; }

.kv { display: flex; justify-content: space-between; gap: 1rem; padding: 0.22rem 0; }
.kv dt { color: var(--text-soft); }
.kv dd { margin: 0; text-align: right; }
.total-row { border-top: 1px solid var(--border); margin-top: 0.4rem; padding-top: 0.5rem; font-weight: 650; }

.actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin: 1.25rem 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.actions-spacer { flex: 1; }

/* ---------- Confirmación destructiva ---------- */

.confirm-card {
  max-width: 560px;
  margin: 2.5rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow-lift);
}
.confirm-card h1 { margin-bottom: 0.5rem; }
.confirm-card .summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem;
  margin: 1.1rem 0;
}
.confirm-actions { display: flex; gap: 0.7rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ---------- Responsive ---------- */

/* Por debajo de este ancho la tabla no cabe completa: se ocultan las columnas
   secundarias (el dato sigue en el detalle de la factura). */
@media (max-width: 940px) {
  .hide-sm { display: none; }
  .supplier { max-width: 18ch; }
}

@media (max-width: 760px) {
  main { padding: 0 1rem; margin-top: 1.1rem; }
  .topbar { padding: 0.6rem 1rem; }
  .user-chip { display: none; }
  .navlink { padding: 0.35rem 0.55rem; font-size: 0.92rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .inline-form { justify-content: space-between; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
  .card-num { font-size: 1.45rem; }
  thead th, tbody td { padding: 0.55rem; }
  .deadline-note { display: none; }
  .auth-card, .confirm-card { margin: 1.5rem auto; padding: 1.5rem; }
}
