:root {
  --bg: #eff6ff;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --border: #bfdbfe;
  --accent: #0284c7;
  --accent-dark: #0369a1;
  --accent-soft: #e0f2fe;
  --accent-border: #7dd3fc;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 12% 8%, #dbeafe 0%, #eff6ff 46%);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

.app-shell {
  max-width: 1680px;
  margin: 0 auto;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(14, 116, 144, 0.12);
}

.brand {
  display: grid;
  gap: 4px;
}

.brand-logo {
  display: block;
  width: 100%;
  height: auto;
}

.brand-logo-login {
  width: min(290px, 100%);
  margin: 0 auto 6px;
}

.brand-logo-header {
  width: 220px;
}

.auth-card h1 {
  margin: 0;
  font-size: 1.4rem;
}

.auth-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.auth-form {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.auth-form label {
  display: grid;
  gap: 4px;
  font-size: 0.88rem;
  color: var(--muted);
}

.auth-form input,
.auth-form button {
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0 10px;
  font-size: 0.95rem;
}

.auth-form button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.auth-form button:hover {
  background: var(--accent-dark);
}

.auth-message {
  min-height: 20px;
  margin: 10px 0 0;
  font-size: 0.86rem;
}

.auth-message.err {
  color: #b91c1c;
}

.auth-message.ok {
  color: #065f46;
}

.auth-help {
  margin-top: 8px;
  font-size: 0.84rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip {
  display: inline-flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 9px;
  background: #f0f9ff;
  line-height: 1.1;
}

.user-chip strong {
  font-size: 0.86rem;
}

.user-chip span {
  font-size: 0.75rem;
  color: var(--muted);
}

.status {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  background: #f8fbff;
}

.status.ok {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-dark);
}

.status.err {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.ghost {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 0 10px;
  cursor: pointer;
}

.ghost:hover {
  border-color: var(--accent-border);
}

.module-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: #f0f9ff;
  border-bottom: 1px solid var(--border);
}

.module-tabs button {
  height: 34px;
  border-radius: 999px;
  border: 1px solid #bae6fd;
  background: #fff;
  padding: 0 12px;
  cursor: pointer;
}

.module-tabs button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.controls {
  display: grid;
  grid-template-columns: 180px 180px minmax(220px, 1fr) auto;
  gap: 10px;
  padding: 12px 16px;
  align-items: end;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.86rem;
  color: var(--muted);
}

.controls select,
.controls input,
.controls button {
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 0 10px;
  font-size: 0.92rem;
  width: 100%;
  min-width: 0;
}

.controls button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
}

.controls button:hover {
  opacity: 0.9;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 14px;
  padding: 0 16px 16px;
}

.calendar-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 72vh;
}

#calendar {
  padding: 10px;
}

.side-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  align-self: start;
  position: sticky;
  top: 10px;
}

.side-panel h2,
.side-panel h3 {
  margin: 0 0 10px;
}

.summary {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.summary > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 0.9rem;
}

.fisio-quick {
  margin-bottom: 14px;
}

.fisio-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.fisio-list li {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
}

.fisio-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fisio-actions button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 4px 8px;
  font-size: 0.78rem;
  cursor: pointer;
}

.fisio-actions button[data-status="Confirmada"] {
  border-color: #0ea5e9;
  color: #075985;
}

.fisio-actions button[data-status="Completada"] {
  border-color: #0284c7;
  color: #0c4a6e;
}

.fisio-actions button[data-status="No presentado"] {
  border-color: #d97706;
  color: #92400e;
}

.password-form {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.password-form input,
.password-form button {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0 8px;
}

.password-form button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
}

.small-msg {
  min-height: 18px;
  font-size: 0.8rem;
  margin: 0 0 14px;
}

.small-msg.ok {
  color: var(--accent-dark);
}

.small-msg.err {
  color: #991b1b;
}

.legend {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 7px;
  font-size: 0.9rem;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}

.s-reservada {
  background: #3b82f6;
}

.s-confirmada {
  background: #0ea5e9;
}

