:root {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #ea580c;
  --primary-hover: #c2410c;
  --primary-soft: rgba(234, 88, 12, 0.1);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-text: #92400e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --bg-card: #131c31;
  --bg-subtle: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #26334d;
  --primary: #f97316;
  --primary-hover: #fb923c;
  --primary-soft: rgba(249, 115, 22, 0.16);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --warn-border: rgba(245, 158, 11, 0.35);
  --warn-text: #fcd34d;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.875rem;
}

code, pre, input[readonly] {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  font-size: 0.85em;
  border-radius: 5px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text);
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  font-size: 1rem;
  border-radius: 6px;
}

/* Badges & Alerts */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-subtle {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-success {
  background: rgba(22, 163, 74, 0.14);
  color: var(--success);
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 0.9rem;
}

.alert-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
}

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

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

.brand-icon-lg {
  width: 56px;
  height: 56px;
  margin-bottom: 10px;
}

.brand-hero h1 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}

.brand-hero p {
  margin: 0;
  font-size: 0.88rem;
}

.login-form label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.password-input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding-right: 4px;
  margin-bottom: 14px;
}

.password-input-wrap:focus-within {
  border-color: var(--primary);
}

.password-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  margin-right: 8px;
}

.nav-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 10px;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 7px 15px;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-tab.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Main Container */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Upload Settings */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
  align-items: end;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

select,
input[type="text"],
input[type="password"],
input[type="search"] {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

select:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="search"]:focus {
  border-color: var(--primary);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Dropzone */
.dropzone {
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 46px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
  box-shadow: var(--shadow);
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dropzone-icon {
  font-size: 2.8rem;
  margin-bottom: 8px;
}

.dropzone h2 {
  margin: 0 0 8px;
  font-size: 1.12rem;
  font-weight: 600;
}

.dropzone p {
  margin: 0 0 18px;
  font-size: 0.87rem;
}

/* Upload Results */
.results-section {
  margin-top: 24px;
}

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

.results-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.results-title h3 {
  margin: 0;
  font-size: 1.02rem;
}

.results-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.format-pills {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: 8px;
}

.pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
}

.pill.active {
  background: var(--primary);
  color: #fff;
}

.upload-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-item {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  align-items: center;
}

.upload-thumb {
  width: 76px;
  height: 76px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.upload-info-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.upload-filename {
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-all;
}

.upload-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.upload-link-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.upload-link-row input {
  flex: 1;
  min-width: 200px;
  font-size: 0.82rem;
  padding: 7px 10px;
}

.quick-fmt-btns {
  display: flex;
  gap: 5px;
}

/* Gallery */
.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.gallery-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 260px;
}

.input-search {
  max-width: 280px;
}

#gallery-folder-select {
  max-width: 200px;
}

.gallery-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.batch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  border: 1px solid var(--primary);
}

.batch-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 16px;
}

.gallery-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.gallery-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.card-thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 11;
  background: var(--bg-subtle);
  overflow: hidden;
}

.card-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}

.card-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.card-ext-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  text-transform: uppercase;
}

.card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-key {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-submeta {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  gap: 5px;
  margin-top: auto;
}

.card-actions .btn {
  flex: 1;
  padding: 5px 6px;
  font-size: 0.76rem;
}

.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.load-more-wrap {
  margin-top: 24px;
  text-align: center;
}

/* Clients & Info Cards */
.cards-two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 18px;
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.info-card h3 {
  margin: 0 0 10px;
  font-size: 1.02rem;
}

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

.card-header-row h3 {
  margin: 0;
}

.ping-banner {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  margin-bottom: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}

.kv-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.kv-list > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.86rem;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.kv-list > div:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.kv-list dt {
  color: var(--text-muted);
}

.kv-list dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}

.code-field {
  margin-top: 10px;
}

.code-field label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.copy-row {
  display: flex;
  gap: 6px;
}

.code-block {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.78rem;
  overflow-x: auto;
  margin: 12px 0;
  white-space: pre-wrap;
  word-break: break-all;
}

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

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 10, 20, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}

.lightbox-body {
  max-width: 92vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.lightbox-body img {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 8px;
  object-fit: contain;
}

.lightbox-caption {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: #f8fafc;
  font-size: 0.88rem;
}

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

/* Toast */
.toast-container {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  animation: slideUp 0.18s ease-out;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

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

@media (max-width: 640px) {
  .upload-item {
    grid-template-columns: 1fr;
  }
  .upload-thumb {
    width: 100%;
    height: 160px;
  }
}
