:root {
  color-scheme: light;
  --background: #f6f7fa;
  --surface: #ffffff;
  --surface-hover: #f0f3f9;
  --text: #1c2940;
  --muted: #65718a;
  --border: #e2e7ef;
  --primary: #3154a5;
  --primary-hover: #24438c;
  --primary-soft: #edf2fc;
  --danger: #b53542;
  --danger-bg: #fff0f1;
  --warning: #89580d;
  --warning-bg: #fff6e5;
  --success: #237451;
  --success-bg: #edf8f1;
  --radius: 16px;
  --shadow: 0 4px 18px rgb(28 41 64 / 4%);
  --max-width: 1200px;
  --page-gutter: 24px;
  --focus-ring: 0 0 0 4px rgb(49 84 165 / 13%);
}

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

[hidden] {
  display: none !important;
}

html {
  scroll-padding-top: 24px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--background);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Noto Sans KR", "Noto Sans CJK KR", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: #dce7ff;
  color: #172d5c;
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  word-break: keep-all;
  overflow-wrap: anywhere;
}

h1 {
  font-size: clamp(28px, 3.5vw, 40px);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.055em;
}

h2 {
  font-size: clamp(19px, 2.4vw, 23px);
  font-weight: 750;
  line-height: 1.4;
  letter-spacing: -0.04em;
}

h3 {
  font-size: 17px;
  line-height: 1.45;
}

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

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: inherit;
}

a:focus-visible,
button:focus-visible {
  outline: 3px solid #668cde;
  outline-offset: 4px;
}

body > header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  min-height: 82px;
  padding-block: 16px;
  padding-inline: max(var(--page-gutter), calc((100% - var(--max-width)) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header > a {
  min-width: 0;
  color: var(--text);
  font-size: 17px;
  font-weight: 750;
  line-height: 1.5;
  letter-spacing: -0.045em;
}

.site-logo {
  display: inline-flex;
  flex: 1 1 200px;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.site-logo img {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.site-logo span {
  min-width: 0;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

header nav {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin-left: auto;
}

header nav a,
header nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
  text-align: center;
}

main {
  width: calc(100% - var(--page-gutter) * 2);
  max-width: var(--max-width);
  margin-inline: auto;
  padding-block: 40px 80px;
}

main > a:first-child {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: -8px 0 20px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

section + section {
  margin-top: 40px;
}

label {
  display: block;
  color: #34415b;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.5;
}

input,
textarea,
select {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #d6ddea;
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

input::placeholder,
textarea::placeholder {
  color: #7c879c;
  opacity: 1;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

input:disabled,
textarea:disabled,
select:disabled {
  background: #f1f3f7;
  cursor: not-allowed;
}

textarea {
  min-height: 100px;
  resize: none;
}

input[type="file"] {
  padding: 8px;
}

input::file-selector-button {
  margin-right: 12px;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  font: inherit;
  cursor: pointer;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 46px;
  padding: 11px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  line-height: 1.5;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button[type="submit"],
#take-item-button,
#edit-item-button,
#accept-button {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

#delete-item-button,
#delete-button {
  border-color: #f0d6da;
  background: var(--danger-bg);
  color: var(--danger);
}

#decline-button,
#cancel-take-button {
  border-color: #ecdfc3;
  background: var(--warning-bg);
  color: var(--warning);
}

button[value="cancel"],
#cancel-edit-button {
  border-color: #d6ddea;
  background: var(--surface);
  color: #4b5870;
}

#search-form,
#admin-search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin: 0;
}

#search-form label,
#admin-search-form label {
  grid-column: 1 / -1;
  margin-bottom: 2px;
}

#search-form input,
#admin-search-form input {
  min-height: 50px;
  padding-left: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23748098' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='10.8' cy='10.8' r='6.8'/%3E%3Cpath d='m16 16 4.5 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px center;
  background-size: 18px;
}

#search-form button,
#admin-search-form button {
  min-width: 80px;
  min-height: 50px;
}

#item-list,
#admin-item-list,
#temporary-item-list,
#taken-item-list,
#declined-item-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 24px;
  min-width: 0;
  margin-top: 22px;
}

.item-card,
.temporary-item-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.item-card > a,
.temporary-item-card > a {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  padding: 10px 10px 18px;
}

