/*
 * Medicine: the section, its modals (add, delete scheduled) and the
 * "next medicine" strip shown above the tabs. The section comes first, in
 * the order it had in style.css, so its responsive rules still win.
 */

/* Medicine Section Styles */

/* Stato dei promemoria push. Il colore segue la gravità: quando serve un
   passo dell'utente (installare la PWA, sbloccare le notifiche) deve leggersi
   come un avviso, non come una nota di servizio. */
.medicine-push-status {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 10px;
  border-left: 4px solid var(--neutral-300, var(--border-default));
  background: var(--neutral-100, var(--neutral-100));
}

.medicine-push-text {
  flex: 1 1 16rem;
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--neutral-700, var(--fg-muted));
}

.medicine-push-text[data-push-status="enabled"] {
  color: var(--success-text);
}

.medicine-push-status:has([data-push-status="enabled"]) {
  border-left-color: var(--m-steps);
  background: var(--success-surface);
}

.medicine-push-status:has([data-push-status="iosInstallRequired"]),
.medicine-push-status:has([data-push-status="blocked"]) {
  border-left-color: var(--warning);
  background: var(--warning-surface);
}

.medicine-date-selector {
  display: flex;
  gap: 10px;
  margin-bottom: 25px;
  align-items: center;
}

.medicine-date-selector input {
  padding: 10px;
  border: 2px solid var(--neutral-200);
  border-radius: 8px;
  font-size: 14px;
}

.medicines-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-bottom: 25px;
}

.medicine-content-area {
  min-height: 60px;
  margin-bottom: 15px;
}

.no-medicine {
  color: var(--neutral-600);
  font-style: italic;
  text-align: center;
  padding: 20px;
}

.medicine-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-card);
  border: 1px solid var(--neutral-200);
  border-left: 4px solid var(--neutral-200);
  border-radius: 8px;
  padding: 12px 15px;
  margin-bottom: 10px;
}

/* One row per dose, read from the clock: past fades, the next one carries the
   metric colour. The word "Prossima" says it too, colour is never the only cue. */
/* Faded by colour, not by opacity: opacity 0.7 took the secondary text of a
   past dose to 3.2:1, under AA. The muted tokens stay readable. */
.medicine-item[data-state="past"] {
  background: transparent;
}

.medicine-item[data-state="past"] .medicine-time,
.medicine-item[data-state="past"] .medicine-name {
  color: var(--fg-muted);
}

.medicine-item[data-state="next"] {
  background: var(--metric-surface, var(--m-medicine-surface));
  border-color: var(--metric-border, var(--m-medicine-border));
  border-left-color: var(--metric, var(--m-medicine));
}

/* Taken (N5): the check icon and the words "Presa alle" carry it, the green
   edge only echoes them. */
.medicine-item[data-state="taken"] {
  border-left-color: var(--success);
}

.medicine-taken-line {
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--success-text);
  font-size: 0.85rem;
  font-weight: 600;
}

.medicine-actions {
  align-items: center;
  flex: none;
  display: flex;
  gap: 5px;
}

.medicine-next-label {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-card);
  border: 1px solid var(--metric, var(--m-medicine));
  color: var(--metric-text, var(--m-medicine-text));
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: middle;
}

.scheduled-indicator,
.notification-indicator {
  display: inline-block;
  font-size: 0.9rem;
  margin-left: 8px;
  opacity: 0.8;
}

.medicine-time {
  flex: none;
  min-width: 4.2ch;
  color: var(--metric-text, var(--m-medicine-text));
  font-weight: 700;
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
}

.medicine-main {
  flex: 1;
  min-width: 0;
}

.medicine-item h4 {
  color: var(--neutral-900);
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  overflow-wrap: break-word;
}

.medicine-meta {
  margin: 2px 0 0;
  color: var(--neutral-600);
  font-size: 0.85rem;
  overflow-wrap: break-word;
}

/* Medicine Modal */
.medicine-modal {
  background: var(--surface-card);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow:
    var(--elevation-3);
  border: 1px solid var(--border-subtle);
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.medicine-modal::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--gradient-hairline);
  background-size: 200% 100%;
  animation: gradientShift 3s ease infinite;
  border-radius: 20px 20px 0 0;
}

.medicine-modal .modal-content input,
.medicine-modal .modal-content textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--neutral-200);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 15px;
  transition: border-color 0.3s;
}

.medicine-modal .modal-content input:focus,
.medicine-modal .modal-content textarea:focus,
.medicine-modal .modal-content select:focus {
  outline: none;
  border-color: var(--m-pressure);
}

.schedule-section {
  margin-bottom: 15px;
}

