/* ContaJosep: verde azulado (el del logo) y un toque cálido. */
:root {
  --bg: #f5f3ee;
  --surface: #fff;
  --surface-2: #faf9f6;
  --text: #1c2724;
  --muted: #66736f;
  --line: #e6e2d9;
  --accent: #0f6b5f;
  --accent-hover: #0b5a50;
  --accent-soft: #e2f1ed;
  --accent-text: #fff;
  --warm: #e8963a;
  --side-bg: #0d3f39;
  --side-text: #c9e3dd;
  --side-active: #ffffff;
  --ok: #157f3c;
  --ok-bg: #e5f5ea;
  --warn: #8a5a00;
  --warn-bg: #fff3d9;
  --error: #b42318;
  --error-bg: #fdecea;
  --shadow: 0 1px 2px rgba(28, 39, 36, .05), 0 4px 14px rgba(28, 39, 36, .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614;
    --surface: #18211e;
    --surface-2: #1d2724;
    --text: #e6ece9;
    --muted: #93a39e;
    --line: #2a3632;
    --accent: #4cc3ad;
    --accent-hover: #6fd3c0;
    --accent-soft: #173a34;
    --accent-text: #08201c;
    --warm: #f2ab5c;
    --side-bg: #0b1311;
    --side-text: #9fbdb6;
    --side-active: #ffffff;
    --ok: #6fd391;
    --ok-bg: #173323;
    --warn: #f2c35b;
    --warn-bg: #3a2e12;
    --error: #ff8a80;
    --error-bg: #3d1a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
main { width: 100%; max-width: 1120px; margin: 0 auto; padding: 32px 28px 72px; min-width: 0; }
h1 { font-size: 26px; line-height: 1.2; letter-spacing: -.02em; margin: 0 0 18px; }
h2 { font-size: 17px; letter-spacing: -.01em; margin: 32px 0 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Barra lateral (escritorio) / barra superior (móvil) */
body.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.top {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  padding: 22px 14px; background: var(--side-bg); color: var(--side-text);
}
.top .brand {
  display: flex; align-items: center; gap: 10px; padding: 0 8px 22px;
  color: #fff; text-decoration: none; font-size: 19px; letter-spacing: -.01em;
}
.top .brand img { display: block; border-radius: 9px; }
.top .brand b { color: #7fe0cd; font-weight: 700; }
.top nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.top nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: 9px; text-decoration: none; color: var(--side-text);
  font-weight: 500; transition: background .15s, color .15s;
}
.top nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.top nav a[aria-current] { background: rgba(255, 255, 255, .12); color: var(--side-active); font-weight: 600; box-shadow: inset 3px 0 0 var(--warm); }
.icon { width: 19px; height: 19px; flex: none; }
.top .logout { padding: 12px 12px 0; border-top: 1px solid rgba(255, 255, 255, .1); }
.top .logout button.link { color: var(--side-text); text-decoration: none; }
.top .logout button.link:hover { color: #fff; }

.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.head h1 { margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.head + * { margin-top: 20px; }

button, .button {
  font: inherit; font-weight: 500; padding: 8px 16px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  text-decoration: none; display: inline-block; line-height: 1.4;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
button:hover, .button:hover { border-color: var(--muted); color: var(--text); }
button.primary, .button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
  box-shadow: 0 1px 2px rgba(15, 107, 95, .25);
}
button.primary:hover, .button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; box-shadow: none; }
.danger, button.link.danger { color: var(--error); }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 14px; }
label small, .small { font-weight: 400; color: var(--muted); font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.grid .wide { grid-column: 1 / -1; }
.grid h2 { margin: 8px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }
.grid h2:first-child { border-top: 0; padding-top: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.filters, .filters-row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; }
.filters label { flex-direction: row; align-items: center; gap: 8px; color: var(--muted); }
.filters select, .filters input { width: auto; }
.tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.tabs a { padding: 5px 12px; border-radius: 7px; text-decoration: none; color: var(--muted); font-weight: 500; }
.tabs a[aria-current] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

table {
  width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tfoot tr:first-child th { border-top: 1px solid var(--line); }
tfoot th { border-bottom: 0; }
thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
tfoot th { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
input.num { text-align: right; }
.neg { color: var(--error); }
tr.muted td { color: var(--muted); }
.row-actions { white-space: nowrap; display: flex; gap: 12px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.kpi {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px 18px 22px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
}
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.kpi:nth-child(2)::before { background: var(--warm); }
.kpi:nth-child(3)::before { background: #3b82c4; }
.kpi:nth-child(4)::before { background: #a77bd8; }
.kpi span { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi strong { font-size: 26px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; background: var(--ok-bg); color: var(--ok); border: 1px solid transparent; }
.flash.error { background: var(--error-bg); color: var(--error); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash a { color: inherit; font-weight: 600; }
.flash ul { margin: 0; padding-left: 18px; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.tag.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.hint { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 28px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.status-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--accent); margin-bottom: 8px; font-weight: 500; }

.lines { margin: 16px 0 8px; box-shadow: none; }
.lines td { padding: 6px; vertical-align: middle; }
.lines tbody tr:hover { background: none; }
.lines td:first-child { width: 45%; }
.totals { display: grid; grid-template-columns: auto auto; justify-content: end; gap: 6px 28px; margin: 14px 0 0; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* Entrada */
body.public {
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(26, 150, 130, .22), transparent 60%),
    radial-gradient(700px 420px at 100% 110%, rgba(232, 150, 58, .16), transparent 60%),
    var(--bg);
}
.login { max-width: 380px; margin: 0 auto; padding-top: 11vh; }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand img { display: block; margin: 0 auto 14px; border-radius: 16px; box-shadow: 0 8px 24px rgba(15, 107, 95, .3); }
.login-brand h1 { font-size: 30px; margin: 0; font-weight: 500; }
.login-brand h1 b { color: var(--accent); font-weight: 750; }
.login-brand p { margin: 6px 0 0; color: var(--muted); }
.login .card { padding: 26px; }
.login button.primary { width: 100%; padding: 10px; margin-top: 4px; }

/* Factura: pensada para imprimir en A4 (Imprimir → Guardar como PDF). */
.invoice {
  background: #fff; color: #1d2430; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 40px; box-shadow: var(--shadow); max-width: 820px; margin: 0 auto; color-scheme: light;
}
.invoice header { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.invoice h1 { font-size: 26px; letter-spacing: 2px; margin: 0 0 6px; text-align: right; }
.invoice h2 { margin: 0 0 6px; font-size: 18px; }
.invoice h3 { font-size: 12px; text-transform: uppercase; color: #667085; margin: 0 0 4px; }
.invoice .meta { text-align: right; }
.invoice .to { margin-bottom: 24px; }
.invoice table { border: 0; border-radius: 0; background: #fff; box-shadow: none; }
.invoice thead th { background: #fff; text-transform: none; letter-spacing: 0; font-size: 13px; }
.invoice tbody tr:hover { background: none; }
.invoice th, .invoice td { border-color: #e3e6eb; color: #1d2430; }
.invoice thead th { color: #667085; }
.invoice .sum { width: auto; margin: 16px 0 0 auto; }
.invoice .sum th { font-weight: 400; text-align: right; color: #667085; }
.invoice .sum .grand th, .invoice .sum .grand td { font-weight: 700; font-size: 18px; color: #1d2430; border-bottom: 0; }
.invoice .notes { margin-top: 24px; }
.invoice footer { margin-top: 32px; font-size: 13px; color: #667085; }

@media print {
  @page { size: A4; margin: 14mm; }
  body, body.app { background: #fff; display: block; }
  .no-print, .top { display: none !important; }
  main { padding: 0; max-width: none; }
  .invoice { border: 0; padding: 0; max-width: none; box-shadow: none; }
}

@media (max-width: 860px) {
  body.app { display: block; }
  .top {
    position: sticky; top: 0; z-index: 10; height: auto;
    flex-direction: row; align-items: center; gap: 8px; padding: 10px 12px;
    flex-wrap: wrap;
  }
  .top .brand { padding: 0 6px 0 2px; font-size: 17px; flex: 1; }
  .top .brand img { width: 30px; height: 30px; }
  .top .logout { border: 0; padding: 0 4px; }
  .top nav {
    order: 3; flex: 1 0 100%; flex-direction: row; overflow-x: auto; gap: 4px;
    scrollbar-width: none; margin: 0 -12px; padding: 2px 12px;
  }
  .top nav::-webkit-scrollbar { display: none; }
  .top nav a { padding: 7px 11px; gap: 7px; white-space: nowrap; font-size: 14px; }
  .top nav a[aria-current] { box-shadow: inset 0 -2px 0 var(--warm); }
  .icon { width: 17px; height: 17px; }
  main { padding: 22px 16px 56px; }
}

@media (max-width: 640px) {
  h1 { font-size: 22px; }
  table { display: block; overflow-x: auto; }
  .kpi strong { font-size: 22px; }
  .invoice { padding: 20px; }
  .invoice header { flex-direction: column; }
  .invoice h1, .invoice .meta { text-align: left; }
}
