:root {
  --bg: #f4f6f8; --surface: #fff; --text: #17202a; --muted: #64707d; --line: #e3e7ec;
  --brand: #0f766e; --brand-2: #115e59; --brand-soft: #e6f4f2;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2;
  --bad: #b91c1c; --bad-soft: #fdecec; --info: #1d4ed8; --info-soft: #e8efff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Estructura */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #0b1f1d; color: #cfe3e0; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; padding: .25rem .5rem 1rem; display: block; }
.sidebar nav a { display: flex; gap: .6rem; align-items: center; color: #cfe3e0; padding: .5rem .6rem; border-radius: 8px; margin-bottom: 2px; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar .section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #7fa7a1; margin: 1rem .6rem .35rem; }
.sidebar .me { border-top: 1px solid rgba(255,255,255,.1); margin-top: 1rem; padding: .75rem .6rem 0; font-size: .85rem; }
.sidebar .me button { background: none; border: 0; color: #9fd0c9; padding: 0; cursor: pointer; font: inherit; }
.main { padding: 1.5rem 2rem 3rem; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn.menu-toggle { display: none; }
@media (min-width: 901px) { .app { background: linear-gradient(90deg, #0b1f1d 240px, var(--bg) 240px); } }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  body.menu-open .sidebar { transform: none; }
  .btn.menu-toggle { display: inline-flex; }
  .main { padding: 1rem; }
}

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 1rem 1.2rem 0; }
.grid { display: grid; gap: 1rem; }
.grid.k4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
@media (max-width: 500px) { .grid.k4 { grid-template-columns: 1fr 1fr; gap: .6rem; } .kpi .value { font-size: 1.15rem; } }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.kpi.pos .value { color: var(--ok); } .kpi.neg .value { color: var(--bad); }

.btn { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .5rem .85rem; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none !important; line-height: 1.2; }
.btn:hover { background: #f1f4f6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: .3rem .6rem; font-size: .85rem; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 0; }
form.inline { display: inline; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: #fafcfc; }
.table-wrap { overflow-x: auto; }
tfoot td { font-weight: 700; background: #fafbfc; }

.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; background: #eef1f4; color: #3b4652; }
.badge.PAID, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.PARTIAL, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.PENDING, .badge.info { background: var(--info-soft); color: var(--info); }
.badge.OVERDUE, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.CANCELLED { text-decoration: line-through; }
.badge.CASH { background: #f0fdf4; color: #166534; } .badge.TRANSFER { background: #eff6ff; color: #1e40af; } .badge.PAYPAL { background: #fef9c3; color: #854d0e; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.success { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cb; }
.flash.error { background: var(--bad-soft); color: var(--bad); border-color: #f5c2c2; }
.flash.info { background: var(--info-soft); color: var(--info); border-color: #c7d6fb; }

/* Formularios */
.form { max-width: 820px; }
.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem 1rem; margin-bottom: .9rem; }
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .3rem; }
label .opt { color: var(--muted); font-weight: 400; }
input, select, textarea { width: 100%; font: inherit; padding: .55rem .7rem; border: 1px solid #cfd6dd; border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #99d5cd; border-color: var(--brand); }
input[type=checkbox] { width: auto; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
textarea { min-height: 80px; resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem .25rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .4rem; }
.form-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: 1rem; }
.filters > div { min-width: 150px; }
.filters label { font-size: .8rem; color: var(--muted); }

.dl { display: grid; grid-template-columns: 170px 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); } .dl dd { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.chart-box { position: relative; height: 280px; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs a.active { border-color: var(--brand); color: var(--text); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: middle; }

/* Páginas de acceso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(135deg, #0b1f1d, #0f766e); }
.auth .card { width: 100%; max-width: 440px; padding: 1.75rem; }
.auth .card.wide { max-width: 720px; }
.auth h1 { margin-bottom: .25rem; }
.auth .field { margin-bottom: .9rem; }
.auth .links { display: flex; justify-content: space-between; margin-top: 1rem; font-size: .9rem; }

#calendar { background: var(--surface); padding: 1rem; border-radius: var(--radius); border: 1px solid var(--line); }
.fc .fc-event { cursor: pointer; font-size: .78rem; }
.fc .fc-toolbar-title { font-size: 1.3rem; }
.fc a { color: inherit; }

/* Plan de pago */
.plan-table { width: auto; min-width: 320px; }
.plan-table th, .plan-table td { padding: .3rem .4rem; border: 0; background: none; }
.plan-table td.n { color: var(--muted); width: 2rem; }
.plan-table input { width: 120px; }
.plan-summary { margin: .75rem 0 .9rem; padding: .6rem .8rem; background: var(--brand-soft); border-radius: 8px; font-size: .92rem; }
.plan-summary:empty { display: none; }
.plan-summary .pos { color: var(--ok); font-weight: 600; } .plan-summary .neg { color: var(--bad); font-weight: 600; }
[hidden] { display: none !important; }

/* Contratos y facturas */
.doc-editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
@media (max-width: 1000px) { .doc-editor { grid-template-columns: 1fr; } }
.doc-source { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-height: 420px; }
.var-list { display: grid; gap: .25rem; max-height: 420px; overflow: auto; }
.var-list code { user-select: all; }
.doc-paper { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 1.5rem 2rem; max-width: 820px; max-height: 600px; overflow: auto; }
.doc-paper h1 { text-align: center; font-size: 1.4rem; } .doc-paper h3 { text-align: center; font-weight: 400; }
.doc-paper h2 { font-size: 1.05rem; margin: 1rem 0 .3rem; } .doc-paper p { margin: .2rem 0; }
.doc-paper .doc-table { border-collapse: collapse; width: 100%; margin: .5rem 0; } .doc-paper .doc-table td { border: 1px solid var(--line); padding: .3rem .5rem; }
.doc-paper .signature-line { border-bottom: 1px solid #333; width: 55%; height: 2.4rem; }
.doc-paper .page-break { border-top: 2px dashed var(--line); margin: 1rem 0; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { text-align: left; font-size: .8rem; color: var(--muted); padding: .25rem; }
.items-table td { padding: .25rem; }
.items-table input { width: 100%; }
.upload-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; padding: 1rem 1.2rem; border-top: 1px solid var(--line); }
.upload-form > div { display: grid; gap: .2rem; }
.upload-form label { font-size: .8rem; color: var(--muted); }

.signed-contracts { margin-top: .7rem; padding: .6rem .7rem; background: #f7f9fb; border: 1px solid var(--line); border-radius: 8px; }
.signed-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .35rem; }
.signed-upload { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-top: .4rem; }
.signed-upload input[type=file] { max-width: 230px; font-size: .85rem; }
.notice { background: var(--info-soft); color: var(--info); border-radius: 8px; padding: .6rem .8rem; }
.radio-row { display: flex; gap: 1.2rem; flex-wrap: wrap; }
[hidden] { display: none !important; }
.radio-row .check { display: inline-flex; align-items: center; gap: .4rem; width: auto; margin: 0; } .radio-row input { width: auto; }

.master-lease { border: 1px solid var(--line); border-radius: 10px; padding: .9rem 1rem; margin-bottom: .8rem; }
.inline-details { display: inline-block; position: relative; }
.inline-details > summary { list-style: none; cursor: pointer; }
.inline-details > summary::-webkit-details-marker { display: none; }
.file-btn { cursor: pointer; position: relative; }
.file-btn input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.proofs { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; margin-top: .3rem; }
.proof { position: relative; display: inline-flex; }
.proof img { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.proof .pdf { width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: .75rem; }
.proof form { position: absolute; top: -6px; right: -6px; }
.proof form button { width: 18px; height: 18px; padding: 0; border-radius: 50%; font-size: .65rem; line-height: 1; }
.deposit-box { margin-top: .7rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; }
.pay-form { display: inline-flex; gap: .3rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pay-form input[type=date], .pay-form select { width: auto; padding: .2rem .4rem; }
.right .proofs { justify-content: flex-end; }
dialog.viewer { width: min(1100px, 96vw); height: 92vh; max-height: 92vh; padding: 0; border: 0; border-radius: 12px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog.viewer[open] { display: flex; flex-direction: column; }
dialog.viewer::backdrop { background: rgba(10, 20, 25, .6); }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--line); background: #fff; flex-wrap: wrap; }
.viewer-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.viewer-actions { display: flex; gap: .35rem; }
.viewer-body { flex: 1; min-height: 0; background: #2b2f33; display: flex; align-items: center; justify-content: center; overflow: auto; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-body > div { color: #fff; }
.new-company { background: #f7f9fb; border: 1px dashed var(--line); border-radius: 8px; padding: .6rem .7rem; }
