:root {
  color-scheme: light;
  --bg: #f3f4ff;
  --bg-accent: radial-gradient(circle at top left, rgba(99, 102, 241, 0.25), transparent 55%),
    radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.25), transparent 45%),
    #f3f4ff;
  --surface: #ffffff;
  --surface-soft: rgba(255, 255, 255, 0.7);
  --border: rgba(120, 119, 198, 0.2);
  --border-strong: rgba(79, 70, 229, 0.35);
  --text: #1f1f2d;
  --muted: #6b7280;
  --primary: #6366f1;
  --primary-strong: #4f46e5;
  --primary-soft: rgba(99, 102, 241, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.16);
  font-family: "Inter", "SF Pro Display", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.admin-toolbar {
  margin-bottom: 1.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.admin-summary {
  font-weight: 600;
  color: var(--muted);
}

.admin-pagination {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.admin-pagination .ghost {
  min-width: 88px;
}

.admin-page-info {
  font-weight: 600;
  color: var(--primary-strong);
}

.admin-page-size {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.admin-page-size select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  border-radius: 14px;
  padding: 0.45rem 2.5rem 0.45rem 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: var(--surface-soft)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M2 2.5L6 6l4-3.5' fill='none' stroke='%236366f1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right 0.9rem center / 12px 8px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.admin-page-size select:focus {
  outline: none;
  border-color: var(--primary-strong);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  background-color: #fff;
}

.admin-card .history-details span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-footer {
  margin-top: auto;
  padding: 0.6rem 1rem 0.8rem;
  text-align: center;
  color: rgba(148, 163, 184, 0.85);
  font-size: 0.9rem;
}

.footer-content {
  display: inline-flex;
  align-items: baseline;
  gap: 0.65rem;
}

.footer-powered a {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  color: inherit;
  font-weight: 400;
  text-decoration: none;
}

.footer-powered__icon {
  width: 1rem;
  height: 1rem;
}

.footer-powered a:hover,
.footer-powered a:focus-visible {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  padding: 0.65rem 0;
  color: #f8fafc;
}

.topbar-inner {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 0 clamp(1.25rem, 4vw, 3rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-link:focus-visible {
  outline: 3px solid rgba(148, 163, 184, 0.45);
  outline-offset: 4px;
  border-radius: 18px;
}

.brand-mark {
  width: 48px;
  height: auto;
  display: block;
  flex-shrink: 0;
  filter: drop-shadow(0 6px 14px rgba(99, 102, 241, 0.38));
}

.brand-logo {
  width: 48px;
  height: auto;
  object-fit: contain;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-text p {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: rgba(241, 245, 249, 0.7);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  background: transparent;
  color: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.nav-button:hover {
  background: rgba(148, 163, 184, 0.2);
}

.nav-button.active {
  background: #fff;
  color: var(--primary-strong);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.2);
}

.nav-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.content {
  flex: 1;
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3rem) clamp(1.25rem, 4vw, 3rem)
    clamp(1.2rem, 4vw, 1.6rem);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  background: var(--surface);
  border-radius: 28px;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  box-shadow: 0 30px 70px rgba(79, 70, 229, 0.12);
  border: 1px solid var(--border);
}

#view-upload .panel {
  padding: clamp(2.25rem, 5vw, 3.5rem);
  padding-top: clamp(1.25rem, 4vw, 2rem);
}

.panel + .results-list {
  margin-top: 1.5rem;
}

.panel-header {
  margin-bottom: 1.5rem;
}

.panel-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
}

.panel-header.with-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: space-between;
}

.panel-header-main {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1 1 260px;
}

.panel-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-end;
}

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

.warning {
  margin-top: 0.75rem;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
}

.upload-area {
  border: 2px dashed rgba(99, 102, 241, 0.35);
  background: var(--primary-soft);
  border-radius: 24px;
  padding: clamp(2rem, 5vw, 3rem);
  text-align: center;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease,
    background 0.2s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1.25rem;
  min-height: clamp(360px, 55vh, 480px);
}

.upload-area:hover {
  border-color: rgba(79, 70, 229, 0.75);
  background: rgba(99, 102, 241, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.16);
}

.upload-area:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.3);
}

