:root {
  --background: #f6f4f1;
  --surface: #ffffff;
  --border: #ddd7d0;
  --text: #302b27;
  --muted: #70675f;
  --accent: #725047;
  --accent-dark: #5c3e37;
  --danger: #a13b37;
  --notice: #e8f2e8;
  --notice-text: #28542d;
  --shadow: 0 1px 3px rgb(48 43 39 / 8%);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--background);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
}

h1 {
  margin: 0 0 0.35rem;
  font-size: 1.65rem;
}

p {
  line-height: 1.5;
}

code {
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: #eee9e3;
}

.topbar {
  height: 62px;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: var(--accent);
}

.brand {
  color: #fff;
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  max-width: 1240px;
  margin: 0 auto;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.5rem 1rem;
}

.menu a {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 0.7rem 0.85rem;
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
}

.menu a:hover {
  background: #ebe5e0;
}

.content {
  min-width: 0;
  padding: 2rem 1.5rem 3rem;
}

.panel {
  padding: 1.4rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login,
.loading {
  max-width: 520px;
  margin: 2.5rem auto;
}

.section-heading {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.4rem;
}

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

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

.card {
  min-height: 74px;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.card:hover {
  border-color: var(--accent);
}

.card-title,
.card-count {
  display: block;
}

.card-title {
  margin-bottom: 0.45rem;
  font-size: 1.1rem;
  font-weight: 600;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0.58rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: #fff;
  background: var(--accent);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.button:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.button.secondary {
  border-color: var(--border);
  color: var(--text);
  background: var(--surface);
}

.button.plain {
  border-color: transparent;
  color: var(--accent);
  background: transparent;
}

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

.button:disabled {
  opacity: 0.55;
  cursor: default;
}

.hidden {
  display: none;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.search {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}

.search input {
  flex: 1;
  max-width: 440px;
}

.search-indicator {
  align-self: center;
  color: var(--muted);
  font-size: 0.94rem;
  white-space: nowrap;
}

.htmx-indicator {
  opacity: 0;
  visibility: hidden;
  transition: opacity 120ms ease-in;
}

.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator {
  opacity: 1;
  visibility: visible;
}

.results-count {
  margin: 0 0 0.75rem;
}

input,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 0.65rem 0.72rem;
  border: 1px solid #cfc7c0;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}

input:focus,
textarea:focus {
  outline: 2px solid #cbb4a9;
  outline-offset: 1px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

th,
td {
  padding: 0.75rem 0.8rem;
  border-bottom: 1px solid #eee9e3;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  background: #fbfaf8;
}

.sort-link {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
  min-height: 44px;
  margin: -0.45rem;
  padding: 0.45rem;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.sort-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.actions {
  width: 1%;
  white-space: nowrap;
}

.link-button,
.danger-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.35rem 0.15rem;
  border: 0;
  color: var(--accent);
  background: transparent;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.danger-link {
  margin-top: 1.25rem;
  color: var(--danger);
}

.empty {
  color: var(--muted);
  text-align: center;
}

.pagination {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  justify-content: flex-end;
  margin-top: 1rem;
}

.details {
  display: grid;
  grid-template-columns: minmax(150px, 220px) 1fr;
  gap: 0;
  margin: 0;
}

.details dt,
.details dd {
  padding: 0.65rem 0;
  border-bottom: 1px solid #eee9e3;
}

.details dt {
  color: var(--muted);
  font-weight: 500;
}

.details dd {
  margin: 0;
  white-space: pre-wrap;
}

.record-form {
  max-width: 700px;
}

.form-row {
  margin-bottom: 1rem;
}

.form-row > label {
  display: block;
  margin-bottom: 0.36rem;
  font-weight: 500;
}

.checkbox-row label {
  display: inline-flex;
  gap: 0.55rem;
  align-items: center;
}

.checkbox-row input {
  width: 24px;
  height: 24px;
  min-height: 24px;
}

.field-error {
  display: block;
  margin-top: 0.3rem;
  color: var(--danger);
  font-size: 0.92rem;
}

.notice {
  margin: 0 0 1.3rem;
  padding: 0.72rem 0.9rem;
  border-radius: 7px;
  color: var(--notice-text);
  background: var(--notice);
}

.confirmation {
  max-width: 650px;
}

.confirmation .buttons {
  margin-top: 1.35rem;
}

.error {
  max-width: 650px;
}

.sr-only {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
}

@media (max-width: 720px) {
  .topbar {
    min-height: 60px;
    height: auto;
    padding: 0.45rem max(1rem, env(safe-area-inset-right)) 0.45rem max(1rem, env(safe-area-inset-left));
  }

  .layout {
    display: block;
  }

  .menu {
    flex-direction: row;
    gap: 0.2rem;
    overflow-x: auto;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .menu a {
    white-space: nowrap;
  }

  .content {
    padding: 1.2rem 1rem 2rem;
  }

  .panel {
    padding: 1rem;
  }

  .login,
  .loading {
    margin: 1rem auto;
  }

  .section-heading,
  .search {
    flex-direction: column;
  }

  .section-heading > .button,
  .search .button {
    width: 100%;
  }

  .search input {
    max-width: none;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  .pagination {
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.55rem;
  }

  .pagination span {
    order: -1;
    width: 100%;
    text-align: center;
  }

  .pagination .button {
    flex: 1;
  }

  .details {
    display: block;
  }

  .details dt {
    padding-bottom: 0.15rem;
    border-bottom: 0;
  }
}