.item-card:focus-within,
.temporary-item-card:focus-within {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.item-card > a:focus-visible,
.temporary-item-card > a:focus-visible {
  outline-offset: -4px;
}

.item-image {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 10px;
  background: #f0f2f6;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.item-image img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 12px;
  object-fit: contain;
  object-position: center;
}

.item-card h3,
.temporary-item-card h3,
.temporary-item-card h2 {
  display: -webkit-box;
  min-height: 1.45em;
  margin: 16px 10px 8px;
  overflow: hidden;
  font-size: 17px;
  font-weight: 750;
  line-height: 1.45;
  letter-spacing: -0.035em;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.item-card p,
.temporary-item-card p {
  margin: 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.item-card p:first-of-type,
.temporary-item-card p:first-of-type {
  display: -webkit-box;
  min-height: 3.4em;
  margin-bottom: 6px;
  overflow: hidden;
  color: #4d5b73;
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.item-card p:nth-of-type(2),
.temporary-item-card p:nth-of-type(2) {
  margin-bottom: 12px;
}

.item-card p:nth-of-type(3),
.temporary-item-card p:nth-of-type(3) {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid #edf0f5;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

:is(
    #item-list,
    #admin-item-list,
    #temporary-item-list,
    #taken-item-list,
    #declined-item-list
  )
  > p {
  display: grid;
  grid-column: 1 / -1;
  place-content: center;
  min-height: 180px;
  padding: 32px 20px;
  border: 1px dashed #cdd6e5;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  font-size: 14px;
}

article#item-detail,
#admin-item-detail,
#temporary-item-detail {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  gap: 20px 40px;
  width: 100%;
  margin: 0;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

:is(article#item-detail, #admin-item-detail, #temporary-item-detail)
  > .item-image {
  grid-column: 1;
  grid-row: 1 / 4;
  align-self: start;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
}

:is(article#item-detail, #admin-item-detail, #temporary-item-detail)
  > .item-image
  img {
  padding: 20px;
}

:is(article#item-detail, #admin-item-detail, #temporary-item-detail)
  > .item-image:has(> img[hidden])::after {
  content: "이미지가 존재하지 않습니다";
  padding: 20px;
  text-align: center;
}

:is(article#item-detail, #admin-item-detail, #temporary-item-detail) > h1 {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  padding-top: 6px;
  font-size: clamp(24px, 2.6vw, 32px);
}

:is(article#item-detail, #admin-item-detail, #temporary-item-detail) > dl {
  display: grid;
  grid-column: 2;
  grid-row: 2;
  grid-template-columns: 94px minmax(0, 1fr);
  align-content: start;
  align-self: start;
  min-width: 0;
  margin: 0;
}

:is(article#item-detail, #admin-item-detail, #temporary-item-detail) dt,
:is(article#item-detail, #admin-item-detail, #temporary-item-detail) dd {
  min-width: 0;
  margin: 0;
  padding-block: 13px;
  border-bottom: 1px solid #edf0f5;
  font-size: 14px;
  line-height: 1.8;
}

:is(article#item-detail, #admin-item-detail, #temporary-item-detail) dt {
  padding-right: 12px;
  color: var(--muted);
  font-weight: 500;
  word-break: keep-all;
}

:is(article#item-detail, #admin-item-detail, #temporary-item-detail) dd {
  color: var(--text);
  overflow-wrap: anywhere;
  white-space: pre-line;
}

#take-item-button,
#admin-item-detail > div:last-child,
#temporary-item-detail > div:last-child {
  grid-column: 2;
  grid-row: 3;
  align-self: end;
  margin-top: 4px;
}

#take-item-button {
  width: 100%;
  min-height: 50px;
}

#admin-item-detail > div:last-child,
#temporary-item-detail > div:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#admin-item-detail > div:last-child > button,
#temporary-item-detail > div:last-child > button {
  flex: 1 1 100px;
}

#temporary-item-register-form,
#edit-item-form,
#admin-login-form,
#take-item-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
  gap: 8px 12px;
}

:is(
    #temporary-item-register-form,
    #edit-item-form,
    #admin-login-form,
    #take-item-form
  )
  > :is(label, input, textarea, select, h2, p) {
  grid-column: 1 / -1;
}

:is(
    #temporary-item-register-form,
    #edit-item-form,
    #admin-login-form,
    #take-item-form
  )
  > :is(input, textarea, select)
  + label {
  margin-top: 14px;
}

:is(
    #temporary-item-register-form,
    #edit-item-form,
    #admin-login-form,
    #take-item-form
  )
  > button {
  width: 100%;
  margin-top: 18px;
}

#admin-login-form > button {
  grid-column: 1 / -1;
}

dialog {
  width: min(460px, calc(100% - 32px));
  max-width: none;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 30px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgb(13 26 51 / 22%);
}

dialog:not([open]) {
  display: none;
}

dialog::backdrop {
  background: rgb(15 25 45 / 52%);
}

#take-item-form > h2 {
  margin-bottom: 16px;
}

#login-error,
#error-message {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid #f0d6da;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

@media (hover: hover) and (pointer: fine) {
  button:not(:disabled):hover,
  header nav a:hover {
    border-color: #cbd5e4;
    background: var(--surface-hover);
    color: var(--text);
  }

  button[type="submit"]:not(:disabled):hover,
  #take-item-button:not(:disabled):hover,
  #edit-item-button:not(:disabled):hover,
  #accept-button:not(:disabled):hover {
    border-color: var(--primary-hover);
    background: var(--primary-hover);
    color: #fff;
  }

  #delete-item-button:not(:disabled):hover,
  #delete-button:not(:disabled):hover {
    border-color: #e7b9c0;
    background: #ffe2e6;
    color: #9f2231;
  }

  #decline-button:not(:disabled):hover,
  #cancel-take-button:not(:disabled):hover {
    border-color: #e6ce9b;
    background: #ffedcc;
    color: #754a07;
  }

  main > a:first-child:hover {
    color: var(--primary);
  }

  .item-card:hover,
  .temporary-item-card:hover {
    transform: translateY(-3px);
    border-color: #becde8;
    box-shadow: 0 10px 28px rgb(28 41 64 / 8%);
  }
}

