:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --border: #e3e5ee;
  --text: #171a2b;
  --text-2: #4a5068;
  --muted: #7c8299;
  --primary: #4f46e5;
  --primary-2: #4338ca;
  --primary-soft: #eceafd;
  --good: #0f8a5f;
  --good-soft: #def5ea;
  --warn: #b26a00;
  --warn-soft: #fdf0d9;
  --bad: #c62f3d;
  --bad-soft: #fde4e6;
  --info: #2563eb;
  --info-soft: #e1ebfd;
  --shadow: 0 1px 2px rgba(16, 20, 40, .05), 0 4px 16px rgba(16, 20, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --surface: #171a2d;
    --surface-2: #1f2338;
    --border: #2b3049;
    --text: #eceef7;
    --text-2: #b9bdd2;
    --muted: #868ca8;
    --primary: #7c74ff;
    --primary-2: #9a94ff;
    --primary-soft: #26254a;
    --good: #3ccf95;
    --good-soft: #143a2d;
    --warn: #f2b047;
    --warn-soft: #3d2f14;
    --bad: #ff6b78;
    --bad-soft: #43202a;
    --info: #6ea2ff;
    --info-soft: #1b2a4a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
a { color: var(--primary); }

/* ---------- Botones e inputs ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
  text-decoration: none;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); background: var(--bad-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); font-size: 18px;
  cursor: pointer; padding: 6px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-2); }
input, select, textarea {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
.error { color: var(--bad); font-size: 14px; margin: 0; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; font-size: 12px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 800; flex: none;
}
.brand-mark.big { width: 48px; height: 48px; font-size: 22px; border-radius: 14px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); text-decoration: none; font-weight: 600;
}
#nav a:hover { background: var(--surface-2); }
#nav a.active { background: var(--primary-soft); color: var(--primary); }
#nav .ico { width: 20px; text-align: center; font-size: 16px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 4px; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 28px; position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
}
.topbar h2 { font-size: 22px; }
.topbar-actions { display: flex; gap: 8px; }
.view { padding: 4px 28px 40px; display: grid; gap: 18px; max-width: 1300px; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { font-size: 16px; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 750; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar input[type="search"] { max-width: 320px; }
.toolbar select { width: auto; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font: inherit;
  font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
td.actions { white-space: nowrap; text-align: right; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--text-2);
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

/* ---------- Progreso bono ---------- */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; display: flex; }
.progress .used { background: var(--primary); }
.progress .reserved { background: color-mix(in srgb, var(--primary) 40%, transparent); margin-left: 2px; }
.bono-card { display: grid; gap: 8px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.bono-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.bono-card .big { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.bono-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* ---------- Listas ---------- */
.list { display: grid; gap: 2px; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; cursor: pointer;
}
.list-item:hover { background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date-chip {
  width: 48px; flex: none; text-align: center; border-radius: 10px; background: var(--primary-soft); color: var(--primary);
  padding: 5px 0; line-height: 1.1;
}
.date-chip b { display: block; font-size: 18px; }
.date-chip span { font-size: 11px; text-transform: uppercase; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; font-size: 13px; background: var(--primary-soft); color: var(--primary);
}

/* ---------- Agenda semanal ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; min-height: 180px; display: flex; flex-direction: column; min-width: 0; }
.day.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.day-head { padding: 10px 10px 8px; display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--border); }
.day-head b { font-size: 15px; }
.day-head small { color: var(--muted); font-weight: 600; text-transform: capitalize; }
.day-body { padding: 8px; display: grid; gap: 6px; align-content: start; flex: 1; }
.day-add { border: 1px dashed var(--border); background: transparent; color: var(--muted); border-radius: 8px; padding: 5px; cursor: pointer; font: inherit; font-size: 13px; }
.day-add:hover { color: var(--primary); border-color: var(--primary); }
.appt {
  border-radius: 9px; padding: 7px 8px; background: var(--info-soft); border-left: 3px solid var(--info);
  cursor: pointer; font-size: 13px; display: grid; gap: 2px; min-width: 0;
}
.appt .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.appt .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt .m { color: var(--text-2); font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.appt.realizada { background: var(--good-soft); border-color: var(--good); }
.appt.no_asistio { background: var(--warn-soft); border-color: var(--warn); }
.appt.cancelada { background: var(--surface-2); border-color: var(--muted); opacity: .7; text-decoration: line-through; }
.appt:hover { filter: brightness(.97); }
.week-summary { display: flex; gap: 18px; flex-wrap: wrap; color: var(--text-2); font-size: 14px; }
.week-summary b { color: var(--text); }

/* ---------- Gráfico ---------- */
.chart { position: relative; }
.chart svg { width: 100%; height: 220px; display: block; overflow: visible; }
.chart .bar { fill: var(--primary); }
.chart .bar.bono { fill: color-mix(in srgb, var(--primary) 45%, var(--surface)); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + g .bar, .chart g.col:hover .bar { filter: brightness(1.12); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 7px 10px;
  border-radius: 8px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 3;
}
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Modal ---------- */
dialog {
  border: 0; padding: 0; background: transparent; max-width: 620px; width: calc(100% - 24px);
  color: var(--text);
}
dialog::backdrop { background: rgba(10, 12, 25, .45); backdrop-filter: blur(2px); }
.modal-card { background: var(--surface); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: grid; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.callout { background: var(--primary-soft); color: var(--text); padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.callout.warn { background: var(--warn-soft); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: max-content; max-width: calc(100% - 32px); }
.toast { background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: pop .2s ease; }
.toast.err { background: var(--bad); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Detalle cliente ---------- */
.client-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.client-head .avatar { width: 56px; height: 56px; font-size: 20px; }
.client-head .info { flex: 1; min-width: 200px; }
.client-head h3 { font-size: 22px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.link-box { display: flex; gap: 8px; }
.link-box input { font-size: 13px; color: var(--text-2); }
.tarifa-row { display: grid; grid-template-columns: 1fr 120px auto; gap: 8px; align-items: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .week { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20;
    flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
  }
  .brand, .sidebar-foot { display: none; }
  #nav { flex-direction: row; width: 100%; justify-content: space-around; }
  #nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; flex: 1; text-align: center; }
  #nav .ico { font-size: 18px; }
  .main { padding-bottom: 80px; }
  .topbar { padding: 14px 16px; }
  .topbar h2 { font-size: 19px; }
  .view { padding: 4px 16px 24px; gap: 14px; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .kpi .value { font-size: 22px; }
  .toolbar input[type="search"] { max-width: none; }
  .hide-sm { display: none; }
  .toasts { bottom: 90px; }
}
@media (max-width: 420px) {
  .topbar-actions #btn-new-client { display: none; }
}
@media print {
  .sidebar, .topbar-actions { display: none; }
  .layout { grid-template-columns: 1fr; }
}
