/* DudiMed — prototipo home mobile-first (dark mode di default) */

:root {
  --bg: #11151a;
  --surface: #1a1f26;
  --surface-2: #222833;
  --line: #2a303b;
  --text: #f2f0ec;
  --text-muted: #9aa2b0;
  --text-faint: #6b7280;

  --ok: #5db9a4;
  --ok-bg: rgba(93, 185, 164, 0.14);
  --warn: #e3a44d;
  --warn-bg: rgba(227, 164, 77, 0.14);
  --alert: #e2726b;
  --alert-bg: rgba(226, 114, 107, 0.14);
  --neutral: #7b8698;
  --neutral-bg: rgba(123, 134, 152, 0.14);

  --accent: #5db9a4;
  --accent-strong: #4aa08d;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.app[hidden] { display: none; }

/* Topbar */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 18px) 20px 8px;
}

.today-date {
  margin: 0 0 2px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.greeting {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  flex-shrink: 0;
}
.icon-btn:active {
  background: var(--surface-2);
}

/* Contenuto scrollabile */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px calc(24px + var(--safe-bottom) + 78px);
  -webkit-overflow-scrolling: touch;
}

.section-title {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

/* Card stato oggi */
.status-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  margin: 12px 0 18px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.status-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.status-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.status-item[data-level="ok"] .status-dot { background: var(--ok-bg); color: var(--ok); }
.status-item[data-level="warn"] .status-dot { background: var(--warn-bg); color: var(--warn); }
.status-item[data-level="alert"] .status-dot { background: var(--alert-bg); color: var(--alert); }
.status-item[data-level="neutral"] .status-dot { background: var(--neutral-bg); color: var(--neutral); }

.status-label {
  margin: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-value {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.15;
}

/* Azioni rapide */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}

.action-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 108px;
  text-align: left;
  transition: transform 0.12s ease, background 0.12s ease;
}
.action-card:active {
  transform: scale(0.96);
  background: var(--surface-2);
}

.action-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-card[data-action="checkin"].is-done .action-icon,
.action-card[data-action="therapy"].is-done .action-icon {
  background: var(--ok-bg);
  color: var(--ok);
}

.action-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.action-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: -6px;
}

.action-card.is-done .action-sub {
  color: var(--ok);
}

/* Timeline */
.timeline-section {
  margin-bottom: 12px;
}

.timeline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.timeline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.timeline-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  animation: fadeIn 0.25s ease;
}
.timeline-item:last-child { border-bottom: none; }

.timeline-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.timeline-body { flex: 1; min-width: 0; }

.timeline-title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
}

.timeline-meta {
  margin: 1px 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-time {
  font-size: 0.76rem;
  color: var(--text-faint);
  flex-shrink: 0;
}

.timeline-empty {
  padding: 22px 4px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.85rem;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Bottom nav */
.bottom-nav {
  position: sticky;
  bottom: 0;
  display: flex;
  background: rgba(26, 31, 38, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--text-faint);
  border-radius: var(--radius-sm);
}

.nav-item span {
  font-size: 0.66rem;
  font-weight: 500;
}

.nav-item.is-active {
  color: var(--accent);
}

.nav-item:active {
  background: var(--surface);
}

/* Bottom sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}
.sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 50;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -8px 30px rgba(0,0,0,0.35);
}
.sheet.is-open {
  transform: translateY(0);
}
.sheet.is-dragging {
  transition: none;
}

.sheet-drag {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  touch-action: none;
}
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}

.sheet-body {
  padding: 6px 20px calc(20px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 4px 0 4px;
}
.sheet-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 18px;
}

/* Componenti form dentro le sheet */
.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 18px 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field-label:first-child { margin-top: 0; }

.emoji-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.emoji-btn {
  flex: 1;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  border-radius: 14px;
  background: var(--surface-2);
  transition: transform 0.12s ease, background 0.12s ease;
}
.emoji-btn.is-selected {
  background: var(--ok-bg);
  transform: scale(1.08);
  box-shadow: inset 0 0 0 2px var(--ok);
}
.emoji-btn:active { transform: scale(0.92); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.84rem;
  color: var(--text-muted);
  border: 1px solid transparent;
}
.chip.is-selected {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok);
  font-weight: 600;
}

.template-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  text-align: left;
}
.template-card:active { background: var(--line); }

.nickel-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.nickel-dot.low { background: var(--ok); }
.nickel-dot.medium { background: var(--warn); }
.nickel-dot.high { background: var(--alert); }

.template-info { flex: 1; min-width: 0; }
.template-name { font-size: 0.88rem; font-weight: 600; margin: 0; }
.template-meta { font-size: 0.75rem; color: var(--text-muted); margin: 2px 0 0; }

.note-toggle {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  padding: 10px 0;
}

textarea.note-input {
  width: 100%;
  min-height: 70px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  resize: none;
}
textarea.note-input:focus { outline: 2px solid var(--accent); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 10px;
}
.switch-row .field-label { margin: 0; }

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.18s ease, background 0.18s ease;
}
.switch.is-on { background: var(--ok-bg); }
.switch.is-on::after {
  transform: translateX(20px);
  background: var(--ok);
}

