/* ============================================================================
 * Coffee Journal — hand-written CSS, framework-free.
 *
 * Design goals:
 *   - modern, minimal, mobile-first
 *   - warm "coffee" palette in light mode; rich espresso in dark mode
 *   - 44px minimum touch targets
 *   - subtle shadows + generous rounded corners
 *   - smooth state transitions, accessible focus rings
 *
 * Layout is a single flex column:
 *   appbar (sticky, 56px) → main view (scroll) → optional floating action.
 * ========================================================================== */

/* ---------- Design tokens (light mode) ---------- */
:root {
  /* Coffee palette */
  --c-bg: #faf6f1;
  --c-surface: #ffffff;
  --c-surface-2: #f3ece3;
  --c-border: #e7ddd1;
  --c-text: #2a1f17;
  --c-text-muted: #7a6a5d;
  --c-primary: #8a5a3b;          /* warm roast */
  --c-primary-hover: #734528;
  --c-primary-contrast: #ffffff;
  --c-accent: #c9925d;           /* latte foam */
  --c-danger: #c0524a;
  --c-success: #5b8c5a;
  --c-star: #e0a93b;
  --c-shadow: 0 1px 2px rgba(58, 42, 31, 0.06), 0 4px 16px rgba(58, 42, 31, 0.06);
  --c-shadow-lg: 0 4px 12px rgba(58, 42, 31, 0.1), 0 12px 32px rgba(58, 42, 31, 0.08);

  /* Sizing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --tap: 44px;
  --appbar-h: 56px;
  --maxw: 720px;

  /* Typography */
  --font:
    -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;

  color-scheme: light;
}

/* ---------- Dark mode (auto via system pref, plus [data-theme="dark"]) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --c-bg: #1a130d;
    --c-surface: #251a13;
    --c-surface-2: #2f2218;
    --c-border: #3a2a1f;
    --c-text: #f3ece3;
    --c-text-muted: #a89481;
    --c-primary: #c9925d;
    --c-primary-hover: #d8a36e;
    --c-primary-contrast: #1a130d;
    --c-accent: #e0a93b;
    --c-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
    --c-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 32px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --c-bg: #1a130d;
  --c-surface: #251a13;
  --c-surface-2: #2f2218;
  --c-border: #3a2a1f;
  --c-text: #f3ece3;
  --c-text-muted: #a89481;
  --c-primary: #c9925d;
  --c-primary-hover: #d8a36e;
  --c-primary-contrast: #1a130d;
  --c-accent: #e0a93b;
  --c-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
  --c-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 32px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  /* Prevent iOS rubber-band scroll on the document — the view itself scrolls. */
  overscroll-behavior: none;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: transparent;
}

a {
  color: var(--c-primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

img {
  max-width: 100%;
  display: block;
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top, 0);
  height: calc(var(--appbar-h) + env(safe-area-inset-top, 0));
  background: color-mix(in srgb, var(--c-bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--c-border);
}

.appbar__back {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
  color: var(--c-text);
}
.appbar__back:hover {
  background: var(--c-surface-2);
}

.appbar__title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appbar__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.appbar__actions button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--c-primary);
  font-weight: 500;
}
.appbar__actions button:hover {
  background: var(--c-surface-2);
}

/* ---------- Main view ---------- */
.view {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0));
}

/* ---------- Card ---------- */
.card {
  background: var(--c-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--c-shadow);
  overflow: hidden;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card:active {
  transform: scale(0.995);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  background: var(--c-primary);
  color: var(--c-primary-contrast);
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover {
  background: var(--c-primary-hover);
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--ghost {
  background: transparent;
  color: var(--c-text);
  border: 1px solid var(--c-border);
}
.btn--ghost:hover {
  background: var(--c-surface-2);
}

.btn--danger {
  background: var(--c-danger);
  color: #fff;
}

.btn--block {
  width: 100%;
}

.btn--lg {
  min-height: 52px;
  font-size: 16px;
}

/* ---------- Form fields ---------- */
.field {
  display: block;
  margin-bottom: 16px;
}

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-muted);
  letter-spacing: 0.02em;
}

.input,
.textarea {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus,
.textarea:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 25%, transparent);
}

.textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.5;
}

.input[type="date"] {
  /* Native picker stays simple; we restyle to fit. */
  font-variant-numeric: tabular-nums;
}

.field__row {
  display: flex;
  gap: 12px;
}
.field__row > * {
  flex: 1;
}

.helper {
  margin-top: 6px;
  font-size: 12px;
  color: var(--c-text-muted);
}

/* ---------- Star rating (input + display) ---------- */
.stars {
  display: inline-flex;
  gap: 4px;
  font-size: 28px;
  line-height: 1;
}
.stars--readonly {
  font-size: 16px;
}
.stars__star {
  background: transparent;
  border: 0;
  padding: 4px;
  border-radius: 6px;
  color: var(--c-border);
  transition: color 0.1s ease;
}
.stars__star:hover,
.stars__star.is-on {
  color: var(--c-star);
}
.stars__clear {
  margin-left: 8px;
  font-size: 13px;
  color: var(--c-text-muted);
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: 6px;
  transition: background 0.15s ease;
}
.stars__clear:hover,
.stars__clear:focus-visible {
  background: var(--c-surface-2);
}

