:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #2b2622;
  --muted: #7a7068;
  --border: #e6dfd5;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-contrast: #ffffff;
  --danger: #b91c1c;
  --success: #15803d;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 4%);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1714;
    --surface: #242019;
    --text: #f1ebe3;
    --muted: #a39a90;
    --border: #3a342c;
    --accent: #f97316;
    --accent-hover: #fb923c;
    --accent-contrast: #1a1714;
    --danger: #f87171;
    --success: #4ade80;
    --shadow: none;
  }
}

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

body {
  margin: 0;
  min-height: 100vh;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0;
}

.muted {
  color: var(--muted);
}

.center {
  text-align: center;
}

.error {
  color: var(--danger);
  margin: 0;
}

/* Layout */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

/* Buttons & inputs */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.button:hover {
  border-color: var(--muted);
}

.button.primary {
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
}

.button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button.danger {
  color: var(--danger);
}

.button:disabled,
.button.htmx-request {
  opacity: 0.6;
  cursor: progress;
}

.link-button {
  padding: 0;
  font: inherit;
  font-size: 0.9rem;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: underline;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  font-weight: 600;
}

input[type='text'],
input[type='url'],
input[type='password'],
textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type='file'] {
  font-weight: 400;
}

.required {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  font-weight: 400;
}

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Login */

.login {
  display: grid;
  place-items: center;
  padding-top: 4rem;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(100%, 22rem);
  padding: 1.5rem;
}

.login-card p {
  margin: 0;
}

/* List */

.list-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.list-header h1 {
  font-size: 1.75rem;
}

.list-header-actions {
  display: flex;
  gap: 0.5rem;
}

.empty {
  padding: 3rem 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.item {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.item-image {
  aspect-ratio: 4 / 3;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.item-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.item-image.placeholder {
  display: grid;
  place-items: center;
  font-size: 2.5rem;
}

.item-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.9rem 1rem 1rem;
}

.item-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.item-price {
  margin: 0;
  font-weight: 700;
  color: var(--accent);
}

.item-description {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 0.6rem;
}

.item.bought .item-image img,
.item.bought .item-title,
.item.bought .item-price,
.item.bought .item-description {
  opacity: 0.55;
}

.item.bought .item-title {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.badge {
  padding: 0.1rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: 999px;
  text-decoration: none;
  display: inline-block;
}

/* Dialog & forms */

dialog {
  width: min(100% - 2rem, 32rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

#dialog-content {
  padding: 1.25rem;
}

.dialog-form,
.fields {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.field-row {
  display: flex;
  gap: 0.5rem;
}

.field-row .button {
  flex-shrink: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.notice {
  margin: 0;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.notice.error {
  border-color: var(--danger);
}

.preview img {
  display: block;
  max-width: 100%;
  max-height: 180px;
  margin: 0 auto;
  border-radius: 8px;
}
