:root {
  --brand-blue: #4a7fe6;
  --brand-blue-dark: #3a6bd0;
  --brand-yellow: #fbbf24;
  --text: #1f2937;
  --bg: #ffffff;
  --border: #e5e7eb;
  --topbar-height: 64px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Keep the hidden attribute working on elements that set their own display */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* Fixed top bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  height: 100%;
}

.topbar__logo {
  height: 48px;
  width: auto;
  display: block;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.btn--ghost {
  background: transparent;
  color: var(--brand-blue);
  border: 2px solid var(--brand-blue);
}

.btn--ghost:hover {
  background: var(--brand-blue);
  color: #fff;
}

.btn--primary {
  background: var(--brand-blue);
  color: #fff;
  border: 2px solid var(--brand-blue);
}

.btn--primary:hover {
  background: var(--brand-blue-dark);
  border-color: var(--brand-blue-dark);
}

/* Page content sits below the fixed bar */
.content {
  padding-top: var(--topbar-height);
  min-height: 100vh;
}

@media (max-width: 480px) {
  .topbar {
    padding: 0 16px;
  }

  .topbar__logo {
    height: 36px;
  }

  .btn {
    padding: 6px 12px;
    font-size: 0.85rem;
  }
}

/* Auth dialog */
.auth-dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 0;
  border: none;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.auth-dialog::backdrop {
  background: rgba(17, 24, 39, 0.5);
}

.auth-form {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 32px 28px 24px;
}

.auth-dialog__close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: #6b7280;
  cursor: pointer;
}

.auth-form__title {
  margin: 0;
  color: var(--brand-blue);
}

.auth-form__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}

.auth-form__field input {
  font: inherit;
  font-weight: 400;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-form__field input:focus {
  outline: 2px solid var(--brand-blue);
  outline-offset: -1px;
}

.auth-form__message {
  margin: 0;
  font-size: 0.9rem;
}

.auth-form__message:empty {
  display: none;
}

.auth-form__message--error {
  color: #dc2626;
}

.auth-form__submit {
  padding: 10px 18px;
}

.auth-form__submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-form__switch {
  margin: 0;
  font-size: 0.9rem;
  text-align: center;
}

.link-btn {
  font: inherit;
  font-weight: 600;
  background: none;
  border: none;
  padding: 0;
  color: var(--brand-blue);
  cursor: pointer;
}

/* Background image on every page except the home page (body.home).
   Drawn on a fixed layer because background-attachment: fixed is unreliable on iOS. */
body:not(.home) {
  background-color: #040a1c;
}

body:not(.home)::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("../assets/ss365bg.png") center / cover no-repeat;
}

/* Signed-in pages */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 16px;
}

/* Content sits on a white panel over the background image. */
body:not(.home) .page {
  margin: 24px auto;
  padding: 32px 24px;
  background: var(--bg);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

@media (max-width: 672px) {
  body:not(.home) .page {
    margin: 16px;
    padding: 24px 16px;
  }
}

.page__title {
  margin: 0 0 24px;
  color: var(--brand-blue);
}

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}

.form-field input,
.form-field select {
  font: inherit;
  font-weight: 400;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.form-field input:focus,
.form-field select:focus {
  outline: 2px solid var(--brand-blue);
  outline-offset: -1px;
}

.form-field input[readonly] {
  background: #f3f4f6;
  color: #6b7280;
}

.form-message {
  margin: 0;
  font-size: 0.9rem;
}

.form-message:empty {
  display: none;
}

.form-message--error {
  color: #dc2626;
}

.profile-form__submit {
  align-self: flex-start;
  padding: 10px 24px;
}

.profile-form__submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.form-hint {
  margin: -8px 0 0;
  font-size: 0.85rem;
  color: #6b7280;
}

.form-hint a {
  color: var(--brand-blue);
}

/* Shopping lists */
.btn--small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.lists-message:not(:empty) {
  margin-bottom: 16px;
}

.list-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.list-card__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-card__name {
  font-weight: 600;
}

.list-card__date {
  font-size: 0.9rem;
  color: #6b7280;
}

.list-card__actions {
  display: flex;
  gap: 8px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  color: #6b7280;
}

.empty-state p {
  margin: 0;
}

a.list-card__name {
  color: var(--text);
  text-decoration: none;
}

a.list-card__name:hover {
  color: var(--brand-blue);
  text-decoration: underline;
}

.list-card__note {
  font-size: 0.8rem;
  color: #9ca3af;
}

/* Single list page */
.list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.list-header__title {
  margin-bottom: 4px;
}

.list-header__meta {
  margin: 0;
  color: #6b7280;
  font-size: 0.95rem;
}

.status-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: middle;
}

