:root {
  --sidebar-bg: #111827;
  --sidebar-border: rgba(255, 255, 255, 0.1);
  --sidebar-text: #eef2ff;
  --sidebar-muted: rgba(238, 242, 255, 0.72);
  --page-bg: linear-gradient(180deg, #fff8ef 0%, #f8fafc 42%, #eef2ff 100%);
  --panel-bg: rgba(255, 255, 255, 0.9);
  --panel-border: rgba(15, 23, 42, 0.08);
  --panel-shadow: 0 20px 44px rgba(15, 23, 42, 0.08);
  --text: #172033;
  --muted: #64748b;
  --line: rgba(15, 23, 42, 0.08);
  --primary: #0f172a;
  --primary-hover: #1f2937;
  --secondary-bg: #fff7ed;
  --secondary-text: #b45309;
  --accent: #f59e0b;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Trebuchet MS", "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--page-bg);
}

.app-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 290px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 14px;
  background:
    radial-gradient(circle at top left, rgba(245, 158, 11, 0.24), transparent 34%),
    linear-gradient(180deg, #111827 0%, #0f172a 100%);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
}

.sidebar-top {
  padding: 10px 12px 0;
}

.sidebar-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.sidebar-sub {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--sidebar-muted);
}

.menu {
  display: grid;
  gap: 8px;
}

.sidebar-content {
  display: contents;
}

.mobile-menu-toggle {
  display: none;
  width: auto;
  min-width: 84px;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--sidebar-text);
}

.mobile-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.18);
}

