/* ===================================================================
   Emoció Centre PWA — estilos mobile-first
   =================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --teal:        #3e9caa;
  --teal-dark:   #2d8a96;
  --teal-light:  #e6f6f8;
  --green:       #27ae60;
  --green-light: #eafaf1;
  --orange:      #f39c12;
  --orange-light:#fef9e7;
  --red:         #e74c3c;
  --red-light:   #fdecea;
  --gray:        #95a5a6;
  --gray-light:  #f4f6f7;
  --text:        #2c3e50;
  --text-muted:  #7f8c8d;
  --border:      #e8ecee;
  --white:       #ffffff;
  --shadow-sm:   0 1px 4px rgba(0,0,0,.08);
  --shadow:      0 2px 12px rgba(0,0,0,.10);
  --radius:      12px;
  --radius-sm:   8px;
  --nav-h:       64px;
  --header-h:    56px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-light);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── App shell ─────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100dvh; }

.app-header {
  height: var(--header-h);
  background: var(--teal);
  color: var(--white);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  position: relative;
  z-index: 10;
}
.app-header-logo { width: 30px; height: 30px; border-radius: 6px; }
.app-header-title { font-size: 17px; font-weight: 600; flex: 1; }
.app-header-subtitle { font-size: 13px; opacity: .8; }
.app-header-action {
  background: none; border: none; color: var(--white);
  padding: 6px; border-radius: 6px; cursor: pointer;
  font-size: 20px; line-height: 1;
}

/* ── Screens ───────────────────────────────────────────────────── */
.screen-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.screen { display: none; min-height: 100%; }
.screen.active { display: block; }

