@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=ZCOOL+XiaoWei&display=swap');

:root {
  --bg: #f3efe7;
  --paper: #fffaf2;
  --ink: #231f1a;
  --muted: #675f56;
  --line: #d8c9b2;
  --brand: #c96a2d;
  --brand-deep: #844b24;
  --accent: #1f6f5f;
  --accent-soft: #dcefe8;
  --danger: #9a2b2b;
  --shadow: 0 18px 45px rgba(36, 25, 12, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1300px 700px at 12% 0%, rgba(201, 106, 45, 0.2), transparent 56%),
    radial-gradient(1200px 600px at 92% 0%, rgba(31, 111, 95, 0.18), transparent 52%),
    linear-gradient(140deg, #ece4d7, var(--bg));
}

.app-version {
  position: fixed;
  left: 14px;
  bottom: 10px;
  z-index: 90;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--line) 86%, white);
  background: color-mix(in srgb, var(--paper) 85%, white);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 14px rgba(30, 25, 18, 0.1);
}

.backdrop-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image: radial-gradient(rgba(0, 0, 0, 0.24) 0.45px, transparent 0.45px);
  background-size: 3px 3px;
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: 'ZCOOL XiaoWei', serif;
  letter-spacing: 0.02em;
}

button, input, select, textarea {
  font: inherit;
}

.layout {
  position: relative;
  max-width: 1600px;
  margin: 24px auto;
  padding: 0 18px 28px;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: color-mix(in srgb, var(--paper) 92%, white);
  box-shadow: var(--shadow);
}

.side-panel {
  position: sticky;
  top: 16px;
  height: calc(100vh - 56px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--accent);
  font-weight: 700;
}

.side-panel h1 {
  margin-top: 6px;
  font-size: 26px;
  line-height: 1.2;
}

.subtext {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
  font-size: 12.5px;
  flex-shrink: 0;
}

.overview {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  flex-shrink: 0;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
  padding: 10px;
}

.metric span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 3px;
  color: var(--brand);
  font-size: 22px;
}

.metric p {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}

.metric-wide {
  grid-column: 1 / span 2;
}

.settings {
  margin-top: 12px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.55);
  flex-shrink: 0;
}

.settings label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.settings input,
.settings select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  background: #fffcf7;
  color: var(--ink);
  width: 100%;
}

.settings-hint {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}

.btn-collect {
  margin-top: 10px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 32%, transparent);
  outline-offset: 1px;
}

.status-box {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.7);
  flex: 1;
  min-height: 80px;
  overflow-y: auto;
}

.status-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.status-log-entry {
  display: flex;
  gap: 7px;
  align-items: baseline;
  font-size: 12px;
  line-height: 1.45;
  animation: enter 220ms ease both;
}

.log-time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.log-text {
  color: var(--brand-deep);
  font-weight: 600;
}

.actions {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  flex-shrink: 0;
}

.actions button {
  border: none;
  border-radius: 12px;
  padding: 11px 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary {
  background: linear-gradient(120deg, var(--brand), #d37d35);
  color: white;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.75);
  color: var(--muted);
  border: 1px solid var(--line) !important;
  font-size: 13px;
  padding: 9px 12px !important;
}

.actions button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(30, 25, 18, 0.2);
}

.actions button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.main-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn-danger-sm {
  background: var(--danger);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s;
}
.btn-danger-sm:hover { opacity: 0.85; }
.btn-danger-sm:disabled { opacity: 0.5; cursor: not-allowed; }

.main-panel {
  padding: 16px;
}

.tab-nav {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.75);
}

.tab-btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  color: var(--brand-deep);
  background: color-mix(in srgb, var(--brand) 16%, white);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
}

.tab-btn:hover {
  color: var(--brand-deep);
}

.tab-panel[hidden] {
  display: none !important;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 8px;
  margin-bottom: 10px;
}

.main-header h2 {
  font-size: 28px;
}

.main-header p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.history-user-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.history-user-tab {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  min-width: 132px;
  text-align: left;
  transition: all 0.2s ease;
}

.history-user-tab.active {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  background: color-mix(in srgb, var(--brand) 12%, white);
  color: var(--brand-deep);
}

.history-user-tab-name-only {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

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

.history-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.95), rgba(250, 243, 232, 0.72));
  overflow: hidden;
  display: grid;
  animation: enter 320ms ease both;
  position: relative; /* needed for badge absolute positioning */
}

/* ===== Card status badges ===== */
.card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.4;
  pointer-events: none;
}

.card-source-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.4;
  color: white;
  background: color-mix(in srgb, var(--accent) 70%, black);
  pointer-events: none;
}

.badge-recreated {
  background: color-mix(in srgb, var(--brand) 88%, black);
  color: white;
}