.menu-link {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
  background: rgba(255, 255, 255, 0.02);
  color: var(--sidebar-text);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.menu-link:hover {
  transform: translateX(2px);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.menu-link.active {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.16);
}

.side-actions {
  display: grid;
  gap: 10px;
}

.sidebar-bottom {
  margin-top: auto;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
}

.user-box-name {
  font-size: 16px;
  font-weight: 700;
}

.user-box-meta {
  margin-top: 6px;
  color: var(--sidebar-muted);
  font-size: 13px;
  line-height: 1.5;
}

.main {
  padding: 22px;
}

.topbar,
.card,
.modal-box {
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(12px);
}

.topbar {
  border-radius: 22px;
  padding: 20px 22px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.topbar p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.panel,
.page {
  display: block;
}

.hidden {
  display: none !important;
}

h2 {
  margin: 0;
  font-size: 24px;
}

h3 {
  margin: 0;
  font-size: 18px;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.card {
  border-radius: 22px;
  padding: 18px;
  margin-bottom: 14px;
}

.grid {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

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

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

.grid.two.compact {
  gap: 12px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.section-head p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.6;
}

.section-head.tight {
  align-items: center;
  margin-bottom: 12px;
}

.form {
  display: grid;
  gap: 12px;
}

.narrow-form {
  max-width: 420px;
}

.form-inline {
  grid-template-columns: minmax(220px, 1fr) repeat(2, minmax(0, auto)) auto;
  align-items: end;
}

.search-form,
.inline-form-row,
.modal-actions,
.action-row {
  display: flex;
  gap: 10px;
  align-items: end;
}

.search-form {
  margin-bottom: 14px;
}

.search-form input {
  flex: 1;
}

.inline-form-row label {
  flex: 1;
}

.inline-button {
  width: auto;
  min-width: 120px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

label.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

input,
select,
textarea,
button {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  font-size: 14px;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.96);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

button {
  border: 0;
  cursor: pointer;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  transition: transform 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--primary-hover);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

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

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

.small-btn {
  padding: 8px 10px;
  font-size: 12px;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(248, 250, 252, 0.92);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.mode-option:hover {
  transform: translateY(-1px);
  border-color: rgba(245, 158, 11, 0.45);
}

.mode-option.active {
  border-color: rgba(245, 158, 11, 0.52);
  background: rgba(255, 247, 237, 0.96);
}

.mode-option input {
  width: auto;
  margin: 0;
}

.task-status {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(15, 23, 42, 0.05);
}

.task-status strong {
  display: block;
  margin-bottom: 4px;
}

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

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(148, 163, 184, 0.28);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

.source-preview {
  border-radius: 18px;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  background: rgba(255, 255, 255, 0.72);
  padding: 12px;
}

.source-preview img {
  width: 100%;
  max-width: 260px;
  display: block;
  border-radius: 16px;
}

.result-card {
  margin-top: 18px;
}

.image-result {
  display: grid;
  place-items: center;
  min-height: 280px;
  padding: 18px;
  border-radius: 22px;
  border: 1px dashed rgba(148, 163, 184, 0.38);
  background:
    radial-gradient(circle at top left, rgba(245, 158, 11, 0.12), transparent 24%),
    rgba(255, 255, 255, 0.82);
  color: var(--muted);
  text-align: center;
}

.image-result img {
  width: 100%;
  max-width: 100%;
  border-radius: 18px;
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.15);
}

.image-result.empty {
  color: var(--muted);
}

.stats {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: #475569;
}

.stat {
  text-align: center;
}

.stat span {
  display: block;
  font-size: 30px;
  font-weight: 700;
  color: var(--primary);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  vertical-align: top;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.table td button {
  width: auto;
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.action-row {
  justify-content: flex-end;
}

.code-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.code-chip {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 247, 237, 0.95);
  border: 1px dashed rgba(245, 158, 11, 0.4);
  color: #9a3412;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(248, 250, 252, 0.82);
}

.pagination button {
  width: auto;
  min-width: 42px;
  padding: 8px 12px;
}

.pagination .active-page {
  background: #111827;
  color: #fff;
}

.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.admin-works {
  display: grid;
  gap: 14px;
}

.work-card {
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.08);
}

.admin-work-card {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
}

.work-media {
  min-height: 220px;
  background: #f8fafc;
}

.work-media img {
  width: 100%;
  height: 100%;
  min-height: 220px;
  object-fit: contain;
  background: #f8fafc;
  display: block;
}

.work-body {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.work-tags {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
  font-size: 12px;
  font-weight: 700;
}

.work-prompt {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}

.work-meta,
.work-account {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 140px;
  padding: 18px;
  border-radius: 18px;
  border: 1px dashed rgba(148, 163, 184, 0.35);
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1000;
}

.modal-box {
  width: min(560px, calc(100vw - 24px));
  padding: 18px;
  border-radius: 22px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-head button {
  width: auto;
  padding: 8px 14px;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1200;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.96);
  color: #fff;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-border);
  }

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

  .grid.two,
  .grid.three,
  .form-inline,
  .admin-work-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-layout {
    min-height: 0;
  }

  .sidebar {
    gap: 8px;
    padding: 10px 10px 12px;
  }

  .sidebar-top {
    padding: 0;
    flex: 1;
  }

  .brand {
    font-size: 16px;
  }

  .sidebar-sub {
    margin-top: 2px;
    font-size: 10px;
    line-height: 1.2;
  }

  .sidebar-topbar {
    align-items: center;
    gap: 10px;
  }

  .mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .sidebar-content {
    display: grid;
    gap: 8px;
    max-height: 480px;
    overflow: hidden;
    transition: max-height 0.22s ease, opacity 0.18s ease, transform 0.18s ease;
  }

  .sidebar-content.collapsed {
    max-height: 0;
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
  }

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

  .menu-link {
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 13px;
  }

  .side-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .side-actions button {
    padding: 8px 10px;
    font-size: 13px;
  }

  .sidebar-bottom {
    margin-top: 0;
    padding: 10px 12px;
    border-radius: 14px;
  }

  .user-box-name {
    font-size: 15px;
  }

  .user-box-meta {
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.4;
  }

  .main {
    padding: 12px;
  }

  .topbar,
  .card,
  .modal-box {
    border-radius: 18px;
  }

  .topbar {
    padding: 16px;
    margin-bottom: 12px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .topbar p {
    margin-top: 6px;
    font-size: 14px;
  }

  .card {
    padding: 16px;
    margin-bottom: 12px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 16px;
  }

  .section-head,
  .work-tags,
  .search-form,
  .inline-form-row,
  .modal-actions,
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-switch,
  .works-grid {
    grid-template-columns: 1fr;
  }

  .task-status {
    padding: 12px;
    gap: 10px;
  }

  .image-result {
    min-height: 220px;
    padding: 12px;
  }

  .table {
    display: block;
    overflow-x: auto;
  }
}