/* ── Bottom nav ────────────────────────────────────────────────── */
.bottom-nav {
  height: var(--nav-h);
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-tab {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 11px; font-weight: 500;
  padding: 8px 4px; transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-tab.active { color: var(--teal); }
.nav-tab svg { width: 22px; height: 22px; }

/* ── Login ─────────────────────────────────────────────────────── */
#screen-login {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 100dvh; padding: 32px 24px;
  background: var(--white);
}
.login-logo { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 12px; }
.login-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { font-size: 14px; color: var(--text-muted); margin-bottom: 32px; }
.login-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-field {
  padding: 14px 16px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 16px;
  outline: none; transition: border-color .15s;
  background: var(--white);
}
.login-field:focus { border-color: var(--teal); }
.login-btn {
  padding: 14px; background: var(--teal); color: var(--white);
  border: none; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 600; cursor: pointer;
  margin-top: 4px; transition: background .15s;
}
.login-btn:active { background: var(--teal-dark); }
.login-error { color: var(--red); font-size: 13px; text-align: center; min-height: 20px; }

/* ── Section header ────────────────────────────────────────────── */
.section-header {
  padding: 16px 16px 8px;
  display: flex; align-items: center; gap: 8px;
}
.section-title { font-size: 18px; font-weight: 700; flex: 1; }
.section-meta { font-size: 13px; color: var(--text-muted); }

/* ── Date nav ──────────────────────────────────────────────────── */
.date-nav {
  display: flex; align-items: center; gap: 0;
  background: var(--white); border-bottom: 1px solid var(--border);
  padding: 8px 16px; gap: 8px;
}
.date-nav-btn {
  background: none; border: none; color: var(--text-muted);
  padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: 18px; cursor: pointer; line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.date-nav-btn:active { background: var(--gray-light); }
.date-nav-label {
  flex: 1; text-align: center; font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.date-nav-today {
  font-size: 12px; font-weight: 600; color: var(--teal);
  background: var(--teal-light); border: none; border-radius: 20px;
  padding: 4px 10px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── Summary cards ─────────────────────────────────────────────── */
.summary-row {
  display: flex; gap: 10px; padding: 12px 16px 8px;
  overflow-x: auto; scrollbar-width: none;
}
.summary-row::-webkit-scrollbar { display: none; }
.summary-card {
  flex: 1; min-width: 90px; background: var(--white);
  border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 4px;
}
.summary-card-label { font-size: 11px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.summary-card-value { font-size: 20px; font-weight: 700; }
.summary-card-value.teal  { color: var(--teal); }
.summary-card-value.green { color: var(--green); }
.summary-card-value.orange{ color: var(--orange); }
.summary-card-value.gray  { color: var(--gray); }

/* ── Visit cards ───────────────────────────────────────────────── */
.visits-list { padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 8px; }

.visit-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
  display: flex; align-items: stretch;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: box-shadow .15s;
  border-left: 4px solid var(--border);
}
.visit-card:active { box-shadow: var(--shadow); }
.visit-card.paid   { border-left-color: var(--green); }
.visit-card.pending{ border-left-color: var(--orange); }
.visit-card.cancelled { border-left-color: var(--gray); opacity: .6; }

.visit-card-time {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 12px 10px; min-width: 52px;
  border-right: 1px solid var(--border);
  gap: 2px;
}
.visit-time-hour { font-size: 15px; font-weight: 700; }
.visit-time-end  { font-size: 11px; color: var(--text-muted); }

.visit-card-body { flex: 1; padding: 12px 12px 12px 14px; min-width: 0; }
.visit-card-patient { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.visit-card-meta    { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.visit-card-right {
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center;
  padding: 12px 12px 12px 8px; gap: 6px;
}
.visit-amount { font-size: 15px; font-weight: 700; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 20px;
  white-space: nowrap;
}
.badge-pending   { background: var(--orange-light); color: #b7770d; }
.badge-paid      { background: var(--green-light);  color: #1e8449; }
.badge-cash      { background: var(--green-light);  color: #1e8449; }
.badge-card      { background: #eaf4fb; color: #1a6b9a; }
.badge-bizum     { background: #f3ebff; color: #7d3cc8; }
.badge-transfer  { background: #fef9e7; color: #9a7d0a; }
.badge-cancelled { background: var(--gray-light);   color: var(--text-muted); }
.badge-square    { background: #fff3e0; color: #e65100; }

/* ── Pay button (quick action) ────────────────────────────────── */
.btn-pay {
  background: var(--teal); color: var(--white);
  border: none; border-radius: var(--radius-sm);
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-pay:active { background: var(--teal-dark); }

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 48px 24px; color: var(--text-muted); gap: 10px;
}
.empty-state-icon { font-size: 48px; line-height: 1; }
.empty-state-text { font-size: 15px; text-align: center; }

/* ── Modal / bottom sheet ──────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 100; display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal-sheet {
  width: 100%; background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0 0 env(safe-area-inset-bottom);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.4,0,.2,1);
  max-height: 90dvh; overflow-y: auto;
}
.modal-backdrop.open .modal-sheet { transform: translateY(0); }

.modal-handle {
  width: 36px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 10px auto 4px;
}
.modal-header {
  padding: 8px 20px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.modal-title    { font-size: 18px; font-weight: 700; }
.modal-subtitle { font-size: 13px; color: var(--text-muted); }

.modal-body { padding: 0 16px 16px; }

/* ── Payment method grid ───────────────────────────────────────── */
.payment-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 0 16px 16px;
}
.payment-btn {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 18px 12px;
  background: var(--gray-light); border: 2px solid transparent;
  border-radius: var(--radius); cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--text);
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.payment-btn:active    { transform: scale(.96); }
.payment-btn.selected  { border-color: var(--teal); background: var(--teal-light); color: var(--teal); }
.payment-btn-icon      { font-size: 28px; line-height: 1; }

.modal-actions { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.btn-primary {
  width: 100%; padding: 15px; background: var(--teal); color: var(--white);
  border: none; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 700; cursor: pointer;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: var(--teal-dark); }
.btn-primary:disabled { background: var(--gray); cursor: default; }
.btn-secondary {
  width: 100%; padding: 13px; background: none; color: var(--text-muted);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── Income screen ─────────────────────────────────────────────── */
.income-method-list { padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.income-method-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.income-method-icon { font-size: 24px; }
.income-method-info { flex: 1; }
.income-method-name  { font-size: 15px; font-weight: 600; }
.income-method-count { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.income-method-amount{ font-size: 17px; font-weight: 700; }

/* ── Pending visits (income screen) ────────────────────────────── */
.pending-header {
  padding: 16px 16px 6px;
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-muted);
}

/* ── Spinner / loading ─────────────────────────────────────────── */
.spinner {
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
}
.spinner::after {
  content: ''; width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--teal);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2c3e50; color: var(--white);
  padding: 10px 20px; border-radius: 20px;
  font-size: 14px; font-weight: 500;
  opacity: 0; transition: all .25s; pointer-events: none;
  white-space: nowrap; max-width: 90vw;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

/* ── Visitas filter tabs ────────────────────────────────────────── */
.filter-tabs {
  display: flex; gap: 0;
  background: var(--white); border-bottom: 1px solid var(--border);
  padding: 0 16px; overflow-x: auto; scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
  flex-shrink: 0; padding: 12px 14px;
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  border: none; background: none; cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.filter-tab.active { color: var(--teal); border-bottom-color: var(--teal); }

/* ── Week strip ─────────────────────────────────────────────────── */
.week-strip {
  background: var(--white); border-bottom: 1px solid var(--border);
  padding: 8px 0 10px; user-select: none;
}
.week-month {
  text-align: center; font-size: 12px; font-weight: 600;
  color: var(--text-muted); text-transform: capitalize;
  letter-spacing: .3px; margin-bottom: 8px;
}
.week-days-row {
  display: flex; align-items: center;
  padding: 0 4px; gap: 0;
}
.week-nav {
  background: none; border: none; color: var(--text-muted);
  padding: 6px 8px; font-size: 18px; cursor: pointer; line-height: 1;
  flex-shrink: 0; border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}
.week-nav:active { background: var(--gray-light); }
.week-days {
  flex: 1; display: flex; justify-content: space-around;
}
.week-day {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 4px 0; min-width: 36px;
  background: none; border: none; cursor: pointer;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.wday-lbl {
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
}
.wday-num {
  width: 32px; height: 32px; display: flex; align-items: center;
  justify-content: center; border-radius: 50%;
  font-size: 15px; font-weight: 600; color: var(--text);
  transition: background .15s, color .15s;
}
.week-day.today .wday-lbl { color: var(--teal); }
.week-day.today .wday-num { color: var(--teal); font-weight: 700; }
.week-day.selected .wday-num {
  background: var(--teal); color: var(--white);
}
.week-day.today.selected .wday-num {
  background: var(--teal); color: var(--white);
}
.week-day-dot {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--teal);
}
.week-day.selected .week-day-dot { background: var(--teal-dark); }

/* ── Pull-to-refresh indicator ─────────────────────────────────── */
.ptr-indicator {
  height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--gray-light); flex-shrink: 0;
  transition: none;
}
.ptr-spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border); border-top-color: var(--teal);
  border-radius: 50%; animation: spin .7s linear infinite;
  opacity: 0; transition: opacity .15s;
}
.ptr-indicator.visible .ptr-spinner { opacity: 1; }
.ptr-indicator.ready .ptr-spinner { border-top-color: var(--green); }

/* ── Visit detail modal ─────────────────────────────────────────── */
.vd-header {
  padding: 12px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.vd-patient {
  font-size: 20px; font-weight: 700; margin-bottom: 4px;
}
.vd-time {
  font-size: 14px; color: var(--text-muted);
}
.vd-rows {
  padding: 8px 0;
}
.vd-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
}
.vd-row:last-child { border-bottom: none; }
.vd-row-label {
  font-size: 14px; color: var(--text-muted);
}
.vd-row-value {
  font-size: 14px; font-weight: 600; text-align: right;
}
.vd-amount {
  font-size: 18px; font-weight: 700; color: var(--teal);
}
.vd-actions {
  padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 8px;
}
