/*
 * overlay.css — Shared overlay (modal) styles.
 *
 * Provides the common structure for all overlay panels (entry-detail,
 * habit-editor, and future overlays). Specific files add their own
 * classes for unique styling.
 *
 * Load after tokens.css, before entry-detail.css / habit-editor.css.
 */

/* ---- Overlay container -------------------------------------------------- */
/* The card is centered via its own auto margins (see .overlay__card) rather
   than the container's align-items, so an overflowing card scrolls internally
   and never pushes the page or clips its top edge. */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ---- Card --------------------------------------------------------------- */
/* Auto margins center the card in the flex container while keeping it inside
   the viewport: when the content is taller than the card's max-height the card
   scrolls internally (overflow-y) instead of extending the page. */
.overlay__card {
  position: relative;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: auto;
  overflow-y: auto;
  /* Allow the card to shrink below its content's min-content width so a
     wide child (e.g. a fixed-width input) can't force the card wider than
     the viewport and clip the right edge. overflow-x: hidden contains any
     such child within the card instead of letting it spill off-screen. */
  min-width: 0;
  overflow-x: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---- Header ------------------------------------------------------------- */
.overlay__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.overlay__title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.overlay__close {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  padding: 0;
}

.overlay__close:hover {
  color: var(--text);
  background: var(--bg);
}

/* ---- Form fields (shared) ----------------------------------------------- */
.overlay__label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.overlay__input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition);
}

.overlay__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.overlay__input::placeholder {
  color: var(--text-muted);
}

/* Hide number input spinners */
.overlay__input::-webkit-inner-spin-button,
.overlay__input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.overlay__input[type="number"] {
  -moz-appearance: textfield;
}

/* ---- Buttons (shared) --------------------------------------------------- */
.overlay__save {
  padding: 8px 20px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity var(--transition);
}

.overlay__save:hover {
  opacity: 0.85;
}

.overlay__save:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.overlay__cancel {
  padding: 8px 20px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.overlay__cancel:hover {
  background: var(--surface);
}

.overlay__cancel:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.overlay__delete {
  padding: 8px 20px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #fff;
  background: var(--danger);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity var(--transition);
}

.overlay__delete:hover {
  opacity: 0.85;
}

.overlay__delete:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

/* ---- Confirm dialog (unsaved changes) ----------------------------------- */
/* A small overlay shown on top of an edit pane when it has unsaved changes. */
.overlay--confirm {
  z-index: 200;
}

.overlay--confirm-card {
  width: min(320px, calc(100vw - 32px));
}

.overlay--confirm-title {
  font-size: 1rem;
}

.overlay--confirm-message {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.overlay--confirm-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.overlay--confirm-btn {
  width: 100%;
}

/* ---- Reduced motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .overlay__input,
  .overlay__save,
  .overlay__cancel,
  .overlay__delete {
    transition: none;
  }
}