/* ---------- Login view ---------- */
.auth {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  text-align: center;
}
.auth__brand {
  font-size: 64px;
  margin-bottom: 4px;
}
.auth__title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
}
.auth__subtitle {
  margin: 0 0 24px;
  color: var(--c-text-muted);
}
.auth__card {
  width: 100%;
  max-width: 360px;
  background: var(--c-surface);
  padding: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--c-shadow);
  text-align: left;
}
.auth__switch {
  margin-top: 16px;
  text-align: center;
  font-size: 14px;
  color: var(--c-text-muted);
}
.auth__switch button {
  color: var(--c-primary);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: 6px;
  transition: background 0.15s ease;
}
.auth__switch button:hover,
.auth__switch button:focus-visible {
  background: var(--c-surface-2);
}

/* ---------- List view ---------- */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.list-header__count {
  font-size: 13px;
  color: var(--c-text-muted);
}

.shop-card {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 12px;
  color: inherit;
}
.shop-card:hover {
  text-decoration: none;
}
.shop-card__cover {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--c-surface-2);
  background-size: cover;
  background-position: center;
}
.shop-card__cover-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: var(--c-text-muted);
}
.shop-card__body {
  padding: 12px 14px 14px;
}
.shop-card__name {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 4px;
}
.shop-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--c-text-muted);
  margin-bottom: 6px;
}
.shop-card__meta .dot {
  width: 3px;
  height: 3px;
  background: var(--c-text-muted);
  border-radius: 999px;
  opacity: 0.6;
}
.shop-card__review {
  font-size: 14px;
  color: var(--c-text);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Empty / loading / error states */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  text-align: center;
  color: var(--c-text-muted);
}
.state__icon {
  font-size: 48px;
  margin-bottom: 8px;
  opacity: 0.7;
}
.state__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--c-text);
  margin: 0 0 4px;
}
.state__hint {
  margin: 0;
  font-size: 14px;
}

/* Spinner */
.spinner {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Floating action button */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  z-index: 5;
  width: 56px;
  height: 56px;
  border-radius: 999px;
  background: var(--c-primary);
  color: var(--c-primary-contrast);
  font-size: 28px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--c-shadow-lg);
  transition: transform 0.1s ease;
}
.fab:hover {
  background: var(--c-primary-hover);
}
.fab:active {
  transform: scale(0.94);
}

/* ---------- Place search component ---------- */
.place-search {
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  padding: 12px;
}
.place-search__results {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.place-result {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: var(--tap);
}
.place-result:hover {
  background: color-mix(in srgb, var(--c-primary) 12%, var(--c-surface-2));
}
.place-result__name {
  font-weight: 600;
  font-size: 14px;
}
.place-result__addr {
  font-size: 12px;
  color: var(--c-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.place-search__footer {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--c-text-muted);
}
.place-search__credit a {
  color: var(--c-text-muted);
}

.place-selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--c-primary) 12%, var(--c-surface));
  border: 1px solid color-mix(in srgb, var(--c-primary) 30%, var(--c-border));
  border-radius: var(--radius-sm);
}
.place-selected__name {
  font-weight: 600;
}
.place-selected__addr {
  font-size: 12px;
  color: var(--c-text-muted);
}
.place-selected__clear {
  font-size: 13px;
  color: var(--c-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: 6px;
  transition: background 0.15s ease;
}
.place-selected__clear:hover,
.place-selected__clear:focus-visible {
  background: var(--c-surface-2);
}

/* ---------- Photo uploader ---------- */
.photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.photo-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--c-surface-2);
  background-size: cover;
  background-position: center;
}
.photo-tile__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.photo-tile__status {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  text-align: center;
}
.photo-add {
  aspect-ratio: 1 / 1;
  border: 2px dashed var(--c-border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-text-muted);
  font-size: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.photo-add:hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
}
.photo-input {
  display: none;
}

/* ---------- Detail view ---------- */
.detail__carousel {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--c-surface-2);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 12px;
}
.detail__carousel-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.detail__carousel-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  color: var(--c-text-muted);
}
.detail__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.detail__nav--prev {
  left: 8px;
}
.detail__nav--next {
  right: 8px;
}
.detail__dots {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
}
.detail__dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
}
.detail__dot.is-on {
  background: #fff;
}

.detail__title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
}
.detail__meta {
  color: var(--c-text-muted);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.detail__meta .dot {
  width: 3px;
  height: 3px;
  background: currentColor;
  border-radius: 999px;
  opacity: 0.5;
}
.detail__address {
  font-size: 14px;
  color: var(--c-text);
  margin: 0 0 12px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.detail__review {
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.6;
  margin: 0 0 16px;
}
.detail__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom, 0));
  z-index: 50;
  background: var(--c-text);
  color: var(--c-bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: 86vw;
  box-shadow: var(--c-shadow-lg);
  animation: toast-in 0.18s ease-out;
}
.toast--err {
  background: var(--c-danger);
  color: #fff;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------- Misc ---------- */
.hidden {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Wide screens ---------- */
@media (min-width: 720px) {
  .view {
    padding: 24px 24px calc(32px + env(safe-area-inset-bottom, 0));
  }
}