.status-badge--open {
  background: #eef3fd;
  color: var(--brand-blue-dark);
}

.status-badge--completed {
  background: #dcfce7;
  color: #166534;
}

.status-badge--archived {
  background: #f3f4f6;
  color: #4b5563;
}

.add-item {
  display: grid;
  grid-template-columns: 1fr 80px 90px auto;
  gap: 8px;
  margin-bottom: 20px;
}

.add-item input {
  font: inherit;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.add-item input:focus {
  outline: 2px solid var(--brand-blue);
  outline-offset: -1px;
}

.items-summary {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: #6b7280;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.item-row__check {
  width: 18px;
  height: 18px;
  accent-color: var(--brand-blue);
}

.item-row__name {
  flex: 1;
}

.item-row__qty {
  font-size: 0.9rem;
  color: #6b7280;
}

.item-row--checked .item-row__name,
.item-row--checked .item-row__qty {
  text-decoration: line-through;
  color: #9ca3af;
}

.item-row__remove {
  padding: 0 6px;
  border: none;
  background: none;
  color: #6b7280;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.item-row__remove:hover {
  color: #dc2626;
}

@media (max-width: 480px) {
  .add-item {
    grid-template-columns: 1fr 1fr;
  }

  .add-item input[name="name"] {
    grid-column: 1 / -1;
  }

  .add-item button {
    grid-column: 1 / -1;
    justify-content: center;
  }
}

/* Supermarket picker */
.market-picker {
  margin: 0;
  padding: 0;
  border: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.market-picker__legend {
  padding: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.market-picker__hint {
  margin: 0;
  font-size: 0.85rem;
  color: #6b7280;
}

.market-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.market-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.is-dragging {
  border-color: var(--brand-blue);
  background: #eef3fd;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.drag-handle {
  display: inline-flex;
  padding: 4px 6px;
  border: none;
  border-radius: 6px;
  background: none;
  color: #9ca3af;
  cursor: grab;
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-handle:focus-visible {
  outline: 2px solid var(--brand-blue);
}

.market-item__rank {
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand-blue);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.market-item__name {
  flex: 1;
}

.market-item__remove {
  padding: 0 6px;
  border: none;
  background: none;
  color: #6b7280;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.market-item__remove:hover {
  color: #dc2626;
}

.market-picker__add {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.market-picker__add:focus {
  outline: 2px solid var(--brand-blue);
  outline-offset: -1px;
}

/* Avatars */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--brand-blue);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar--large {
  width: 96px;
  height: 96px;
  font-size: 2.4rem;
}

/* Top bar drop-down menus */
.menu {
  position: relative;
}

.menu__chevron {
  margin-left: 6px;
  transition: transform 0.15s;
}

.menu__btn[aria-expanded="true"] .menu__chevron {
  transform: rotate(180deg);
}

.menu__btn--avatar {
  display: block;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

.menu__btn--avatar:hover,
.menu__btn--avatar[aria-expanded="true"] {
  border-color: var(--brand-blue);
}

.menu__btn--avatar:focus-visible {
  outline: 2px solid var(--brand-blue);
  outline-offset: 2px;
}

.menu__list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.menu__item {
  white-space: nowrap;
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.menu__item:hover,
.menu__item:focus-visible {
  background: #f3f4f6;
  outline: none;
}

/* Profile picture editor */
.avatar-editor {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}

.avatar-editor__controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.avatar-editor__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.crop-dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 0;
  border: none;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.crop-dialog::backdrop {
  background: rgba(17, 24, 39, 0.5);
}

.crop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
}

.crop__title {
  margin: 0;
  align-self: flex-start;
  color: var(--brand-blue);
}

.crop__canvas {
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #f3f4f6;
  cursor: grab;
  touch-action: none;
}

.crop__canvas:active {
  cursor: grabbing;
}

.crop__zoom {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  font-size: 0.9rem;
  font-weight: 600;
}

.crop__zoom input {
  flex: 1;
  accent-color: var(--brand-blue);
}

.crop__actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  width: 100%;
}

#crop-save:disabled,
#avatar-remove:disabled {
  opacity: 0.6;
  cursor: default;
}