.schedule-section label {
  display: block;
  margin-bottom: 5px;
  color: var(--neutral-700);
  font-weight: 500;
  font-size: 14px;
}

.schedule-section select {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--neutral-200);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface-card);
  transition: border-color 0.3s;
  margin-bottom: 10px;
}

.custom-days-input {
  margin-top: 10px;
}

.custom-days-input label {
  font-size: 13px;
  margin-bottom: 5px;
}

.custom-days-input input {
  width: 80px;
  padding: 8px;
  border: 2px solid var(--neutral-200);
  border-radius: 6px;
  font-size: 14px;
}

/* Notification Section */
.notification-section {
  margin-bottom: 15px;
  padding: 15px;
  /* --warning-surface, non --warning-border: il testo qui dentro e'
     --warning-text, che e' calibrato sulla superficie. Sul colore del bordo
     scendeva a 3.86:1, sotto il minimo AA per il testo normale; sulla
     superficie sta a 5.93:1. */
  background-color: var(--warning-surface);
  border: 2px solid var(--accent-500);
  border-radius: 8px;
}

.notification-checkbox {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--warning-text);
  margin-bottom: 8px;
}

.notification-checkbox input[type="checkbox"] {
  margin-right: 10px;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.notification-hint {
  font-size: 12px;
  color: var(--warning-text);
  margin: 0 0 10px 0;
  font-style: italic;
}

/* Responsive per mobile */
@media (max-width: 768px) {
  .notification-section {
    padding: 12px;
  }

  .notification-checkbox {
    font-size: 13px;
    margin-bottom: 10px;
  }

  .notification-hint {
    font-size: 11px;
    margin-bottom: 12px;
  }
}

/* Responsive Medicine Section */
@media (max-width: 768px) {
  .medicine-date-selector {
    flex-direction: column;
    align-items: stretch;
  }

  .medicine-time {
    font-size: 1.2rem;
  }
}

/* On a phone the time, the name and the buttons on one line left the name
   about 80px: "Metformina" broke mid-word. The time takes its own line above
   the name, and the buttons ("Presa", edit, delete) one below it. */
@media (max-width: 480px) {
  .medicine-item {
    flex-wrap: wrap;
    row-gap: 2px;
  }

  .medicine-time {
    flex-basis: 100%;
    font-size: 1rem;
  }

  .medicine-actions {
    flex-basis: 100%;
    justify-content: flex-end;
  }
}

/* Delete Scheduled Medicine Modal */
.delete-scheduled-modal {
  background: var(--surface-card);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  width: 90%;
  max-width: 470px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow:
    var(--elevation-3);
  border: 1px solid var(--border-subtle);
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.delete-scheduled-modal::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--gradient-hairline);
  background-size: 200% 100%;
  animation: gradientShift 3s ease infinite;
  border-radius: 20px 20px 0 0;
}

.delete-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
}

.delete-single {
  border-color: var(--accent-500);
  color: var(--warning-text);
}

.delete-single:hover {
  border-color: var(--warning);
  background: var(--warning-surface);
}

.delete-all {
  border-color: var(--danger);
  color: var(--danger-text);
}

.delete-all:hover {
  border-color: var(--danger);
  background: var(--danger-surface);
}

/* Responsive Delete Modal */
@media (max-width: 768px) {
  .delete-scheduled-modal {
    width: 95%;
    margin: 20px;
  }

}

/* Next Medicine: striscia sottile, una riga (due sul telefono).
   Il fondo e' --surface-header, che resta scuro in entrambi i temi, e il testo
   --fg-on-solid, chiaro sempre: non sono gradini di rampa, che si specchiano. */
/* A <section>, so the legacy `section` card rule reaches it: reset it here,
   or the strip sits inside a white padded card. */
.next-medicine-section {
  margin-bottom: var(--space-4);
  background: none;
  padding: 0;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.next-medicine-box {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  min-height: 44px;
  background: var(--surface-header);
  border-radius: var(--radius-lg);
  color: var(--fg-on-solid);
  box-shadow: var(--elevation-1);
}

.next-medicine-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--on-brand-surface-strong);
  font-size: 1rem;
}

.next-medicine-line {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: var(--space-2);
  line-height: 1.3;
}

/* Il nome non si spezza a meta' parola: se non sta va a capo intero. */
.next-medicine-name {
  /* ds-base.css colours every <strong> with --fg-default, dark on dark here. */
  color: var(--fg-on-solid);
  font-weight: 700;
  overflow-wrap: normal;
}

.next-medicine-time {
  opacity: 0.9;
  font-size: 0.9rem;
}

.next-medicine-btn {
  flex-shrink: 0;
}