@media (max-width: 1099px) {
  #item-list,
  #admin-item-list,
  #temporary-item-list,
  #taken-item-list,
  #declined-item-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
  }

  article#item-detail,
  #admin-item-detail,
  #temporary-item-detail {
    gap: 20px 28px;
    padding: 26px;
  }
}

@media (max-width: 819px) {
  #item-list,
  #admin-item-list,
  #temporary-item-list,
  #taken-item-list,
  #declined-item-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  article#item-detail,
  #admin-item-detail,
  #temporary-item-detail {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    gap: 22px;
  }

  :is(article#item-detail, #admin-item-detail, #temporary-item-detail)
    > .item-image {
    grid-column: 1;
    grid-row: 1;
    aspect-ratio: 4 / 3;
    max-height: 480px;
  }

  :is(article#item-detail, #admin-item-detail, #temporary-item-detail) > h1 {
    grid-column: 1;
    grid-row: 2;
    padding-top: 0;
  }

  :is(article#item-detail, #admin-item-detail, #temporary-item-detail) > dl {
    grid-column: 1;
    grid-row: 3;
  }

  #take-item-button,
  #admin-item-detail > div:last-child,
  #temporary-item-detail > div:last-child {
    grid-column: 1;
    grid-row: 4;
  }
}

@media (max-width: 599px) {
  :root {
    --page-gutter: 16px;
  }

  body > header {
    gap: 10px 12px;
    min-height: 72px;
    padding-block: 14px;
  }

  header > a {
    font-size: 15px;
  }

  .site-logo {
    flex-basis: 160px;
    gap: 9px;
  }

  .site-logo img {
    flex-basis: 32px;
    width: 32px;
    height: 32px;
  }

  header nav a,
  header nav button {
    min-height: 44px;
    padding-inline: 10px;
    font-size: 12px;
  }

  main {
    padding-block: 26px 48px;
  }

  section + section {
    margin-top: 28px;
  }

  #search-form,
  #admin-search-form {
    gap: 8px;
  }

  #search-form button,
  #admin-search-form button {
    min-width: 66px;
    padding-inline: 14px;
  }

  #search-form input,
  #admin-search-form input {
    padding-left: 36px;
    background-position: 11px center;
    background-size: 16px;
  }

  #item-list,
  #admin-item-list,
  #temporary-item-list,
  #taken-item-list,
  #declined-item-list {
    gap: 16px;
    margin-top: 18px;
  }

  article#item-detail,
  #admin-item-detail,
  #temporary-item-detail {
    gap: 18px;
    padding: 18px;
    border-radius: 16px;
  }

  :is(article#item-detail, #admin-item-detail, #temporary-item-detail) > dl {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  :is(article#item-detail, #admin-item-detail, #temporary-item-detail) dt,
  :is(article#item-detail, #admin-item-detail, #temporary-item-detail) dd {
    font-size: 13px;
  }

  dialog {
    padding: 24px 20px;
    border-radius: 16px;
  }
}

@media (max-width: 539px) {
  #item-list,
  #admin-item-list,
  #temporary-item-list,
  #taken-item-list,
  #declined-item-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .item-card > a,
  .temporary-item-card > a {
    padding-bottom: 20px;
  }

  .item-card h3,
  .temporary-item-card h3 {
    font-size: 18px;
  }

  .item-card p,
  .temporary-item-card p {
    font-size: 13px;
  }

  .item-card p:nth-of-type(3),
  .temporary-item-card p:nth-of-type(3) {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  .item-card:hover,
  .temporary-item-card:hover {
    transform: none;
  }
}