.primary-btn {
  width: 100%;
  padding: 15px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #0d1310;
  font-weight: 700;
  font-size: 0.95rem;
  margin-top: 20px;
  transition: transform 0.12s ease, background 0.12s ease;
}
.primary-btn:active {
  transform: scale(0.98);
  background: var(--accent-strong);
}
.primary-btn.is-done {
  background: var(--ok);
}

.therapy-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 6px;
}
.therapy-hero-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--ok-bg);
  color: var(--ok);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.therapy-hero-text .t1 { font-weight: 700; font-size: 0.98rem; }
.therapy-hero-text .t2 { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.sheet-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  background: #222833;
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90%;
  white-space: nowrap;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast .toast-check { color: var(--ok); flex-shrink: 0; }

@media (min-width: 481px) {
  body { background: #05070a; }
  .app { min-height: 100dvh; box-shadow: 0 0 60px rgba(0,0,0,0.5); }
}

/* Login */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
}
.login-screen[hidden] { display: none; }
.login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: var(--ok-bg);
  color: var(--ok);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-title {
  margin: 0 0 4px;
  font-size: 1.6rem;
  font-weight: 800;
}
.login-subtitle {
  margin: 0 0 26px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
#loginForm { text-align: left; }

.text-input {
  width: 100%;
  padding: 14px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  margin-bottom: 10px;
}
.text-input:focus { outline: 2px solid var(--accent); }

.login-error {
  color: var(--alert);
  font-size: 0.82rem;
  margin: 2px 0 10px;
}

/* Tab panels (storico / report / profilo) */
.panel-section { margin-bottom: 22px; }
.panel-empty {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.85rem;
  padding: 30px 10px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.history-item .h-icon {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); color: var(--accent);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.history-item .h-body { flex: 1; min-width: 0; }
.history-item .h-title { margin: 0; font-size: 0.87rem; font-weight: 600; }
.history-item .h-meta { margin: 2px 0 0; font-size: 0.76rem; color: var(--text-muted); }
.history-item .h-date { font-size: 0.72rem; color: var(--text-faint); flex-shrink: 0; }

.day-strip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.day-bar {
  flex: 0 0 auto;
  width: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.day-bar .bar-track {
  width: 8px;
  height: 60px;
  border-radius: 999px;
  background: var(--surface-2);
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.day-bar .bar-fill {
  width: 100%;
  border-radius: 999px;
  background: var(--accent);
}
.day-bar[data-nickel="high"] .bar-fill { background: var(--alert); }
.day-bar[data-nickel="medium"] .bar-fill { background: var(--warn); }
.day-bar .bar-label { font-size: 0.6rem; color: var(--text-faint); }

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 6px;
}
.stat-tile {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px;
}
.stat-tile .s-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-tile .s-value { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }

.profile-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.profile-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--ok-bg); color: var(--ok);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem; flex-shrink: 0;
}
.profile-info .p-name { margin: 0; font-weight: 700; }
.profile-info .p-email { margin: 2px 0 0; font-size: 0.78rem; color: var(--text-muted); }

.settings-list { display: flex; flex-direction: column; gap: 8px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: left;
  width: 100%;
}
.settings-row .sr-label { font-size: 0.88rem; font-weight: 600; }
.settings-row .sr-sub { font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }
.settings-row.is-danger .sr-label { color: var(--alert); }

.ingredient-picker { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; }
.ingredient-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2);
}
.ingredient-row .ing-name { flex: 1; font-size: 0.86rem; }
.ingredient-row input[type="number"] {
  width: 64px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit;
}
.ingredient-row.is-selected { box-shadow: inset 0 0 0 1.5px var(--ok); }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-head .section-title { margin: 0; }
.add-btn {
  display: flex; align-items: center; gap: 4px;
  background: var(--ok-bg); color: var(--ok);
  border-radius: 999px; padding: 6px 12px 6px 10px;
  font-size: 0.78rem; font-weight: 700;
}

.item-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: var(--radius-md);
  padding: 12px 14px; margin-bottom: 8px;
}
.item-row .item-body { flex: 1; min-width: 0; }
.item-row .item-title { margin: 0; font-weight: 600; font-size: 0.88rem; }
.item-row .item-sub { margin: 2px 0 0; font-size: 0.76rem; color: var(--text-muted); }
.item-row .item-sub.is-off { color: var(--text-faint); }
.row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn-sm {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-muted); flex-shrink: 0;
}
.icon-btn-sm.is-danger { color: var(--alert); }

.marker-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.marker-row:last-child { border-bottom: none; }
.marker-row .marker-name { flex: 1; font-size: 0.86rem; }
.marker-row input {
  width: 90px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; text-align: right;
}
.marker-value.is-out { color: var(--alert); font-weight: 700; }

.alert-banner {
  background: var(--alert-bg); color: var(--alert);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 0.78rem; margin: 10px 0;
}
.alert-banner.is-warn { background: var(--warn-bg); color: var(--warn); }