.upload-area.dragover {
  border-color: var(--primary-strong);
  transform: translateY(-3px);
  box-shadow: 0 18px 32px rgba(99, 102, 241, 0.24);
  background: rgba(99, 102, 241, 0.28);
}
.dropzone-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.dropzone-hint {
  margin: 0.35rem 0 1.25rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.panel-actions {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

button {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 0.75rem 1.4rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(99, 102, 241, 0.2);
}

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

button.secondary {
  background: rgba(99, 102, 241, 0.12);
  color: var(--primary-strong);
  border: 1px solid rgba(99, 102, 241, 0.35);
  box-shadow: none;
}

button.secondary:hover {
  filter: brightness(1.05);
}

button.ghost {
  background: transparent;
  color: var(--primary-strong);
  border: 1px solid rgba(99, 102, 241, 0.25);
  box-shadow: none;
}

button.ghost:hover {
  background: rgba(99, 102, 241, 0.1);
}

button.danger {
  background: linear-gradient(135deg, #f87171, #ef4444);
  box-shadow: 0 18px 38px rgba(239, 68, 68, 0.2);
}

input[type="text"],
input[type="url"],
input[type="password"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: var(--surface-soft);
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

input[type="text"]:focus,
input[type="url"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--primary-strong);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
  background: #fff;
}

.form-grid {
  display: grid;
  gap: 1.5rem;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.toggle-item .toggle-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toggle-control input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--primary-strong);
}

.input-with-action {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.input-with-action input {
  flex: 1;
}

.input-with-action button {
  margin-top: 0;
  white-space: nowrap;
}

.form-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.form-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.results-list {
  display: grid;
  gap: 1rem;
}

.result-item {
  background: var(--surface);
  border-radius: 22px;
  padding: 1.25rem 1.5rem;
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow: 0 20px 45px rgba(79, 70, 229, 0.12);
  display: grid;
  gap: 0.9rem;
}

.history-card {
  grid-template-columns: minmax(140px, 180px) 1fr;
  align-items: stretch;
}

.history-thumb {
  width: 100%;
  height: 160px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(148, 163, 184, 0.08);
  object-fit: contain;
}

.thumb-link {
  display: block;
  border-radius: 16px;
  overflow: hidden;
}

.thumb-link:focus-visible {
  outline: 3px solid rgba(99, 102, 241, 0.55);
  outline-offset: 2px;
}

.upload-card .badge {
  align-self: center;
}

.history-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-info {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem;
}

.history-meta {
  flex: 1 1 240px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.history-name,
.history-details {
  line-height: 1.4;
}

.history-name {
  font-weight: 700;
  font-size: 1rem;
  word-break: break-all;
}

.history-info button {
  margin-left: auto;
  flex-shrink: 0;
  white-space: nowrap;
}

.history-details {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--muted);
}

.history-tabs {
  margin-top: auto;
}

.flex-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.image-preview {
  width: 100%;
  height: 220px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(148, 163, 184, 0.08);
  object-fit: contain;
  display: block;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pending-list {
  margin-top: 1.25rem;
  padding: 1.25rem 1.5rem;
  border-radius: 20px;
  border: 1px dashed rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.08);
  display: grid;
  gap: 0.85rem;
}

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

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

.pending-item {
  background: #fff;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 16px;
  padding: 0.9rem;
  display: grid;
  gap: 0.65rem;
  box-shadow: 0 15px 32px rgba(99, 102, 241, 0.12);
}

.pending-thumb {
  width: 100%;
  height: 140px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(148, 163, 184, 0.1);
  object-fit: contain;
  display: block;
}

.pending-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.pending-meta {
  display: grid;
  gap: 0.3rem;
}

.pending-name {
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-all;
}

.pending-size {
  font-size: 0.8rem;
  color: var(--muted);
}

.link-tabs {
  display: grid;
  gap: 0.75rem;
}

.link-tabs-nav {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

button.tab-button {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--primary-strong);
  box-shadow: none;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

button.tab-button:hover:not(.active) {
  background: rgba(99, 102, 241, 0.18);
}

button.tab-button.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(99, 102, 241, 0.16);
}

.link-tabs-input {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.link-tabs-field {
  flex: 1;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: #ffffff;
  color: var(--text);
  font-family: "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  word-break: break-all;
  cursor: pointer;
  user-select: all;
}

.link-tabs-field:focus {
  outline: none;
  border-color: var(--primary-strong);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

button.icon-button {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--primary-strong);
  padding: 0.55rem;
  min-width: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

button.icon-button:hover {
  background: rgba(99, 102, 241, 0.22);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-strong);
  font-size: 0.75rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px dashed rgba(148, 163, 184, 0.3);
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  min-width: 240px;
  max-width: min(360px, 80vw);
  padding: 1rem 1.25rem;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid rgba(148, 163, 184, 0.3);
  box-shadow: 0 24px 50px rgba(15, 23, 42, 0.22);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

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

.toast.success {
  border-color: rgba(34, 197, 94, 0.4);
  box-shadow: 0 24px 50px rgba(34, 197, 94, 0.2);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.45);
  box-shadow: 0 24px 50px rgba(239, 68, 68, 0.2);
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topnav {
    width: 100%;
  }

  .panel {
    border-radius: 22px;
  }

  .upload-area {
    border-radius: 20px;
  }

  .history-card {
    grid-template-columns: 1fr;
  }

  .history-thumb {
    height: 220px;
  }
}

@media (max-width: 600px) {
  .panel-header.with-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-header-actions {
    justify-content: flex-start;
  }

  .panel-header-actions button {
    width: auto;
  }

  .history-info button {
    width: auto;
  }

  .panel-actions {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .results-list {
    gap: 0.75rem;
  }

  .toast {
    left: 50%;
    right: auto;
    transform: translate(-50%, 20px);
  }

  .toast.show {
    transform: translate(-50%, 0);
  }
}
