:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --text: #202124;
  --muted: #62666d;
  --line: #dfe1e5;
  --accent: #0b6b63;
  --accent-strong: #084f49;
  --danger: #a12b2b;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141514;
  --panel: #1f211f;
  --text: #f0f2ef;
  --muted: #b8bdb7;
  --line: #353934;
  --accent: #65b8aa;
  --accent-strong: #8fd3c7;
  --danger: #ff9a9a;
}

* {
  box-sizing: border-box;
}

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

main {
  max-width: 1440px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.header-actions,
.form-stack {
  display: flex;
  gap: 12px;
}

.header-actions {
  align-items: center;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.button,
.copy-button,
.danger-button,
.icon-button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}

.button-secondary,
.icon-button {
  background: transparent;
  color: var(--accent-strong);
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
}

.status-progress {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.auth-shell {
  display: grid;
  min-height: calc(100vh - 160px);
  place-items: center;
}

.auth-card {
  width: min(460px, 100%);
}

.form-stack {
  flex-direction: column;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

input,
select,
textarea {
  min-height: 40px;
  font: inherit;
}

textarea {
  resize: vertical;
}

input[type="color"] {
  width: 100%;
  min-height: 42px;
  padding: 4px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(2, minmax(180px, 240px));
  gap: 12px;
  margin-bottom: 16px;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

th[data-sort] {
  cursor: pointer;
}

.cover-thumb {
  width: 54px;
  height: 72px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

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

.empty-thumb {
  display: grid;
  place-items: center;
  width: 54px;
  height: 72px;
  border: 1px dashed var(--line);
  border-radius: 4px;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--swatch);
}

.subject-cell {
  max-width: 360px;
}

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

.pagination-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 14px;
}

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

.page-size-control {
  display: flex;
  align-items: center;
  grid-template-columns: none;
  gap: 8px;
}

.page-size-control select {
  min-width: 76px;
}

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

.pagination button[aria-current="true"] {
  background: var(--accent-strong);
}

.page-size-select {
  width: 80px;
}

dialog {
  max-width: min(90vw, 720px);
  border: 0;
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.book-dialog {
  width: min(92vw, 760px);
  max-width: min(92vw, 760px);
}

.prompt-dialog {
  width: min(94vw, 860px);
  max-width: min(94vw, 860px);
}

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

dialog img {
  max-width: 100%;
  max-height: 82vh;
  display: block;
}

.dialog-close {
  float: right;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 22px;
}

.book-form {
  display: grid;
  gap: 14px;
}

.form-grid,
.color-fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.color-fieldset {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 12px;
}

.color-fieldset legend {
  color: var(--muted);
  padding: 0 4px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.tag-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--accent-strong);
  cursor: pointer;
  font: inherit;
  padding: 6px 9px;
}

.flash-stack {
  width: min(960px, calc(100% - 32px));
  margin: 16px auto 0;
}

.flash {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  padding: 10px 12px;
}

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

.flash-success {
  color: var(--accent-strong);
}

@media (max-width: 760px) {
  main {
    width: min(100% - 20px, 1440px);
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px;
  }

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

  .page-actions {
    justify-content: stretch;
  }

  .page-actions form,
  .page-actions button {
    width: 100%;
  }

  .pagination-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination {
    justify-content: stretch;
  }

  .form-grid,
  .color-fieldset {
    grid-template-columns: 1fr;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions button {
    width: 100%;
  }
}
