/* StandBy Mode Pro - Styles for Milestone 2 widgets
 *
 * Loads after css/a11y.css so reduced-motion and contrast rules win. Kept in a
 * separate file so the pre-existing three stylesheets stay untouched and the
 * diff against master remains reviewable.
 */

/* --- Shared: Milestone 2 widget shells ---------------------------------- */
/* .widget-panel has no padding of its own, so each container provides its
   own inset. Without this the headings sit flush against the panel edge and
   appear clipped. */
.alarm-container,
.note-container,
.habit-container {
  padding: 0.75rem 0.85rem;
}

/* --- Alarm widget ---------------------------------------------------- */

.alarm-container {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  font-size: 0.85rem;
}

.alarm-header {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.alarm-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.alarm-next {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-family: var(--font-mono);
}

.alarm-next__label { color: var(--text-primary); font-weight: 600; }
.alarm-next__time { color: var(--accent-color); font-weight: 700; }
.alarm-next__rel { color: var(--text-muted); font-size: 0.75rem; }
.alarm-next--empty { color: var(--text-muted); }

.alarm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.alarm-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  background: var(--bg-surface);
}

.alarm-item--off { opacity: 0.45; }

.alarm-item__main {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.alarm-item__time {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.alarm-item__label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alarm-item__meta { display: flex; gap: 0.25rem; }

.alarm-tag {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  padding: 0.05rem 0.3rem;
  border-radius: 9999px;
  background: rgba(59, 130, 246, 0.16);
  color: var(--accent-color);
  white-space: nowrap;
}

.alarm-item__controls { display: flex; gap: 0.2rem; }
.alarm-item__controls .btn-icon { min-width: 32px; min-height: 32px; }
.alarm-item__controls .btn-icon svg { width: 14px; height: 14px; }

/*
 * The enable/disable toggle and the delete button.
 *
 * Both were emitted by the markup with no rule of their own, so they inherited
 * `.btn-icon` and looked identical whether an alarm was on or off. The toggle
 * carries `aria-pressed`, so a screen reader announced the state while the
 * display showed nothing - which is worse than having no state, because the
 * reader is told something the display contradicts.
 *
 * State is carried by opacity and a rule, not by colour alone, so it survives a
 * greyscale screenshot.
 */
.alarm-toggle {
  opacity: 0.45;
  /* The dimmed state is what says "this alarm will not ring". */
  filter: grayscale(1);
}

.alarm-toggle[aria-pressed="true"] {
  opacity: 1;
  filter: none;
  box-shadow: inset 0 0 0 1px var(--accent-color, currentColor);
}

.alarm-delete:hover,
.alarm-delete:focus-visible {
  color: var(--danger-color, #f87171);
}

.alarm-snoozed-badge {
  position: absolute;
  top: -0.35rem;
  right: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  padding: 0.05rem 0.35rem;
  border-radius: 9999px;
  background: var(--accent-color);
  color: #fff;
}

.alarm-empty {
  padding: 0.75rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.alarm-ringing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 0.75rem;
  border: 1px solid var(--accent-color);
  background: rgba(59, 130, 246, 0.14);
}

.alarm-ringing__label {
  flex: 1;
  font-weight: 700;
  color: var(--text-primary);
}

.alarm-ringing .btn-primary { padding: 0.3rem 0.7rem; font-size: 0.7rem; }
.alarm-dismiss { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); }

.alarm-actions {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.35rem;
}

.alarm-time-input,
.alarm-label-input,
.habit-name-input,
.note-input {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 0.6rem;
  padding: 0.35rem 0.5rem;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.alarm-label-input,
.habit-name-input { font-family: var(--font-sans); }

.alarm-add { padding: 0.35rem 0.8rem; font-size: 0.75rem; }

.alarm-notice {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-radius: 0.6rem;
  font-size: 0.7rem;
  line-height: 1.35;
}

.alarm-notice { background: rgba(245, 158, 11, 0.12); color: var(--warning-color); }
.alarm-notice--warn { background: rgba(245, 158, 11, 0.12); color: var(--warning-color); }
.alarm-notice--muted { background: rgba(255, 255, 255, 0.04); color: var(--text-muted); }
.alarm-notice .btn-primary { padding: 0.25rem 0.6rem; font-size: 0.65rem; white-space: nowrap; }

/* --- Note widget ----------------------------------------------------- */

.note-container {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.note-input {
  flex: 1;
  min-height: 4rem;
  resize: none;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  line-height: 1.45;
  /* AUDIT M4 lesson: notes must be selectable even though the body is not. */
  user-select: text;
}

.note-footer {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-muted);
}

.note-status { color: var(--success-color); }

/* The character counter. Styled because it is a number that changes as you type:
 * without tabular figures it shifts the footer sideways on every keystroke. */
.note-count {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

/* Near the limit it is worth knowing before you hit it. */
.note-count[data-near-limit="true"] { color: var(--warning-color); }

/* --- Habit widget --------------------------------------------------- */

.habit-container {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  overflow-y: auto;
}

.habit-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.habit-grid-wrap { display: flex; flex-direction: column; gap: 0.4rem; }

.habit-row {
  display: grid;
  grid-template-columns: minmax(4.5rem, 1fr) auto auto auto;
  align-items: center;
  gap: 0.4rem;
}

.habit-toggle {
  text-align: left;
  padding: 0.25rem 0.35rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-toggle--on {
  color: var(--text-primary);
  border-color: var(--accent-color);
  background: rgba(59, 130, 246, 0.14);
  font-weight: 600;
}

.habit-streak {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--warning-color);
  min-width: 2.2rem;
  text-align: right;
}

.habit-cells {
  display: grid;
  grid-template-rows: repeat(7, 5px);
  grid-auto-flow: column;
  gap: 2px;
}

.habit-cell {
  width: 5px;
  height: 5px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.07);
}

.habit-cell--on { background: var(--success-color); }
.habit-cell--future { opacity: 0.25; }

.habit-remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.25rem;
  border-radius: 0.35rem;
}

.habit-remove:hover { color: var(--danger-color); background: rgba(239, 68, 68, 0.12); }

.habit-empty {
  padding: 0.6rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.habit-add-form { display: grid; grid-template-columns: 1fr auto; gap: 0.35rem; }
.habit-add-form .btn-primary { padding: 0.3rem 0.7rem; font-size: 0.72rem; }

/* --- Install / PWA banner -------------------------------------------- */

/* Anchored bottom-centre so it never competes with the top bar for attention,
   and auto-hides with the rest of the chrome when the display goes idle. */
.pwa-banner {
  position: absolute;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem 0.4rem 0.9rem;
  border-radius: 9999px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.pwa-banner button {
  border: none;
  /* White on --accent-color (#3b82f6) is only 3.67:1, which fails WCAG AA for
     text this small. A darker blue restores 4.5:1+ without changing the look. */
  background: #1d4ed8;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.22rem 0.6rem;
  border-radius: 9999px;
  cursor: pointer;
}

.pwa-banner button:hover { filter: brightness(1.1); }

.pwa-banner__dismiss {
  background: transparent !important;
  color: var(--text-muted) !important;
  font-size: 0.9rem !important;
  padding: 0 0.2rem !important;
}

/* --- Offline indicator ----------------------------------------------- */

body.is-offline #offline-badge { display: inline-flex; }

#offline-badge {
  display: none;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  background: rgba(245, 158, 11, 0.16);
  color: var(--warning-color);
}

/* Respect the motion preference for the new interactive elements too. */
@media (prefers-reduced-motion: reduce) {
  .alarm-ringing { transition: none; }
}