.s-cancelada {
  background: #ef4444;
}

.s-completada {
  background: #0284c7;
}

.s-noshow {
  background: #f59e0b;
}

.s-curso {
  background: #2563eb;
}

.s-reprogramada {
  background: #38bdf8;
}

.module {
  padding: 12px 16px 16px;
}

.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.46);
}

.modal-card {
  width: min(980px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
}

.modal .patient-form,
.modal .billing-form {
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.kpi-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  margin-bottom: 12px;
}

.kpi {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.kpi span {
  color: var(--muted);
  font-size: 0.84rem;
}

.kpi strong {
  font-size: 1.2rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.dash-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 6px 20px rgba(14, 116, 144, 0.06);
}

.dash-panel h3 {
  margin: 0 0 10px;
  font-size: 0.96rem;
  color: #0c4a6e;
}

.dash-panel canvas {
  width: 100% !important;
  height: 240px !important;
}

.dash-rankings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 12px;
}

.dash-ranking-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.dash-ranking-card h4 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  color: #0c4a6e;
}

.dash-ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.dash-ranking-list li {
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 4px;
}

.dash-ranking-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.dash-ranking-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.module-head {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.module-head input,
.module-head select,
.module-head button {
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 0 10px;
  min-width: 0;
}

.module-head button {
  cursor: pointer;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.payments-toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

.payments-toolbar label {
  display: grid;
  gap: 4px;
  font-size: 0.84rem;
  color: #334155;
}

.payments-toolbar input,
.payments-toolbar button {
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 0 10px;
  min-width: 0;
}

.payments-toolbar button {
  cursor: pointer;
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.payments-toolbar button:hover {
  background: #dbeafe;
}

.payments-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.payments-summary article {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  display: grid;
  gap: 4px;
}

.payments-summary article span {
  font-size: 0.8rem;
  color: var(--muted);
}

.payments-summary article strong {
  font-size: 1rem;
}

.payments-summary-methods {
  grid-column: span 2;
}

.payments-summary-methods p {
  margin: 0;
  font-size: 0.86rem;
}

.payments-summary-methods ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
}

.payments-summary-methods li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
}

.patient-form {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  margin-bottom: 10px;
}

.patient-form h3 {
  margin: 0 0 8px;
}

.patient-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
}

.patient-form label {
  display: grid;
  gap: 4px;
  font-size: 0.86rem;
  color: #334155;
  min-width: 0;
}

.patient-form input,
.patient-form select,
.patient-form textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  font: inherit;
  width: 100%;
  min-width: 0;
}

.patient-form-checks {
  margin-top: 8px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.patient-form-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.patient-form-actions button {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0 12px;
  cursor: pointer;
}

.patient-form-actions #pfSave {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.billing-form {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  margin-bottom: 10px;
}

.billing-config {
  margin: 8px 0 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f0f9ff;
  color: #334155;
  font-size: 0.86rem;
}

.billing-config .err {
  color: #b91c1c;
}

.billing-form h3 {
  margin: 0 0 8px;
}

.billing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
}

.billing-form label {
  display: grid;
  gap: 4px;
  font-size: 0.86rem;
  color: #334155;
  min-width: 0;
}

.billing-full {
  grid-column: 1 / -1;
}

.billing-form input,
.billing-form select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  font: inherit;
  width: 100%;
  min-width: 0;
}

.billing-actions {
  margin-top: 10px;
}

