:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #182026;
  --muted: #66737f;
  --line: #d8e0e6;
  --accent: #1f7a6f;
  --accent-dark: #176057;
  --danger: #b93d35;
  --shadow: 0 10px 30px rgba(22, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

.hidden {
  display: none !important;
}

button,
input,
textarea {
  font: inherit;
}

.auth-panel {
  min-height: calc(100vh - 52px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
  display: grid;
  gap: 14px;
}

.auth-box p {
  line-height: 1.5;
}

.auth-actions,
.account-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

#current-user {
  color: var(--text);
  font-weight: 600;
}

button,
.export-link {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.export-link:hover {
  background: var(--accent-dark);
}

button.secondary {
  background: #e6ecef;
  color: var(--text);
}

button.secondary:hover {
  background: #d9e2e6;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 18px;
}

.scanner-panel,
.editor-panel,
.library-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

p,
span,
label {
  color: var(--muted);
}

.scanner-frame {
  position: relative;
  overflow: hidden;
  min-height: 300px;
  border-radius: 8px;
  background: #11191d;
}

video {
  width: 100%;
  height: 100%;
  min-height: 300px;
  object-fit: cover;
  display: block;
}

.scan-mask {
  position: absolute;
  inset: 22%;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.32);
}

#scanner-state {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 9px 12px;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
}

