
  :root {
    --bg: #14110f;
    --surface: #1c1916;
    --surface-2: #252119;
    --border: #2e2a23;
    --border-soft: #25211c;
    --text: #f4f0e8;
    --text-muted: #a8a096;
    --text-dim: #706a5f;

    --train: #f97316;
    --train-soft: rgba(249, 115, 22, 0.12);
    --train-glow: rgba(249, 115, 22, 0.25);

    --nutri: #9ac428;
    --nutri-soft: rgba(154, 196, 40, 0.12);
    --nutri-glow: rgba(154, 196, 40, 0.25);

    --accent: var(--train);
    --accent-soft: var(--train-soft);
    --accent-glow: var(--train-glow);

    --radius: 14px;
    --radius-lg: 20px;

    --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
    --sans: "Manrope", -apple-system, BlinkMacSystemFont, sans-serif;
  }

  body[data-mode="alimentazione"] {
    --accent: var(--nutri);
    --accent-soft: var(--nutri-soft);
    --accent-glow: var(--nutri-glow);
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  html {
    /* Impedisce a Safari iOS di scalare il testo automaticamente al cambio orientamento */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
  }

  /* ---------- Layout ---------- */
  .app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    position: relative;
  }

  /* ---------- Header ---------- */
  header {
    padding: max(env(safe-area-inset-top), 14px) 18px 12px;
    border-bottom: 1px solid var(--border-soft);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-shrink: 0;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .brand-mark {
    font-family: var(--serif);
    font-weight: 600;
    font-size: 22px;
    letter-spacing: -0.02em;
    font-style: italic;
    color: var(--accent);
    transition: color 0.3s ease;
  }
  .brand-name {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 18px;
    letter-spacing: -0.01em;
  }
  .brand-profile-btn {
    width: 44px;
    margin-left: 7px;
    padding-left: 10px;
    border-left: 1px solid var(--border);
    border-radius: 0;
    color: var(--text);
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  /* Icone che appaiono solo in una modalità specifica */
  .icon-btn.mode-only { display: none; }
  body[data-mode="allenamento"] .icon-btn.mode-only[data-only-mode="allenamento"] { display: inline-flex; }
  body[data-mode="alimentazione"] .icon-btn.mode-only[data-only-mode="alimentazione"] { display: inline-flex; }

  /* Icon button con badge (indicatore notifica in alto a destra) */
  .icon-btn { position: relative; }
  .icon-btn .icon-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ef4444;
    border: 1.5px solid var(--bg);
    display: none;
    animation: pulse-badge 2s ease-in-out infinite;
  }
  .icon-btn[data-has-alert="true"] .icon-badge { display: block; }
  @keyframes pulse-badge {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.7; }
  }

  .hint-block {
    display: block;
    margin: -4px 0 12px;
    color: var(--text-dim);
    font-size: 11.5px;
    font-style: italic;
  }

  /* Profilo personale: dati fisici numerici in riga (3 colonne) */
  .profile-numbers {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 4px;
  }
  .profile-numbers .field-compact { margin: 0; }
  .profile-numbers .field-compact input { max-width: none; width: 100%; }
  @media (max-width: 450px) {
    .profile-numbers { gap: 6px; }
    .profile-numbers .field-compact label { font-size: 11px; }
  }

  /* Sex pills (radio gruppo) */
  .sex-pills {
    display: flex;
    width: 100%;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
  }
  .sex-pill {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    padding: 7px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s ease;
    letter-spacing: 0.01em;
  }
  .sex-pill:hover {
    color: var(--text);
  }
  .sex-pill[aria-checked="true"] {
    color: var(--text);
    border-color: var(--text);
  }

  /* ---------- Routine settimanale strutturata ---------- */
  #weeklyRoutineContainer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
  }

  .day-routine-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 12px 14px;
  }

  .day-routine-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
  }
  .day-routine-label {
    font-family: var(--sans);
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text);
  }
  .day-routine-work {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 0.02em;
  }
  .day-work-select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text);
    font-family: var(--sans);
    cursor: pointer;
    transition: border-color 0.15s ease;
  }
  .day-work-select:focus {
    outline: none;
    border-color: var(--accent);
  }

  .day-activities {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
  }
  .day-activities-empty {
    font-size: 12px;
    color: var(--text-dim);
    font-style: italic;
    padding: 4px 0;
  }

  .activity-row {
    display: grid;
    grid-template-columns: 1fr 88px 70px 32px;
    gap: 8px;
    align-items: center;
  }
  .activity-row input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 9px;
    font-size: 13px;
    color: var(--text);
    font-family: var(--sans);
    transition: border-color 0.15s ease;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    /* Disabilito lo styling nativo iOS che aggiunge padding/decorazioni invisibili */
    -webkit-appearance: none;
    appearance: none;
  }
  .activity-row input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface);
  }
  .activity-sport { font-weight: 500; }
  .activity-time {
    font-variant-numeric: tabular-nums;
    text-align: center;
  }

  .activity-duration-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
  }
  .activity-duration {
    padding-right: 28px !important;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
  .activity-duration-unit {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: var(--text-dim);
    pointer-events: none;
    font-weight: 600;
  }

  .activity-delete {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    padding: 5px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
  }
  .activity-delete:hover {
    color: var(--text);
    background: var(--surface-2);
  }
  .activity-delete svg {
    width: 14px;
    height: 14px;
  }

  .add-activity-btn {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-family: var(--sans);
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    width: 100%;
    transition: all 0.15s ease;
  }
  .add-activity-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  /* Routine: stesso layout desktop su tutte le dimensioni (4 elementi in una riga).
     Niente media query: il layout grid 1fr 90px 90px 32px funziona bene anche su mobile. */

  /* Tracking block (solo allenamento) */
  .tracking-block {
    display: none;
    border-top: 1px dashed var(--border-soft);
    margin-top: 6px;
    padding-top: 10px;
  }
  body[data-mode="allenamento"] .tracking-block { display: block; }
  .tracking-field input {
    max-width: 180px;
  }
  .checkup-warn {
    color: #fbbf24 !important;
    font-weight: 500;
  }
  .checkup-overdue {
    color: #ef4444 !important;
    font-weight: 600;
  }
  .checkup-ok {
    color: var(--text-dim);
  }

  .icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
  }
  .icon-btn:hover { color: var(--text); border-color: var(--accent); }
  .icon-btn svg { width: 18px; height: 18px; }

  /* Override per icona profilo: bordo sempre bianco al hover, mai colorato col tema sezione */
  .brand-profile-btn:hover,
  .brand-profile-btn:focus,
  .brand-profile-btn:active {
    color: var(--text);
    border-color: var(--text);
    border-radius: 10px;
    background: var(--surface);
  }
  .brand-profile-btn:hover svg,
  .brand-profile-btn:focus svg,
  .brand-profile-btn:active svg {
    color: var(--text);
  }

  /* ---------- Mode toggle ---------- */
  .mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 10px 14px 6px;
    gap: 6px;
    flex-shrink: 0;
  }
  .mode-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 14px;
    color: var(--text-muted);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.01em;
  }
  .mode-btn .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: background 0.2s ease;
  }
  .mode-btn[data-active="true"] {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 1px var(--accent) inset, 0 4px 20px -8px var(--accent-glow);
  }
  .mode-btn[data-active="true"] .dot { background: var(--accent); }
  .mode-btn[data-mode="allenamento"][data-active="true"] .dot { background: var(--train); }
  .mode-btn[data-mode="alimentazione"][data-active="true"] .dot { background: var(--nutri); }
  .mode-btn:hover:not([data-active="true"]) { color: var(--text); }

  /* ---------- Messages ---------- */
  .messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
  }

  .empty-state {
    margin: auto;
    text-align: center;
    max-width: 340px;
    padding: 30px 20px;
    color: var(--text-muted);
  }
  .empty-state h2 {
    font-family: var(--serif);
    font-weight: 500;
    font-style: italic;
    font-size: 26px;
    letter-spacing: -0.02em;
    color: var(--text);
    margin: 0 0 8px;
  }
  .empty-state p {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
  }
  .empty-state .accent { color: var(--accent); font-weight: 600; font-style: normal; }

  .msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: fadeUp 0.3s ease;
  }
  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .msg.user {
    align-self: flex-end;
    align-items: flex-end;
  }
  .msg.assistant { align-self: flex-start; }

  .bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
  }
  .msg.user .bubble {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    color: var(--text);
    border-bottom-right-radius: 6px;
  }
  .msg.assistant .bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
  }
  .msg-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: 5px;
    padding: 0 4px;
  }
  .msg.assistant .msg-label { color: var(--accent); }

  .msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .msg.assistant:hover .msg-actions,
  .msg.assistant:focus-within .msg-actions { opacity: 1; }
  @media (hover: none) {
    .msg-actions { opacity: 1; }
  }
  .msg-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .msg-action-btn:hover { color: var(--text); border-color: var(--accent); }
  .msg-action-btn[disabled] { opacity: 0.5; cursor: wait; }
  .msg-action-btn svg { width: 12px; height: 12px; }
  .msg-action-btn.saved { color: var(--accent); border-color: var(--accent); }

  .typing {
    display: inline-flex;
    gap: 4px;
    padding: 14px 16px;
  }
  .typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.2s infinite ease-in-out;
  }
  .typing span:nth-child(2) { animation-delay: 0.15s; }
  .typing span:nth-child(3) { animation-delay: 0.3s; }
  @keyframes pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
  }

  /* ---------- Composer ---------- */
  .composer {
    padding: 10px 14px max(env(safe-area-inset-bottom), 14px);
    border-top: 1px solid var(--border-soft);
    background: var(--bg);
    flex-shrink: 0;
  }
  .composer-inner {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 14px;
    transition: border-color 0.2s ease;
  }
  .composer-inner:focus-within { border-color: var(--accent); }

  #prompt {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.45;
    padding: 9px 0;
    resize: none;
    max-height: 160px;
    min-height: 22px;
  }
  #prompt::placeholder { color: var(--text-dim); }

  .send-btn {
    width: 38px; height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease, opacity 0.2s ease;
    flex-shrink: 0;
  }
  .send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
  .send-btn:not(:disabled):active { transform: scale(0.92); }
  .send-btn svg { width: 18px; height: 18px; }

  /* ---------- Settings panel ---------- */
  .backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 40;
    backdrop-filter: blur(3px);
  }
  .backdrop.open { opacity: 1; pointer-events: auto; }

  .panel {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    width: min(460px, 100%);
    background: var(--bg);
    border-left: 1px solid var(--border);
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.3, 0.85, 0.3, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .panel.open { transform: translateX(0); }

  .panel-header {
    padding: max(env(safe-area-inset-top), 18px) 20px 14px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
  }
  .panel-header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
  }
  .panel-title {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 0.01em;
    margin: 0;
  }
  .panel-body {
    overflow-y: auto;
    padding: 18px 20px max(env(safe-area-inset-bottom), 20px);
    display: flex;
    flex-direction: column;
    gap: 22px;
  }

  .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .field label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
  }
  .field .hint {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.5;
    margin-top: 2px;
  }
  .field .hint a { color: var(--accent); text-decoration: none; }
  .field .hint a:hover { text-decoration: underline; }

  input[type="text"], input[type="password"], input[type="number"], input[type="time"], input[type="date"], input[type="email"], textarea, select {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease;
    color-scheme: dark;
  }
  input:focus, textarea:focus, select:focus { border-color: var(--accent); }
  textarea { resize: vertical; min-height: 90px; line-height: 1.5; }

  .section-heading {
    font-family: var(--serif);
    font-size: 15px;
    font-weight: 500;
    font-style: italic;
    letter-spacing: -0.01em;
    color: var(--accent);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-soft);
    margin: 4px 0 0;
  }
  /* Pannello profilo: cross-sezione, scritte neutre (non colorate) */
  #profilePanel .section-heading {
    color: var(--text);
  }
  /* Tutti gli input/textarea/select del pannello profilo hanno focus bianco */
  #profilePanel input:focus,
  #profilePanel textarea:focus,
  #profilePanel select:focus,
  #profilePanel .day-work-select:focus,
  #profilePanel .activity-row input:focus {
    border-color: var(--text);
    background: var(--surface);
    box-shadow: none;
  }
  #profilePanel .add-activity-btn:hover {
    color: var(--text);
    border-color: var(--text);
    background: var(--surface-2);
  }
  #profilePanel .activity-delete:hover {
    color: var(--text);
    background: var(--surface-2);
  }

  .btn-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  .btn {
    padding: 9px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .btn:hover { border-color: var(--accent); }
  .btn.danger:hover { border-color: #dc2626; color: #fca5a5; }

  .error {
    margin: 6px 16px 0;
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(220, 38, 38, 0.12);
    border: 1px solid rgba(220, 38, 38, 0.4);
    color: #fca5a5;
    font-size: 13px;
    line-height: 1.45;
  }
  .error[hidden] { display: none; }

  /* ---------- Scrollbars ---------- */
  .messages::-webkit-scrollbar, .panel-body::-webkit-scrollbar { width: 6px; }
  .messages::-webkit-scrollbar-thumb, .panel-body::-webkit-scrollbar-thumb {
    background: var(--border); border-radius: 3px;
  }

  /* ---------- Plans panel ---------- */
  .plans-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .plan-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .plan-card:hover { border-color: var(--accent); }
  .plan-card .plan-title {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.01em;
    color: var(--text);
  }
  .plan-card .plan-meta {
    font-size: 12px;
    color: var(--text-dim);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }
  .plan-card .plan-meta .warn { color: #fbbf24; }

  .plan-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-soft);
  }
  .card-action {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 3px 6px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s ease;
  }
  .card-action:hover { color: var(--accent); background: var(--accent-soft); }
  .card-action.danger:hover { color: #fca5a5; background: rgba(220, 38, 38, 0.08); }

  .plans-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 14px;
    line-height: 1.55;
  }
  .plans-empty h3 {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 0.01em;
    color: var(--text);
    margin: 0 0 8px;
  }

  .plan-detail { display: flex; flex-direction: column; gap: 14px; }
  .plan-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
  }
  .plan-detail-header h3 {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 0.01em;
    margin: 0 0 2px;
    color: var(--text);
  }
  .plan-detail-header .plan-meta { font-size: 12px; color: var(--text-dim); }
  .back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--sans);
  }
  .back-btn:hover { color: var(--text); border-color: var(--accent); }
  .back-btn svg { width: 12px; height: 12px; }

  .plan-rendered {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 16px 18px;
    font-size: 14px;
    line-height: 1.6;
    overflow-x: auto;
  }
  .plan-rendered h1, .plan-rendered h2, .plan-rendered h3 {
    font-family: var(--sans);
    font-weight: 600;
    letter-spacing: 0.01em;
    margin: 16px 0 8px;
    color: var(--text);
  }
  .plan-rendered h1 { font-size: 20px; }
  .plan-rendered h2 { font-size: 17px; color: var(--accent); }
  .plan-rendered h3 { font-size: 15px; }
  .plan-rendered p { margin: 0 0 10px; }
  .plan-rendered ul, .plan-rendered ol { margin: 0 0 10px; padding-left: 22px; }
  .plan-rendered li { margin-bottom: 4px; }
  .plan-rendered table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
  }
  .plan-rendered th, .plan-rendered td {
    border: 1px solid var(--border);
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
  }
  .plan-rendered th {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--nutri);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .plan-rendered strong { color: var(--text); }
  .plan-rendered code {
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12.5px;
  }

  /* ---------- Pantry (Dispensa) ---------- */
  .pantry-add {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
  }
  .pantry-add input {
    flex: 1;
    margin: 0;
  }
  .pantry-add button {
    flex-shrink: 0;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--nutri);
    background: var(--nutri-soft);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .pantry-add button:hover { background: rgba(154, 196, 40, 0.2); }
  .pantry-add button:disabled { opacity: 0.4; cursor: not-allowed; }

  .pantry-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--text-dim);
  }
  .pantry-toolbar .count { font-weight: 600; color: var(--text-muted); }
  .pantry-toolbar .quick-actions {
    display: flex;
    gap: 6px;
  }
  .pantry-toolbar .quick-actions button {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    padding: 2px 4px;
    font-family: var(--sans);
    transition: color 0.15s ease;
  }
  .pantry-toolbar .quick-actions button:hover { color: var(--nutri); }
  .pantry-toolbar .quick-actions .sep { color: var(--border); }

  /* ---------- Sort menu (icona + dropdown) ---------- */
  .sort-menu {
    position: relative;
    display: inline-flex;
    align-items: center;
  }
  .sort-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, background 0.15s ease;
  }
  .sort-btn:hover {
    color: var(--text);
    background: var(--surface-2);
  }
  .sort-btn svg { width: 16px; height: 16px; }
  .sort-btn[aria-expanded="true"] {
    color: var(--text);
    background: var(--surface-2);
  }

  .sort-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    padding: 4px;
    min-width: 140px;
    z-index: 50;
    display: none;
    flex-direction: column;
    gap: 2px;
  }
  .sort-dropdown.open {
    display: flex;
  }
  .sort-option {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--sans);
    font-size: 13px !important;
    font-weight: 500 !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    text-align: left !important;
    padding: 7px 12px !important;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.12s ease;
  }
  .sort-option:hover {
    background: var(--surface-2);
    color: var(--text) !important;
  }

  /* ---------- Export modal ---------- */
  .export-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
  }
  .export-modal.open { display: flex; }

  .export-modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .export-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
  }
  .export-modal-header h2 {
    margin: 0;
    font-family: var(--serif);
    font-size: 22px;
    font-weight: 500;
    font-style: italic;
  }
  .export-modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
  }
  .export-modal-footer {
    display: flex;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
  }
  .export-modal-footer .btn.primary {
    background: var(--accent);
    color: #1a1814;
    border-color: var(--accent);
    font-weight: 600;
  }
  .export-modal-footer .btn.primary:hover {
    filter: brightness(1.1);
  }

  .export-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
  }
  .export-option {
    display: grid;
    grid-template-columns: 24px 1fr;
    grid-template-rows: auto auto;
    gap: 0 10px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
  }
  .export-option:hover { background: var(--surface); }
  .export-option input[type="checkbox"] {
    grid-row: 1 / span 2;
    align-self: center;
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
  }
  .export-option-label {
    grid-column: 2;
    grid-row: 1;
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
  }
  .export-option-hint {
    grid-column: 2;
    grid-row: 2;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
  }

  .export-preview-wrap { display: flex; flex-direction: column; gap: 6px; }
  .export-preview-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
  }
  #exportPreview,
  #importMarkdown {
    width: 100%;
    box-sizing: border-box;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-family: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    resize: vertical;
    min-height: 160px;
  }
  #importMarkdown:focus,
  #importTitle:focus {
    outline: none;
    border-color: var(--accent);
  }
  #importTitle {
    width: 100%;
    box-sizing: border-box;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
  }

  @media (max-width: 500px) {
    .export-modal { padding: 0; }
    .export-modal-card { max-height: 100vh; max-width: 100%; border-radius: 0; }
    .export-modal-footer { flex-direction: column; }
    .export-modal-footer .btn { width: 100%; }
  }

  /* ---------- Toast notifications ---------- */
  .toast-container {
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: max-content;
    max-width: calc(100vw - 32px);
  }
  .toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 16px;
    color: var(--text);
    font-family: var(--sans);
    font-size: 13.5px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: auto;
    text-align: center;
    max-width: 100%;
  }
  .toast.show {
    opacity: 1;
    transform: translateY(0);
  }
  .toast.toast-warning {
    border-color: rgba(251, 191, 36, 0.4);
    background: linear-gradient(180deg, var(--surface), rgba(251, 191, 36, 0.04));
  }
  .toast.toast-info {
    border-color: var(--border);
  }

  .pantry-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .pantry-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: all 0.15s ease;
  }
  .pantry-item[data-selected="false"] {
    opacity: 0.45;
    background: transparent;
  }
  .pantry-item .checkbox {
    width: 18px; height: 18px;
    border-radius: 5px;
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
  }
  .pantry-item[data-selected="true"] .checkbox {
    background: var(--nutri);
    border-color: var(--nutri);
  }
  .pantry-item[data-selected="true"] .checkbox svg {
    width: 11px; height: 11px;
    color: var(--bg);
    stroke-width: 3;
  }
  .pantry-item .checkbox svg { display: none; }
  .pantry-item[data-selected="true"] .checkbox svg { display: block; }

  .pantry-item .name {
    flex: 1;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
  }
  .pantry-item[data-selected="false"] .name {
    text-decoration: line-through;
    color: var(--text-muted);
  }
  .pantry-item .delete-btn {
    width: 28px; height: 28px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0;
    transition: all 0.15s ease;
  }
  .pantry-item:hover .delete-btn { opacity: 1; }
  @media (hover: none) {
    .pantry-item .delete-btn { opacity: 0.6; }
  }
  .pantry-item .delete-btn:hover { color: #fca5a5; background: rgba(220, 38, 38, 0.1); }
  .pantry-item .delete-btn svg { width: 14px; height: 14px; }

  .pantry-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 30px 20px;
    font-size: 13px;
  }

  /* ---------- Plan fullscreen modal ---------- */
  .plan-modal {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 200;
    display: none;
    flex-direction: column;
    overflow: hidden;
  }
  .plan-modal.open { display: flex; }

  .plan-modal-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .plan-modal-header .title-block { min-width: 0; flex: 1; }
  .plan-modal-header h2 {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.01em;
    color: var(--text);
    margin: 0 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .plan-modal-header .meta {
    font-size: 12px;
    color: var(--text-dim);
  }
  .plan-modal-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
  }
  .plan-modal-actions .download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 11px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .plan-modal-actions .download-btn:hover {
    color: var(--text);
    border-color: var(--accent);
  }
  .plan-modal-actions .download-btn svg { width: 13px; height: 13px; }

  /* ---------- Stopwatch button ---------- */
  /* Usa la variabile --train (arancione) per essere coerente con la sezione Allenamento */
  .stopwatch-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid rgba(249, 115, 22, 0.4);
    background: rgba(249, 115, 22, 0.12);
    color: var(--train);
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  .stopwatch-btn:hover {
    border-color: var(--train);
    background: rgba(249, 115, 22, 0.18);
  }
  .stopwatch-btn .stopwatch-icon,
  .stopwatch-btn .stopwatch-pause-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }
  .stopwatch-btn .stopwatch-time {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    min-width: 38px;
    text-align: left;
  }

  /* Stato: in corso (sfondo pieno arancione, testo scuro) */
  .stopwatch-btn.running {
    background: var(--train);
    border-color: var(--train);
    color: #1a1814;
  }
  .stopwatch-btn.running:hover {
    background: var(--train);
    filter: brightness(1.08);
  }
  .stopwatch-btn.running .stopwatch-icon { display: none; }
  .stopwatch-btn.running .stopwatch-pause-icon { display: inline-block; }

  /* Stato: in pausa (outline arancione, tempo congelato visibile) */
  .stopwatch-btn.paused {
    background: rgba(249, 115, 22, 0.06);
    border-color: rgba(249, 115, 22, 0.5);
    color: var(--train);
  }
  /* In pausa mostra l'icona stopwatch normale (non pause), così lo stato visivo è chiaro */
  .stopwatch-btn.paused .stopwatch-icon { display: inline-block; }
  .stopwatch-btn.paused .stopwatch-pause-icon { display: none; }

  /* Feedback long-press: piccola contrazione */
  .stopwatch-btn:active { transform: scale(0.97); }

  .plan-modal-body {
    flex: 1;
    overflow: auto;
    padding: 24px 32px 40px;
    padding-left: calc(32px + env(safe-area-inset-left));
    padding-right: calc(32px + env(safe-area-inset-right));
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
  }

  /* Il markdown nel modale è più generoso (non riusa .plan-rendered del pannello) */
  .plan-fullscreen-content {
    max-width: 1200px;
    margin: 0 auto;
    font-size: 15px;
    line-height: 1.65;
    color: var(--text);
  }
  .plan-fullscreen-content h1,
  .plan-fullscreen-content h2,
  .plan-fullscreen-content h3 {
    font-family: var(--sans);
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text);
    margin: 20px 0 12px;
  }
  .plan-fullscreen-content h1 { font-size: 26px; margin-top: 0; }
  .plan-fullscreen-content h2 { font-size: 20px; color: var(--accent); }
  .plan-fullscreen-content h3 { font-size: 16px; }
  .plan-fullscreen-content p { margin: 0 0 12px; }
  .plan-fullscreen-content ul,
  .plan-fullscreen-content ol { margin: 0 0 14px; padding-left: 24px; }
  .plan-fullscreen-content li { margin-bottom: 5px; }
  .plan-fullscreen-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 14px;
    background: var(--surface);
    border-radius: 10px;
    overflow: hidden;
  }
  .plan-fullscreen-content th,
  .plan-fullscreen-content td {
    border: 1px solid var(--border);
    padding: 12px 14px;
    text-align: left;
    vertical-align: top;
  }
  .plan-fullscreen-content th {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--accent);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
  }
  .plan-fullscreen-content td:first-child {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
  }
  .plan-fullscreen-content strong { color: var(--text); }
  .plan-fullscreen-content code {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
  }

  /* ---------- Workout cards (stili specifici per schede allenamento) ---------- */
  .workout-params {
    font-size: 12px;
    color: var(--text-dim);
    margin: -6px 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px dashed var(--border-soft);
    letter-spacing: 0.02em;
  }
  .exercise-row {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-soft);
  }
  .exercise-row:last-child { border-bottom: none; }
  .exercise-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
  }
  .exercise-params {
    margin-bottom: 5px;
  }
  .exercise-params .chip {
    display: inline-block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.03em;
  }
  .exercise-note {
    font-size: 12.5px;
    color: var(--text-dim);
    line-height: 1.45;
    font-style: italic;
  }

  /* ---------- Workout interactive schedule ---------- */
  .plan-fullscreen-content.workout-view {
    max-width: 900px;
  }
  .schedule-badge-row {
    margin: -4px 0 14px;
  }
  .schedule-badge-active {
    display: inline-block;
    background: var(--train-soft);
    color: var(--train);
    border: 1px solid var(--train);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
  .active-tag {
    color: var(--train) !important;
    font-weight: 600;
  }

  .workout-exercises {
    padding: 0;
  }
  .wo-exercise {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "head inputs" "note note";
    gap: 10px 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-soft);
    align-items: start;
  }
  .wo-exercise:last-child { border-bottom: none; }

  .wo-ex-head {
    grid-area: head;
    display: flex;
    gap: 12px;
    align-items: center;
    min-width: 0;
  }
  .wo-ex-icon {
    width: 52px;
    height: 46px;
    flex-shrink: 0;
    border-radius: 8px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid var(--border);
  }
  .wo-ex-icon img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }
  .wo-ex-icon-empty {
    background: var(--surface-2);
  }

  .wo-ex-info {
    min-width: 0;
    flex: 1;
  }
  .wo-ex-name {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.01em;
    color: var(--text);
    line-height: 1.3;
  }
  .wo-ex-schema {
    display: inline-block;
    margin-top: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 9px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.03em;
  }

  .wo-ex-inputs {
    grid-area: inputs;
    display: flex;
    gap: 10px;
    align-items: center;
  }
  .wo-input-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }
  .wo-input-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
  }
  .wo-input-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
  }
  .wo-input {
    width: 72px;
    padding: 7px 28px 7px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    text-align: right;
    transition: all 0.15s ease;
  }
  .wo-input.wo-reps { padding-right: 10px; }
  .wo-input:focus {
    outline: none;
    border-color: var(--train);
    background: var(--surface);
  }
  .wo-input-unit {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--text-dim);
    pointer-events: none;
    font-weight: 600;
  }
  .wo-input.wo-input-saved {
    border-color: var(--train);
    background: var(--train-soft);
  }

  .wo-ex-note {
    grid-area: note;
    font-size: 12.5px;
    color: var(--text-dim);
    font-style: italic;
    line-height: 1.45;
    padding-left: 64px; /* allinea con l'inizio del testo, non dell'icona */
  }

  .workout-extra-notes {
    margin-top: 20px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.55;
  }
  .workout-extra-notes h2 {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.01em;
    margin: 0 0 8px;
    color: var(--text);
  }
  .workout-extra-notes ul { margin: 0; padding-left: 20px; }
  .workout-extra-notes li { margin-bottom: 4px; color: var(--text-muted); }

  @media (max-width: 600px) {
    .wo-exercise {
      grid-template-columns: 1fr;
      grid-template-areas: "head" "inputs" "note";
      gap: 8px;
      padding: 14px 14px 16px;
    }
    .wo-ex-inputs {
      margin-left: 64px;
      gap: 12px;
      justify-content: flex-start;
    }
    .wo-ex-note { padding-left: 64px; }
    .wo-input-group {
      flex: 0 0 auto;
      width: auto;
    }
    .wo-input-wrap {
      width: auto;
    }
    .wo-input {
      width: 80px;
      font-size: 14px;
      padding: 6px 26px 6px 8px;
    }
    .wo-input.wo-reps {
      width: 70px;
      padding-right: 8px;
    }
    .wo-input-unit { right: 8px; font-size: 10px; }
  }
  @media (max-width: 420px) {
    .wo-ex-inputs {
      margin-left: 0;
      flex-wrap: nowrap;
      gap: 10px;
      align-items: flex-end;
      justify-content: flex-start;
    }
    .wo-ex-note { padding-left: 0; }
    .wo-input-group { flex: 0 0 auto; width: auto; }
    .wo-input-wrap { width: auto; }
    .wo-input {
      width: 72px;
      font-size: 14px;
      padding: 6px 24px 6px 7px;
    }
    .wo-input.wo-reps {
      padding-right: 7px;
      width: 64px;
    }
    .wo-input-label { font-size: 9px; }
    .wo-input-unit { right: 6px; font-size: 9px; }
  }

  /* ---------- Plan modal: mobile cards view (accordion) ---------- */
  .plan-fullscreen-content.cards-view {
    max-width: 640px;
    font-size: 14px;
  }
  .plan-fullscreen-content.cards-view h1 {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 18px;
    letter-spacing: 0.01em;
    margin: 0 0 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
  }

  /* Toolbar apri/chiudi tutti */
  .cards-toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    justify-content: flex-end;
  }
  .cards-toolbar button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 5px 10px;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .cards-toolbar button:hover { color: var(--accent); border-color: var(--accent); }

  /* Accordion card (details/summary) */
  details.day-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 10px;
    overflow: hidden;
    transition: border-color 0.15s ease;
  }
  details.day-card[open] {
    border-color: var(--accent);
  }

  summary.day-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: background 0.15s ease;
  }
  /* Rimuovo il triangolino di default di summary su tutti i browser */
  summary.day-header::-webkit-details-marker { display: none; }
  summary.day-header::marker { display: none; content: ""; }

  summary.day-header:hover { background: var(--surface-2); }
  details.day-card[open] summary.day-header {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
  }

  .day-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    color: var(--accent);
    transition: transform 0.2s ease;
  }
  .day-chevron svg { width: 14px; height: 14px; }
  details.day-card[open] .day-chevron { transform: rotate(90deg); }

  .day-header-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
  }
  .day-name {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.01em;
    color: var(--text);
    line-height: 1.3;
  }
  details.day-card[open] .day-name { color: var(--accent); }
  .day-note {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-top: 3px;
    letter-spacing: 0.01em;
  }

  .day-meals {
    padding: 4px 0 6px;
  }
  .meal-row {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-soft);
    align-items: start;
  }
  .meal-row:last-child { border-bottom: none; }
  .meal-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    padding-top: 2px;
  }
  .meal-content {
    font-size: 14px;
    line-height: 1.45;
    color: var(--text);
  }

  /* Note/legenda aggiuntive in vista mobile */
  .plan-fullscreen-content.cards-view .mobile-extra-notes {
    margin-top: 22px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.55;
  }
  .plan-fullscreen-content.cards-view .mobile-extra-notes h2 {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.01em;
    margin: 0 0 8px;
    color: var(--text);
  }
  .plan-fullscreen-content.cards-view .mobile-extra-notes ul {
    margin: 0;
    padding-left: 20px;
  }
  .plan-fullscreen-content.cards-view .mobile-extra-notes li {
    margin-bottom: 4px;
    color: var(--text-muted);
  }

  /* Ottimizzazione per schermi molto stretti */
  @media (max-width: 420px) {
    .meal-row {
      grid-template-columns: 1fr;
      gap: 3px;
      padding: 10px 16px 12px;
    }
    .meal-label { padding-top: 0; }
    .plan-fullscreen-content.cards-view h1 { font-size: 16px; }
    .day-name { font-size: 14px; }
  }

  @media (max-width: 600px) {
    .plan-modal-header { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
    .plan-modal-header h2 { font-size: 15px; }
    .plan-modal-actions .download-btn span { display: none; }
    .plan-modal-actions .download-btn { padding: 7px 9px; }
    /* Stopwatch su mobile: padding più compatto ma il tempo resta sempre visibile */
    .stopwatch-btn { padding: 6px 10px; font-size: 12px; gap: 5px; }
    .stopwatch-btn .stopwatch-time { min-width: 34px; }
    .plan-modal-body { padding: 16px 14px 30px; }
    .plan-fullscreen-content { font-size: 13.5px; }
    .plan-fullscreen-content h1 { font-size: 20px; }
    .plan-fullscreen-content table { font-size: 12.5px; display: block; overflow-x: auto; }
    .plan-fullscreen-content th,
    .plan-fullscreen-content td { padding: 8px 10px; }
  }

  /* ---------- Print styles (PDF export via browser print dialog) ---------- */
  @media print {
    /* Formato pagina: A4 orizzontale con margini compatti per massimizzare spazio utile */
    @page {
      size: A4 landscape;
      margin: 10mm 8mm;
    }

    /* Tutto nascosto di default, eccetto il modale e le sue voci utili */
    body > *:not(.plan-modal) { display: none !important; }

    /* Il modale va smontato dalla sua posizione fixed per poter fluire naturalmente */
    .plan-modal {
      position: static !important;
      display: block !important;
      background: white !important;
      color: black !important;
      overflow: visible !important;
      height: auto !important;
      margin: 0 !important;
      padding: 0 !important;
    }
    /* Assicuro che html/body non abbiano margini che spingono il contenuto */
    html, body {
      margin: 0 !important;
      padding: 0 !important;
      height: auto !important;
      overflow: visible !important;
    }

    /* Header del modale: titolo + data compatti */
    .plan-modal-header {
      background: white !important;
      border-bottom: 0.5pt solid #bbb !important;
      padding: 0 0 3mm 0 !important;
      margin-bottom: 3mm !important;
    }
    .plan-modal-header h2 {
      color: black !important;
      font-size: 14pt !important;
      white-space: normal !important;
      margin: 0 0 1pt !important;
    }
    .plan-modal-header .meta { color: #555 !important; font-size: 8pt !important; }
    .plan-modal-actions { display: none !important; }

    /* Corpo del modale */
    .plan-modal-body {
      overflow: visible !important;
      padding: 0 !important;
      display: block !important;
    }
    .plan-fullscreen-content {
      max-width: none !important;
      color: black !important;
      font-size: 8.5pt !important;
      line-height: 1.35 !important;
    }
    .plan-fullscreen-content h1,
    .plan-fullscreen-content h2,
    .plan-fullscreen-content h3 { color: black !important; }
    .plan-fullscreen-content h1 {
      font-size: 12pt !important;
      margin: 0 0 4pt !important;
    }
    .plan-fullscreen-content h2 {
      font-size: 10pt !important;
      color: #555 !important;
      margin: 6pt 0 3pt !important;
    }
    .plan-fullscreen-content h3 { font-size: 9pt !important; margin: 5pt 0 2pt !important; }
    .plan-fullscreen-content p { margin: 0 0 4pt !important; }
    .plan-fullscreen-content ul,
    .plan-fullscreen-content ol {
      margin: 2pt 0 4pt !important;
      padding-left: 14pt !important;
      font-size: 8pt !important;
    }
    .plan-fullscreen-content li { margin-bottom: 1pt !important; }

    /* Tabelle compatte ma leggibili */
    .plan-fullscreen-content table {
      background: white !important;
      border-radius: 0 !important;
      page-break-inside: auto;
      border: 0.5pt solid #333 !important;
      margin: 4pt 0 !important;
      table-layout: fixed;
      width: 100% !important;
    }
    .plan-fullscreen-content tr { page-break-inside: avoid; }
    .plan-fullscreen-content th,
    .plan-fullscreen-content td {
      border: 0.4pt solid #999 !important;
      padding: 3pt 4pt !important;
      font-size: 7.5pt !important;
      line-height: 1.3 !important;
      color: black !important;
      background: white !important;
      word-wrap: break-word;
      overflow-wrap: break-word;
    }
    .plan-fullscreen-content th {
      background: #efefef !important;
      color: #222 !important;
      font-weight: 700 !important;
      font-size: 6.5pt !important;
      letter-spacing: 0.02em !important;
      padding: 3pt 4pt !important;
    }
    .plan-fullscreen-content td:first-child {
      background: #f7f7f7 !important;
      font-weight: 700 !important;
      font-size: 7.5pt !important;
    }
    /* <br> nelle celle più compatti */
    .plan-fullscreen-content td br { line-height: 1.1 !important; }

    /* Niente shadow, niente effetti */
    * { box-shadow: none !important; text-shadow: none !important; }

    /* --- Stampa scheda interattiva: compatta ma con carichi leggibili --- */
    .plan-fullscreen-content.workout-view { max-width: none !important; }
    .schedule-badge-row,
    .cards-toolbar { display: none !important; }
    .workout-params {
      font-size: 9pt !important;
      color: #555 !important;
      margin: 0 0 4mm !important;
      padding: 0 !important;
      border: none !important;
    }
    details.workout-day,
    details.day-card {
      background: white !important;
      border: 1px solid #ccc !important;
      border-radius: 0 !important;
      margin: 0 0 4mm !important;
    }
    details.day-card > summary.day-header {
      background: #efefef !important;
      border-bottom: 1px solid #999 !important;
      padding: 5pt 8pt !important;
      display: block !important;
    }
    details.day-card .day-chevron { display: none !important; }
    .day-name { font-size: 11pt !important; color: black !important; }
    .day-note { font-size: 9pt !important; color: #555 !important; }

    .wo-exercise {
      display: grid !important;
      grid-template-columns: 40px 1fr auto !important;
      grid-template-areas: "icon info inputs" "icon note note" !important;
      gap: 2pt 8pt !important;
      padding: 5pt 8pt !important;
      border-bottom: 1pt solid #ddd !important;
      page-break-inside: avoid;
    }
    .wo-ex-head {
      grid-area: auto !important;
      display: contents !important;
    }
    .wo-ex-icon {
      grid-area: icon;
      width: 36pt !important;
      height: 32pt !important;
      background: white !important;
      border: 1px solid #ddd !important;
    }
    .wo-ex-icon img { max-width: 100% !important; max-height: 100% !important; }
    .wo-ex-info {
      grid-area: info;
    }
    .wo-ex-name {
      font-size: 9.5pt !important;
      color: black !important;
    }
    .wo-ex-schema {
      background: white !important;
      color: #555 !important;
      font-size: 8pt !important;
      border: 1pt solid #999 !important;
      padding: 0 5pt !important;
    }
    .wo-ex-inputs {
      grid-area: inputs;
      display: flex !important;
      gap: 8pt !important;
      margin: 0 !important;
    }
    .wo-input-label {
      font-size: 7pt !important;
      color: #666 !important;
    }
    /* Trasformo gli input in "valori" leggibili */
    .wo-input {
      border: 1pt solid #999 !important;
      background: white !important;
      color: black !important;
      padding: 2pt 4pt !important;
      width: 50pt !important;
      font-size: 9.5pt !important;
      font-weight: 700 !important;
      text-align: center !important;
    }
    .wo-input::placeholder { color: #bbb !important; }
    .wo-input-unit {
      font-size: 8pt !important;
      color: #666 !important;
    }
    .wo-ex-note {
      grid-area: note;
      padding-left: 0 !important;
      font-size: 8.5pt !important;
      color: #555 !important;
    }
    .workout-extra-notes {
      background: white !important;
      border: 1pt solid #ccc !important;
      font-size: 9pt !important;
      margin-top: 4mm !important;
    }
    .workout-extra-notes h2 { font-size: 10pt !important; color: black !important; }
  }

  @media (max-width: 500px) {
    .brand-mark { font-size: 20px; }
    .brand-name { font-size: 16px; }
    .bubble { font-size: 14.5px; }
  }