.billing-actions button {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0 12px;
  cursor: pointer;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table-wrap th,
.table-wrap td {
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  padding: 8px;
  white-space: nowrap;
}

.table-wrap thead th {
  position: sticky;
  top: 0;
  background: #f0f9ff;
  z-index: 1;
}

.table-btn {
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 0 8px;
  cursor: pointer;
}

.comm-type {
  display: inline-block;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f8fafc;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 600;
}

.comm-type.t24 {
  border-color: #bae6fd;
  background: #e0f2fe;
  color: #0c4a6e;
}

.comm-type.t2 {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
}

.comm-type.tfollow {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
}

.comm-type.treview {
  border-color: #c7d2fe;
  background: #eef2ff;
  color: #3730a3;
}

.patient-drawer {
  position: fixed;
  right: 0;
  top: 0;
  width: min(420px, 100vw);
  height: 100vh;
  background: #ffffff;
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(15, 23, 42, 0.12);
  z-index: 40;
  padding: 14px;
  overflow: auto;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.drawer-meta {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.drawer-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: grid;
  gap: 8px;
}

.drawer-list li {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 0.88rem;
  line-height: 1.35;
}

.drawer-form {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin: 0 0 12px;
  background: #f0f9ff;
}

.drawer-form h4 {
  margin: 0 0 8px;
}

.drawer-form form {
  display: grid;
  gap: 8px;
}

.drawer-form label {
  display: grid;
  gap: 4px;
  font-size: 0.86rem;
  color: #334155;
}

.drawer-form input,
.drawer-form select,
.drawer-form textarea,
.drawer-form button {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  width: 100%;
  min-width: 0;
}

input[type="file"] {
  width: 100%;
  min-width: 0;
  height: auto;
  padding: 6px;
}

.drawer-form button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
}

.fc .fc-toolbar-title {
  font-size: 1.1rem;
}

.fc .fc-button {
  text-transform: capitalize;
}

.fc .fc-button-primary {
  background-color: var(--accent);
  border-color: var(--accent);
}

.fc .fc-button-primary:hover,
.fc .fc-button-primary:focus {
  background-color: var(--accent-dark);
  border-color: var(--accent-dark);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }

  .module {
    padding: 12px 14px 14px;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .brand-logo-header {
    width: 190px;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .controls .search,
  .controls button {
    grid-column: 1 / -1;
  }

  .calendar-panel {
    min-height: 60vh;
  }

  .module-head {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .billing-grid,
  .patient-form-grid {
    grid-template-columns: 1fr;
  }

  .payments-toolbar,
  .payments-summary {
    grid-template-columns: 1fr;
  }

  .payments-summary-methods {
    grid-column: auto;
  }

  .dashboard-grid,
  .dash-rankings {
    grid-template-columns: 1fr;
  }

  .table-wrap th,
  .table-wrap td {
    white-space: normal;
    vertical-align: top;
  }

  .table-wrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }

  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tbody {
    display: grid;
    gap: 10px;
  }

  .table-wrap tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    padding: 8px;
  }

  .table-wrap td {
    border-bottom: 1px dashed #e5e7eb;
    border-top: 0;
    border-left: 0;
    border-right: 0;
    min-height: 38px;
    position: relative;
    padding: 8px 8px 8px 120px;
  }

  .table-wrap td:last-child {
    border-bottom: 0;
  }

  .table-wrap td[colspan] {
    padding-left: 8px;
  }

  .table-wrap td[colspan]::before {
    content: none;
  }

  .table-wrap td::before {
    content: attr(data-label);
    position: absolute;
    left: 8px;
    top: 8px;
    width: 104px;
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
  }

  .table-wrap td[data-label="Acciones"] {
    padding-left: 8px;
  }

  .table-wrap td[data-label="Acciones"]::before {
    position: static;
    width: auto;
    display: block;
    margin-bottom: 6px;
  }

  .table-btn {
    margin: 2px 6px 2px 0;
    min-height: 34px;
    height: auto;
    padding: 6px 10px;
  }

  .module-tabs {
    overflow: auto;
    white-space: nowrap;
  }

  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-card {
    width: 100%;
    max-height: 100vh;
    border-radius: 14px 14px 0 0;
  }
}

@media (max-width: 560px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .controls .search,
  .controls button {
    grid-column: auto;
  }

  .module {
    padding: 10px 10px 14px;
  }

  .layout {
    padding: 0 10px 12px;
  }
}

@media (pointer: coarse) {
  .ghost,
  .module-tabs button,
  .controls select,
  .controls input,
  .controls button,
  .module-head input,
  .module-head select,
  .module-head button,
  .patient-form-actions button,
  .billing-actions button {
    min-height: 40px;
  }
}
