:root{--nav-height:78px}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial, 'Noto Sans', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background: #0b1220; color: #e6edf3; }
a { color: #93c5fd; text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header { position: fixed; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; background: #0b1220; border-bottom: 1px solid #1f2937; }
.title-area { display: flex; align-items: center; gap: 12px; }
.title-area .logo { width: 40px; height: 40px; border-radius: 10px; }
h1 { margin: 0; font-size: 1.25rem; }
.subtitle { margin: 0; font-size: .85rem; color: #9ca3af; }
.actions { display: flex; align-items: center; gap: 8px; }
.install-status { font-size: .85rem; color: #9ca3af; }

.btn { border: 1px solid #334155; background: #111827; color: #e6edf3; padding: 8px 10px; border-radius: 12px; cursor: pointer; }
.btn:hover { background: #0f172a; }
.btn.primary { background: #0ea5e9; border-color: #0ea5e9; color: #0b1220; }
.btn.small { padding: 10px 12px; border-radius: 12px; }
.btn.icon { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; font-size: 1.1rem; }
.btn.step { font-weight: 700; }

main { padding: 16px; max-width: 1100px; margin: 0 auto; }
.week-info { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 16px; font-size: .95rem; color: #cbd5e1; }
.note { color: #94a3b8; font-size: .85rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { background: #0f172a; border: 1px solid #1f2937; border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card.completed { outline: 2px solid #10b981; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { font-weight: 900; text-transform: uppercase; color: #0ea5e9; font-size: 1.35rem; }
.card-sub { font-size: .85rem; color: #9ca3af; }

.progress { width: 100%; background: #111827; height: 10px; border-radius: 999px; overflow: hidden; border: 1px solid #1f2937; }
.progress > div { height: 100%; width: 0%; background: linear-gradient(90deg, #60a5fa, #22d3ee); transition: width .25s ease; }

.counter { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.counter .value { font-variant-numeric: tabular-nums; padding: 2px 8px; border-radius: 8px; background: #111827; border: 1px solid #1f2937; }
.counter .value.reached { color: #10b981; border-color: #10b981; background: #052e2b; }
/* Larger counter numbers */
.counter .value { font-size: 1.6rem; line-height: 1.2; font-weight: 700; letter-spacing: 0.2px; }
@media (min-width: 480px) {
  .counter .value { font-size: 1.8rem; }
}

/* Safer controls spacing */
.controls { display: flex; flex-direction: column; gap: 10px; }
.controls-line { display: flex; align-items: center; gap: 12px; }
.controls-reset { display: flex; }
.controls-reset .btn.reset { width: 100%; }

/* Reset button caution style */
.btn.reset { border-color: #ef4444; color: #ef4444; background: #111827; }
.btn.reset:hover { background: #220d0d; }

.badge { font-size: .8rem; color: #10b981; display: inline-flex; align-items: center; gap: 6px; }
.badge svg { width: 16px; height: 16px; }

.modal::backdrop { background: rgba(0,0,0,.6); }
.modal { border: 1px solid #334155; border-radius: 14px; padding: 0; max-width: 680px; width: 92vw; color: #e6edf3; }
.modal form { margin: 0; padding: 0; }
.modal h3 { margin: 0; padding: 14px; border-bottom: 1px solid #1f2937; background: #0b1220; color: #e6edf3; }
.modal .info-body, .modal .history-body { padding: 14px; background: #0f172a; max-height: 60vh; overflow: auto; color: #e6edf3; }
.modal .info-body a, .modal .history-body a { color: #bfe0ff; }
.modal-actions { padding: 12px 14px; border-top: 1px solid #1f2937; background: #0b1220; display: flex; justify-content: flex-end; }

.info-list { padding-left: 18px; line-height: 1.5; }
.history-item { padding: 10px 12px; border: 1px solid #1f2937; border-radius: 10px; margin-bottom: 10px; background: #0b1220; }
.history-item .title { font-weight: 700; margin-bottom: 6px; }
.history-grid { display: grid; grid-template-columns: repeat(2, minmax(160px, 1fr)); gap: 8px; }
.history-grid .row { display: flex; justify-content: space-between; gap: 8px; font-size: .92rem; }

footer { padding: 12px 16px; color: #94a3b8; text-align: center; }

/* Material 3 FAB */
.fab {
  position: fixed; right: 20px; bottom: calc(var(--nav-height, 78px) + 16px + env(safe-area-inset-bottom, 0px)); width: 56px; height: 56px;
  border-radius: 16px; border: none; outline: none; cursor: pointer;
  background: #0ea5e9; color: white; box-shadow: 0 6px 10px rgba(0,0,0,.3);
  display: grid; place-items: center; z-index: 80;
}
.fab:active { transform: translateY(1px); }
.fab-icon { font-weight: 900; font-size: 1.25rem; line-height: 1; }
.sheet-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; }
.m3-sheet { position: fixed; left:0; right:0; bottom:0; background:#0b1220; color:#e5e7eb;
  border-top-left-radius:24px; border-top-right-radius:24px; box-shadow:0 -10px 30px rgba(0,0,0,.35);
  transform: translateY(100%); transition: transform .28s ease; max-height:80vh; z-index:100; display:flex; flex-direction:column;}
.m3-sheet.show { transform: translateY(0); }
.m3-sheet .sheet-handle { width:48px; height:5px; border-radius:3px; background:#334155; margin:10px auto; }
.m3-sheet .sheet-content { padding:12px 16px 80px; overflow:auto; }
.m3-sheet h2 { font-size:1.1rem; margin:8px 0 6px; color:#93c5fd; font-weight:800; }
.m3-sheet h3 { margin:14px 0 6px; font-weight:800; color:#60a5fa; text-transform:uppercase; letter-spacing:.02em; }
.m3-sheet ul { margin:0 0 8px 18px; padding:0; }
.m3-sheet li { margin:4px 0; line-height:1.3; }
.sheet-close { position: fixed; bottom: 0; align-self:center; margin:8px auto 10px; background:#1d4ed8; color:white; border:none; border-radius:12px; padding:10px 16px; font-weight:700; cursor:pointer; }
.sheet-close:active { transform: translateY(1px); }


/* Inputs for modals */
.input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #334155; background:#0b1220; color:#e6edf3; }
.input:focus { outline: 2px solid #0ea5e9; border-color: transparent; }

/* Tiny icon buttons for header controls */
.btn.tiny { width: 32px; height: 32px; padding: 0; display:inline-flex; align-items:center; justify-content:center; border-radius: 10px; font-size: 1rem; }
.btn.warn { border-color:#ef4444; color:#ef4444; }
.btn.ghost { background: transparent; }
.card-header .controls-icons { display:flex; gap:6px; align-items:center; }
.card .value.editable { cursor: pointer; border-bottom: 1px dashed #334155; }


/* Textarea style */
.textarea { width:100%; padding:10px 12px; border-radius:10px; border:1px solid #334155; background:#0b1220; color:#e6edf3; resize:vertical; }
.textarea:focus { outline:2px solid #0ea5e9; border-color:transparent; }


/* Drag & Drop reordering */
.card.drag-over { outline: 2px dashed #60a5fa; }
.card.dragging { opacity: 0.6; }


/* Drag handle (grip) */
.btn.grip { cursor: grab; user-select: none; touch-action: none; font-weight: 900; }
.btn.grip:active { cursor: grabbing; }
.card.dragging { opacity: 0.6; }


/* Ensure labels 'Titolo' and 'Target' are above fields and full-width in modals */
.modal .info-body label { display:block; width:100%; margin: 8px 0 6px; font-weight:600; }
.modal .info-body .input, .modal .info-body .textarea { width:100%; }



/* Full-width title+target block above everything */
.card-top { width: 100%; display: block; }
.card-top .card-title { display: block; }
.card-target { display: block; font-size: .95rem; color: #9ca3af; margin-top: 2px; }


/* Bottom Navigation (Material 3-ish) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  background: #0b1220;
  border-top: 1px solid #1f2937;
  padding: 6px 6px calc(env(safe-area-inset-bottom, 0) + 6px);

  left: 0;
  right: 0;
  width: 100%;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  border-radius: 12px;
  cursor: pointer;
}
.nav-item.active {
  background: #111827;
  color: #0ea5e9;
}
.nav-item:focus-visible { outline: 2px solid #0ea5e9; outline-offset: 2px; }
.nav-icon { line-height: 0; }
.nav-label { font-size: 12px; }

/* Ensure content not hidden under nav */
main { padding-bottom: calc(env(safe-area-inset-bottom, 0) + var(--nav-height)); }

.empty-section {
  color: #9ca3af;
  text-align: center;
  padding: 24px 8px;
  font-size: .95rem;
}

/* Category badge on cards */
.cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid #334155;
  background: #0b1220;
  color: #cbd5e1;
  font-weight: 600;
  font-size: .75rem;
  width: fit-content;
  margin-top: 6px;
}

/* --- App Bar Full-Width, Sticky, Elevated --- */
.app-header {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 1000;
  background: #0b1220;
  border-bottom: 1px solid #1f2937;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  padding-top: env(safe-area-inset-top, 0);
}
body { padding-top: 0; }

.app-header .title-area { width: 100%; display: flex; align-items: center; gap: 12px; }
.app-header .title-area .logo { flex-shrink: 0; }
.app-header .title-area h1 { margin: 0; }
.app-header .title-area .subtitle { margin: 0; opacity: .85; }

main { padding-top: 8px; }


/* --- Preserve newlines in textual content --- */
.note, .info-text, .modal .info-body .preview, .card .notes, .read-only-text {
  white-space: pre-wrap; /* keep \n as line breaks */
  word-break: break-word;
}