.badge-adopted {
  background: color-mix(in srgb, var(--accent) 92%, black);
  color: white;
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.history-cover {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #e5d9c8;
}

.history-body {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.history-title {
  font-size: 16px;
  line-height: 1.4;
}

.history-meta,
.history-desc {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(31, 111, 95, 0.34);
  background: rgba(31, 111, 95, 0.1);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
}

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

.card-actions button {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.card-actions .detail-btn {
  background: #fffdf8;
  color: var(--accent);
}

.card-actions .recreate-btn {
  background: color-mix(in srgb, var(--brand) 18%, white);
  color: var(--brand-deep);
}

.card-actions button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ===== Recreated history list ===== */
.recreated-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

/* Pending recreation placeholder card */
.gen-pending-card {
  opacity: 0.8;
}

.gen-pending-cover {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: linear-gradient(135deg, #e8d9c5, #d4c4b0);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gen-pending-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(201, 106, 45, 0.25);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.gen-cover-placeholder {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #e5d9c8;
}

/* ===== Source note content card ===== */
.source-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  padding: 12px;
  margin-top: 6px;
}

.source-card-clickable {
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.source-card-clickable:hover {
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
  box-shadow: 0 4px 14px rgba(30, 25, 18, 0.1);
}

.source-card-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.source-card-cover {
  width: 60px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  background: #e5d9c8;
  flex-shrink: 0;
}

.source-card-info {
  flex: 1;
  min-width: 0;
}

.source-card-info h4 {
  font-size: 15px;
  line-height: 1.35;
  margin: 0;
}

.source-card-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

.source-card-text {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
  max-height: 120px;
  overflow: hidden;
}

.source-card-images {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.source-card-images img {
  width: 70px;
  height: 93px;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
  flex-shrink: 0;
}

.source-card-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 0;
}

/* ===== Generation detail in modal ===== */
.gen-detail-section {
  margin-bottom: 4px;
}

.gen-detail-label {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.gen-detail-divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.empty-note {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.recreated-body {
  margin: 8px 0;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
}

.image-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.image-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #ecdfcb;
  margin: 0;
}

.image-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

.image-card footer {
  padding: 7px;
}

.image-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.note-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.note-actions button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  background: color-mix(in srgb, var(--accent) 15%, white);
  color: var(--accent);
}

.note-actions button:hover {
  background: color-mix(in srgb, var(--accent) 24%, white);
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 36%, transparent);
}

a:hover {
  color: var(--brand-deep);
  border-bottom-color: color-mix(in srgb, var(--brand-deep) 56%, transparent);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(29, 21, 14, 0.7);
  padding: 16px;
}

.modal[hidden] {
  display: none !important;
}

.modal-dialog {
  width: min(1050px, 94vw);
  max-height: 90vh;
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fffaf1;
  padding: 16px;
  position: relative;
}

.modal-close {
  position: sticky;
  top: 0;
  left: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  background: white;
  color: var(--muted);
}

.detail-content h3 {
  font-size: 26px;
  margin-top: 6px;
}

.detail-content-note {
  display: grid;
  gap: 12px;
}

.detail-header {
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--brand) 25%, var(--line));
  border-radius: 14px;
  background:
    linear-gradient(140deg, rgba(201, 106, 45, 0.12), rgba(255, 255, 255, 0.92)),
    rgba(255, 255, 255, 0.84);
}

.detail-eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--brand-deep);
  font-weight: 700;
}

.detail-meta-readable {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.detail-meta-item {
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line));
  border-radius: 10px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--accent-soft) 40%, white);
  min-height: 74px;
}

.detail-meta-label {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.detail-meta-value {
  margin: 5px 0 0;
  font-size: 13px;
  line-height: 1.4;
  font-weight: 700;
  color: var(--ink);
  word-break: break-word;
}

.detail-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.7);
}

.detail-section-title {
  margin: 0 0 8px;
  color: var(--brand-deep);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.detail-content .detail-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.78;
  font-size: 14px;
  color: var(--ink);
  border-left: 3px solid color-mix(in srgb, var(--brand) 45%, var(--line));
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
}

.detail-images {
  margin-top: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.detail-images img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

.detail-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.detail-actions button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(120deg, var(--brand), #d37d35);
  color: white;
}

.detail-actions button[disabled] {
  opacity: 0.62;
  cursor: not-allowed;
}

.detail-empty-text {
  color: var(--muted);
  font-size: 12px;
}

.detail-images .detail-empty-text {
  grid-column: 1 / -1;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(24, 18, 13, 0.85);
  padding: 20px;
}

.lightbox[hidden] {
  display: none !important;
}

.lightbox img {
  width: min(86vw, 700px);
  max-height: 90vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.lightbox-close {
  position: fixed;
  top: 14px;
  right: 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 1300px) {
  .history-grid,
  .recreated-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-images {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: relative;
    top: 0;
    height: auto;
  }

  .history-grid,
  .recreated-list,
  .image-grid,
  .detail-images {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-user-tab {
    min-width: 110px;
  }

  .detail-meta-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .history-grid,
  .recreated-list,
  .image-grid,
  .detail-images {
    grid-template-columns: 1fr;
  }

  .main-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .main-header h2 {
    font-size: 24px;
  }

  .source-card-header {
    flex-direction: column;
  }
}
