:root {
  --green-900: #254418;
  --green-700: #3d7128;
  --green-600: #4d8f33;
  --green-500: #6bbe4a;
  --green-100: #ecf8e7;
  --green-soft-bg: #f1f9ec;
  --sand-50: #faf8f5;
  --ink: #1c2321;
  --muted: #6b7573;
  --danger: #c0392b;
  --warning-bg: #fff4e5;
  --warning-border: #f0c36d;
  --border: #e1e6e4;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--sand-50);
  color: var(--ink);
}

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

h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.2rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; color: var(--green-700); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* -------- Flash messages -------- */
.flash-container { position: sticky; top: 0; z-index: 50; padding: .5rem 1rem 0; }
.flash {
  max-width: 900px; margin: 0 auto .5rem; padding: .7rem 1rem; border-radius: var(--radius);
  font-size: .9rem;
}
.flash-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c0; }
.flash-success { background: var(--green-100); color: var(--green-900); border: 1px solid #bfe0dd; }

.alert { padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-warning { background: var(--warning-bg); border: 1px solid var(--warning-border); color: #7a5300; }

/* -------- Auth pages -------- */
.auth-wrap, .public-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.public-wrap {
  background: linear-gradient(180deg, var(--green-soft-bg) 0%, var(--green-100) 100%);
}
.auth-card, .public-card {
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  padding: 2rem; width: 100%; max-width: 480px; box-shadow: 0 8px 24px rgba(18,60,58,0.06);
}
.public-card { max-width: 560px; }

/* -------- Brand / logo -------- */
.brand-header { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.brand-logo { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex-shrink: 0; }
.brand-header h1 { margin: 0; }
.sidebar-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.02rem; margin-bottom: 1.5rem; }
.sidebar-brand img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }

/* -------- Forms -------- */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--green-900); margin-bottom: .9rem; }
input, textarea, select {
  display: block; width: 100%; margin-top: .35rem; padding: .6rem .7rem;
  border: 1px solid var(--border); border-radius: 8px; font-size: .95rem; font-family: inherit;
  background: #fff; color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--green-500); outline-offset: 1px; }
textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.checkbox-label input { width: auto; margin: 0; }
.checkbox-row { display: flex; flex-wrap: wrap; gap: .8rem; margin-bottom: 1rem; }
.form-section { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; margin-bottom: 1rem; background: #fff; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }
.form-grid { max-width: 720px; }

/* -------- Buttons -------- */
.btn {
  display: inline-block; padding: .6rem 1.1rem; border-radius: 8px; border: 1px solid transparent;
  font-size: .9rem; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-700); }
.btn-primary:disabled { background: #a9c4c2; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--green-700); border-color: var(--border); }
.btn-secondary:hover { background: var(--green-100); }
.btn-danger { background: #fff; color: var(--danger); border-color: #f0c9c4; }
.btn-danger:hover { background: #fdecea; }
.btn-block { width: 100%; text-align: center; }
.btn-small { padding: .3rem .6rem; font-size: .8rem; }
.inline-form { display: inline; }

/* -------- Admin shell -------- */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--green-900); color: #f2f6f5; padding: 1.2rem 1rem;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.sidebar-nav a {
  color: #cfe4e1; padding: .55rem .7rem; border-radius: 8px; font-size: .92rem;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.sidebar-nav a.active { background: var(--green-600); color: #fff; }
.sidebar-footer { display: flex; flex-direction: column; gap: .4rem; font-size: .82rem; }
.sidebar-footer a { color: #a9c9c6; }
.admin-main { flex: 1; padding: 2rem 2.5rem; max-width: 1100px; }

/* -------- Panels / tables -------- */
.panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem; margin-bottom: 1.5rem; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; }
.stat-value { display: block; font-size: 1.6rem; font-weight: 700; color: var(--green-700); }
.stat-label { font-size: .8rem; color: var(--muted); }

.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-confirmada { background: #e8f0fe; color: #1a56db; }
.badge-completada { background: var(--green-100); color: var(--green-900); }
.badge-cancelada { background: #fdecea; color: var(--danger); }
.badge-no-asistio { background: #f3f0e8; color: #8a6d1d; }

.patient-info-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.2rem; display: grid; gap: .35rem; font-size: .92rem; }

.day-nav { display: flex; align-items: center; gap: .8rem; margin-bottom: .5rem; }
.day-picker input { margin: 0; }
.fecha-titulo { text-transform: capitalize; }

.search-bar { display: flex; gap: .6rem; margin-bottom: 1rem; max-width: 480px; }
.search-bar input { margin: 0; }

/* -------- Public booking -------- */
.slots-grid { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; }
.slot-btn {
  padding: .5rem .8rem; border: 1px solid var(--green-500); border-radius: 8px; background: #fff;
  color: var(--green-700); font-weight: 600; cursor: pointer; font-size: .88rem;
}
.slot-btn:hover { background: var(--green-100); }
.slot-btn.selected { background: var(--green-600); color: #fff; border-color: var(--green-600); }

.search-results { position: relative; margin-top: -.6rem; margin-bottom: .8rem; }
.search-result-item, .search-result-empty {
  padding: .5rem .7rem; border: 1px solid var(--border); border-top: none; background: #fff; font-size: .88rem; cursor: pointer;
}
.search-result-item:hover { background: var(--green-100); }
.selected-patient {
  background: var(--green-100); border: 1px solid #bfe0dd; border-radius: 8px; padding: .6rem .8rem;
  margin-bottom: .8rem; font-size: .9rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}

.pagination { display: flex; align-items: center; gap: 1rem; justify-content: center; margin-top: 1.2rem; }
.btn.disabled { pointer-events: none; opacity: .45; }

/* -------- Facturación: gráfico y filtros -------- */
.filtro-periodo { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.filtro-periodo label { margin-bottom: 0; }
.filtro-periodo input { margin: .35rem 0 0; }
.chart-wrap { overflow-x: auto; padding-top: 1.6rem; }
.chart-bars {
  display: flex; align-items: flex-end; gap: .5rem; height: 200px; min-width: 100%;
  border-bottom: 1px solid var(--border); padding-bottom: 2px;
}
.chart-col { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 34px; height: 100%; justify-content: flex-end; }
.chart-bar {
  width: 60%; min-width: 10px; background: var(--green-500); border-radius: 4px 4px 0 0;
  position: relative; transition: background .15s;
}
.chart-bar:hover { background: var(--green-700); }
.chart-bar-value {
  position: absolute; top: -1.5rem; left: 50%; transform: translateX(-50%);
  font-size: .68rem; color: var(--green-900); white-space: nowrap; font-weight: 600;
}
.chart-col-label { font-size: .68rem; color: var(--muted); margin-top: .4rem; white-space: nowrap; transform: rotate(-40deg) translateX(-6px); transform-origin: top left; }
.chart-labels-spacer { height: 1.6rem; }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin: 1rem 0 1.5rem; }
.summary-card { background: var(--sand-50); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.1rem; }
.summary-card .summary-value { display: block; font-size: 1.4rem; font-weight: 700; color: var(--green-700); }
.summary-card .summary-sub { font-size: .78rem; color: var(--muted); }

@media (max-width: 720px) {
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .admin-main { padding: 1.2rem; }
  .form-row { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: 1fr 1fr; }
}
