:root {
  --bg: #f4efe7;
  --panel: rgba(255, 252, 247, 0.88);
  --line: rgba(76, 58, 38, 0.14);
  --text: #2d241b;
  --muted: #6f6357;
  --primary: #b95c2e;
  --primary-dark: #964620;
  --success: #2f7d4a;
  --warning: #c48a1d;
  --danger: #a73a32;
  --shadow: 0 24px 60px rgba(82, 56, 20, 0.12);
  --radius-xl: 28px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(185, 92, 46, 0.18), transparent 28%),
    radial-gradient(circle at left bottom, rgba(121, 144, 107, 0.22), transparent 24%),
    linear-gradient(135deg, #f7f0e7 0%, #f1ebe2 48%, #ebe5da 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.auth-shell,
.app-shell {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 0;
}

.auth-card,
.hero,
.panel,
.dialog-card,
.sync-bar {
  backdrop-filter: blur(14px);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(520px, 100%);
  padding: 36px;
  border-radius: var(--radius-xl);
}

.app-shell {
  padding: 28px 0 40px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 32px;
  border-radius: var(--radius-xl);
}

.eyebrow,
.section-label {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--primary);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 12px;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1.02;
}

.hero-copy,
.helper-text,
.error-text {
  color: var(--muted);
  line-height: 1.6;
}

.error-text {
  min-height: 24px;
  color: var(--danger);
  margin-bottom: 0;
}

.login-form,
.hero-actions,
.form-actions,
.dialog-actions,
.filters,
.consent-header {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.hero-actions {
  align-content: flex-start;
  justify-content: flex-end;
}

.session-chip {
  display: grid;
  gap: 4px;
  min-width: 160px;
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.54);
  border: 1px solid var(--line);
}

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

.sync-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
  padding: 14px 20px;
  border-radius: 20px;
}

#syncStatus[data-tone="success"] {
  color: var(--success);
}

#syncStatus[data-tone="error"] {
  color: var(--danger);
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn,
.file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 700;
  transition: 0.2s ease;
}

.primary-btn {
  background: var(--primary);
  color: #fffaf4;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn,
.file-label {
  background: rgba(185, 92, 46, 0.08);
  color: var(--primary-dark);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.danger-btn {
  background: rgba(167, 58, 50, 0.12);
  color: var(--danger);
}

.danger-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.file-label input {
  display: none;
}

.layout {
  display: grid;
  grid-template-columns: 1.05fr 1.2fr;
  gap: 22px;
  margin-top: 22px;
}

.dashboard-panel,
.list-panel {
  grid-column: 1;
}

.form-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.panel {
  padding: 24px;
  border-radius: var(--radius-xl);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  padding: 18px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(248, 240, 228, 0.96));
  border: 1px solid rgba(76, 58, 38, 0.08);
}

.stat-label,
.stat-help {
  display: block;
}

.stat-label {
  margin-bottom: 8px;
  color: var(--muted);
}

.stat-value {
  display: block;
  margin-bottom: 6px;
  font-size: 1.8rem;
}

.stat-help {
  color: var(--muted);
  font-size: 0.92rem;
}

.attention-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.attention-card,
.patient-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: rgba(255, 255, 255, 0.62);
}

.attention-card strong,
.patient-head strong {
  display: block;
  margin-bottom: 6px;
}

.attention-card p,
.patient-meta,
.patient-notes,
.muted-line {
  color: var(--muted);
  line-height: 1.5;
}

.patient-form,
.consent-box,
.history-box,
.patient-list {
  display: grid;
  gap: 18px;
}

.form-grid,
.consent-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 0.96rem;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(76, 58, 38, 0.16);
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
}

textarea {
  resize: vertical;
}

.consent-box,
.history-box {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.consent-box {
  background: linear-gradient(180deg, rgba(255, 247, 238, 0.95), rgba(255, 252, 247, 0.9));
}

.history-box {
  background: rgba(255, 255, 255, 0.54);
}

.checkbox-row {
  grid-column: 1 / -1;
  grid-template-columns: auto 1fr;
  align-items: flex-start;
}

.checkbox-row input {
  width: auto;
  margin-top: 4px;
}

.signature-preview {
  min-height: 130px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  border: 1px dashed rgba(76, 58, 38, 0.2);
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  overflow: hidden;
}

.signature-preview img {
  max-width: 100%;
  height: auto;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 250, 244, 0.92);
  border: 1px solid rgba(76, 58, 38, 0.1);
}

.history-item strong {
  display: block;
  margin-bottom: 6px;
}

.history-item p {
  margin-bottom: 0;
  color: var(--muted);
}

.signature-preview.empty {
  padding: 18px;
}

.filters {
  margin-bottom: 18px;
}

.filters input,
.filters select {
  flex: 1 1 180px;
}

.patient-list {
  max-height: 900px;
  overflow: auto;
  padding-right: 4px;
}

.patient-card {
  display: grid;
  gap: 12px;
}

.patient-head,
.patient-actions,
.badge-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
}

.badge.status-pendiente,
.badge.flag-hoy {
  background: rgba(196, 138, 29, 0.14);
  color: var(--warning);
}

.badge.status-contactado,
.badge.status-confirmado {
  background: rgba(47, 125, 74, 0.12);
  color: var(--success);
}

.badge.status-en-pruebas {
  background: rgba(83, 92, 168, 0.12);
  color: #4450a2;
}

.badge.status-recogido {
  background: rgba(111, 99, 87, 0.12);
  color: #5d5349;
}

.badge.flag-vencido,
.badge.flag-sin-consentimiento {
  background: rgba(167, 58, 50, 0.12);
  color: var(--danger);
}

.patient-actions button {
  min-height: 38px;
  padding: 0 14px;
}

.signature-dialog {
  width: min(960px, calc(100% - 24px));
  border: 0;
  padding: 0;
  background: transparent;
}

.signature-dialog::backdrop {
  background: rgba(45, 36, 27, 0.42);
  backdrop-filter: blur(5px);
}

.dialog-card {
  display: grid;
  gap: 16px;
  padding: 24px;
  border-radius: var(--radius-xl);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

#signaturePad {
  width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: #fff;
  touch-action: none;
}

.empty-state {
  padding: 24px;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--line);
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.46);
}

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

  .dashboard-panel,
  .form-panel,
  .list-panel {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (max-width: 720px) {
  .auth-shell,
  .app-shell {
    width: min(100% - 18px, 1400px);
  }

  .app-shell {
    padding-top: 18px;
  }

  .hero,
  .panel,
  .auth-card {
    padding: 20px;
  }

  .hero,
  .sync-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats-grid,
  .form-grid,
  .consent-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 2rem;
  }
}
