:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

.app { min-height: 100vh; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

code {
  background: #eef2ff;
  color: #3730a3;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-size: 0.9em;
  word-break: break-all;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}

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

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-sm { padding: 0.45rem 0.7rem; font-size: 0.875rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  width: 42px;
  height: 42px;
  font-size: 1.1rem;
  cursor: pointer;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  text-align: center;
}

#login-form {
  display: grid;
  gap: 0.85rem;
  text-align: left;
  margin-top: 1rem;
}

.brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-weight: 800;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 65px);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem;
}

.sidebar-nav {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.nav-item {
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.nav-item.active,
.nav-item:hover {
  background: #eff6ff;
  color: var(--primary);
}

.content {
  padding: 1rem;
  max-width: 1200px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-header { margin-bottom: 1rem; }
.card-header h2,
.card-header h3 { margin: 0 0 0.35rem; }

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.field input,
.field select,
.search-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  background: #fff;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.preview-box {
  display: grid;
  gap: 0.75rem;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.preview-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.preview-url code { display: block; }

.dropzone {
  display: block;
  border: 2px dashed #93c5fd;
  background: #f8fbff;
  border-radius: 14px;
  padding: 1.25rem;
  cursor: pointer;
  margin-bottom: 1rem;
}

.dropzone.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}

.dropzone-inner { text-align: center; }
.dropzone-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 0.5rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #dbeafe;
  color: var(--primary);
  font-size: 1.4rem;
}

.file-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.file-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.bulk-rules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.bulk-rules article {
  background: #f8fafc;
  border-radius: 12px;
  padding: 1rem;
}

.bulk-rules h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.bulk-item-valid {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.bulk-item-invalid {
  border-color: #fecaca;
  background: #fef2f2;
}

.bulk-item-meta {
  flex: 1;
  text-align: center;
}

.bulk-duplicates {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.bulk-duplicates h4 {
  margin: 0 0 0.5rem;
  color: #b45309;
}

.bulk-duplicate-item {
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
}

.bulk-duplicates-actions {
  margin-top: 0.85rem;
}

.bulk-errors {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.bulk-errors h4 {
  margin: 0 0 0.5rem;
  color: var(--danger);
}

.bulk-error-item {
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
}

.bulk-item-summary,
.bulk-item-more {
  background: #f8fafc;
  font-weight: 600;
}

.bulk-progress {
  margin: 0 0 1rem;
}

.bulk-progress-track {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.bulk-progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.2s ease;
}

.bulk-progress-text {
  margin-top: 0.4rem;
}

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

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

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

.gallery-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.gallery-thumb-wrap {
  aspect-ratio: 4 / 3;
  background: #f1f5f9;
  display: grid;
  place-items: center;
}

.gallery-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gallery-body {
  padding: 0.85rem;
  display: grid;
  gap: 0.45rem;
}

.gallery-title { font-weight: 700; }
.gallery-url { font-size: 0.78rem; word-break: break-all; color: var(--muted); }
.gallery-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

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

.spec-grid article {
  background: #f8fafc;
  border-radius: 12px;
  padding: 1rem;
}

.spec-grid ul { margin: 0.5rem 0 0; padding-left: 1.1rem; }

.result-list {
  display: grid;
  gap: 0.75rem;
}

.result-item {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  background: #0f172a;
  color: #fff;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.error { color: var(--danger); font-size: 0.9rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 65px auto 0 0;
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 30;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .icon-btn { display: inline-grid; place-items: center; }
  .form-grid,
  .spec-grid,
  .bulk-rules { grid-template-columns: 1fr; }
  .row-between { flex-direction: column; }
}

@media (max-width: 520px) {
  .content { padding: 0.75rem; }
  .card { padding: 1rem; }
  .gallery-grid { grid-template-columns: 1fr; }
}