.controls,
.form-actions,
.inline-form {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.scan-options {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.device-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  flex-wrap: wrap;
}

.device-label {
  white-space: nowrap;
}

.device-row select {
  flex: 1;
  min-width: 160px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

.isbn-form {
  margin-top: 16px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  padding: 10px 11px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(31, 122, 111, 0.15);
}

.book-preview {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 18px;
}

.cover-box {
  width: 150px;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef2f4;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.cover-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

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

.wide-field {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow-x: auto;
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.list-toolbar input,
.list-toolbar select {
  margin: 0;
}

.list-toolbar input[type="search"] {
  flex: 1 1 240px;
}

.list-toolbar select {
  flex: 0 0 auto;
  width: auto;
  min-width: 120px;
}

.refresh-actions {
  display: flex;
  gap: 8px;
}

.refresh-panel {
  margin-top: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fafb;
}

.refresh-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

#refresh-summary {
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.refresh-log {
  margin: 0;
  max-height: 140px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}

td {
  font-size: 14px;
}

.thumb {
  width: 44px;
  height: 60px;
  border-radius: 4px;
  background: #eef2f4;
  object-fit: cover;
  display: block;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.danger {
  background: var(--danger);
}

.danger:hover {
  background: #96312b;
}

@media (min-width: 980px) {
  .app-shell {
    grid-template-columns: 0.95fr 1.35fr;
  }

  .library-panel,
  .share-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .form-header,
  .table-header,
  .controls,
  .form-actions,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .list-toolbar {
    flex-direction: column;
  }

  .list-toolbar input[type="search"] {
    flex: 1 1 auto;
  }

  .book-preview,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .cover-box {
    width: 120px;
    min-height: 172px;
  }

  .top-nav {
    padding: 0 12px;
  }

  .home-view,
  .shelf-view {
    padding: 16px 12px 32px;
  }

  .home-banner {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 20px;
  }

  .banner-icon {
    width: 64px;
    height: 64px;
    margin-top: 12px;
  }

  .home-hero h1 {
    font-size: 24px;
  }

  .cover-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .share-actions {
    flex-direction: column;
  }
}

/* ===== 顶部导航 ===== */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

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

.nav-links {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav-links a,
.nav-links button {
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 0;
  min-height: 0;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}

.nav-links a:hover,
.nav-links button:hover {
  color: var(--accent);
  background: transparent;
}

.nav-links .nav-user {
  color: var(--muted);
  font-weight: 600;
}

/* ===== 首页 / 分享书架视图 ===== */
.home-view,
.shelf-view {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px 20px 0;
}

/* 首页顶部特性 banner */
.home-banner {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.banner-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px 20px;
  min-height: 140px;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.banner-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  z-index: 1;
}

.banner-icon {
  width: 72px;
  height: 72px;
  margin-top: 16px;
  display: block;
}

.banner-headline,
  font-size: 19px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.banner-sub {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.home-hero {
  text-align: center;
  margin-bottom: 24px;
}

.home-hero h1 {
  font-size: 32px;
  margin-bottom: 8px;
}

.home-stats,
.shelf-stats {
  color: var(--muted);
  font-size: 14px;
}

.shelf-header {
  margin-bottom: 18px;
}

.shelf-header h1 {
  font-size: 22px;
  margin-bottom: 4px;
}

/* ===== 封面网格 ===== */
.cover-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}

.cover-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cover-card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: #eef2f4;
  display: block;
}

.cover-card .cover-title {
  font-size: 13px;
  line-height: 1.3;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cover-card .cover-author,
.cover-card .cover-owner {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cover-card .cover-owner {
  margin-top: -2px;
}

/* ===== 分享管理面板 ===== */
.share-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 12px;
}

.panel-header h2 {
  margin-bottom: 4px;
}

.share-active {
  display: grid;
  gap: 10px;
}

.share-active input {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.share-actions {
  display: flex;
  gap: 10px;
}

.share-actions button {
  flex: 1;
}

#share-expires {
  font-size: 12px;
  color: var(--muted);
}

/* ===== 空结果与加载更多 ===== */
.empty-hint {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px;
  font-size: 14px;
}

#home-load-more {
  display: block;
  margin: 18px auto 0;
  min-width: 140px;
}

.site-footer {
  margin-top: 10px;
  padding: 0 0 24px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer .footer-sep {
  margin: 0 8px;
  color: var(--muted);
}

.site-footer .footer-link {
  cursor: pointer;
}

/* ===== 首页底部帮助入口卡片 ===== */
.home-help-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 24px auto 0;
  padding: 18px 24px;
  /* max-width: 520px; */
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.home-help-entry:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.home-help-title {
  font-size: 15px;
  font-weight: 600;
}

.home-help-sub {
  font-size: 12px;
  color: var(--muted);
}

/* ===== 帮助页 ===== */
.help-view {
  padding: 24px 16px 48px;
}

.help-container {
  max-width: 720px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 28px 24px;
}

.help-container > h1 {
  font-size: 22px;
  margin: 0 0 8px;
}

.help-intro {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.help-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

.help-actions a {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}

.help-actions a.primary {
  background: var(--accent);
  color: #fff;
}

.help-actions a.help-back-home {
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  padding: 8px 4px;
}

.help-block {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.help-block:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 8px;
}

.help-block h2 {
  font-size: 17px;
  margin: 0 0 10px;
}

.help-block h3 {
  font-size: 14px;
  margin: 18px 0 6px;
  color: var(--text);
}

.help-block p {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}

.help-block ol {
  margin: 0 0 12px;
  padding-left: 22px;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
}

.help-block ol li {
  margin-bottom: 4px;
}

.help-tip {
  margin: 14px 0 4px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.03);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}

.help-tip strong {
  color: var(--accent);
}

@media (max-width: 720px) {
  .help-view {
    padding: 16px 12px 32px;
  }
  .help-container {
    padding: 20px 16px;
  }
}

tbody td.empty-hint {
  padding: 24px 10px;
}

/* ===== 站内信:未读徽章 ===== */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  padding: 0 5px;
  margin-left: 4px;
  font-weight: 600;
}

/* ===== 站内信:联系书主按钮(书卡内)===== */
.cover-card .contact-btn {
  min-height: 30px;
  font-size: 12px;
  padding: 0 10px;
  margin-top: 4px;
  width: 100%;
}

/* ===== 站内信:消息视图 ===== */
.messages-view {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.messages-view h2 {
  margin-bottom: 12px;
}

#conv-list-panel h2 {
  font-size: 20px;
}

.conv-item {
  display: flex;
  gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  align-items: center;
  position: relative;
}

.conv-item:hover {
  background: #f7fafb;
}

.conv-item.unread {
  background: #f0f7f6;
}

.conv-cover {
  width: 40px;
  height: 56px;
  border-radius: 4px;
  object-fit: cover;
  background: #eef2f4;
  flex-shrink: 0;
}

.conv-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  overflow: hidden;
}

.conv-peer {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
  flex-shrink: 0;
}

.conv-book-title {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-last {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: var(--muted);
}

.conv-unread {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

/* 会话详情 */
#conv-detail-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#conv-back {
  align-self: flex-start;
}

#conv-book-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.conv-detail-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.conv-detail-head .conv-peer {
  font-size: 15px;
}

.conv-detail-sep {
  color: var(--muted);
}

.conv-detail-title {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-delete-btn {
  min-height: 30px;
  font-size: 12px;
  padding: 0 10px;
  flex-shrink: 0;
}

.conv-messages {
  max-height: 50vh;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafcfc;
  padding-left: 12px;
  padding-right: 12px;
}

.msg-mine {
  text-align: right;
  margin: 6px 0;
}

.msg-other {
  text-align: left;
  margin: 6px 0;
}

.msg-bubble {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 12px;
  max-width: 75%;
  word-break: break-word;
  text-align: left;
  font-size: 14px;
  line-height: 1.4;
}

.msg-mine .msg-bubble {
  background: var(--accent);
  color: #fff;
}

.msg-other .msg-bubble {
  background: #eef3f5;
  color: inherit;
}

.conv-reply-form {
  display: flex;
  gap: 8px;
}

.conv-reply-form input {
  flex: 1;
}

/* ===== 模态框 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
  z-index: 100;
}

.modal-box {
  background: var(--panel);
  border-radius: 8px;
  padding: 20px;
  width: min(440px, 92vw);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-box h2 {
  font-size: 18px;
}

.modal-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

#contact-book-preview {
  padding: 10px 12px;
  background: #f7fafb;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-book-title {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.contact-book-meta {
  font-size: 12px;
  color: var(--muted);
}

#contact-body {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

#location-modal .modal-box input[type="text"] {
  width: 100%;
  margin: 0;
  box-sizing: border-box;
}

/* ===== 移动端站内信适配 ===== */
@media (max-width: 720px) {
  .messages-view {
    padding: 16px 12px 32px;
  }

  .conv-reply-form {
    flex-direction: column;
  }

  #conv-book-info {
    flex-direction: column;
    align-items: stretch;
  }

  .conv-delete-btn {
    align-self: flex-start;
  }
}
