/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --surface3: #1e2a4a;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-light: rgba(124, 58, 237, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== LOGIN SCREEN ===== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: radial-gradient(ellipse at center, var(--surface) 0%, var(--bg) 70%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-icon {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 1rem;
}

.login-card h1 {
  text-align: center;
  font-size: 1.5rem;
  margin-bottom: 0.3rem;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.login-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ===== DASHBOARD ===== */
.dashboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.dashboard-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-left {
  flex: 1;
  min-width: 200px;
}

.app-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.header-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface2);
  padding: 0.25rem 0.7rem;
  border-radius: 50px;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-wrapper {
  position: relative;
  min-width: 200px;
}

.search-input {
  width: 100%;
  padding: 0.5rem 0.8rem 0.5rem 2.2rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--primary);
}

.search-icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  pointer-events: none;
}

.header-filters {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.8rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.filter-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-select {
  padding: 0.35rem 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.filter-select:focus {
  border-color: var(--primary);
}

.view-toggle {
  display: flex;
  gap: 0.3rem;
  margin-left: auto;
}

.view-btn {
  padding: 0.35rem 0.6rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.view-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface3);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}

.btn-full {
  width: 100%;
  justify-content: center;
  padding: 0.7rem;
}

/* ===== MAIN CONTENT ===== */
.dashboard-main {
  flex: 1;
  padding: 1.5rem;
}

.loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.empty-state h2 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

/* ===== ITEM GRID ===== */
.item-grid {
  display: grid;
  gap: 1rem;
}

.item-grid.grid-view {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.item-grid.list-view {
  grid-template-columns: 1fr;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.item-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.1);
}

.item-card .card-image {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}

.item-card.list-view .card-image {
  width: 120px;
  aspect-ratio: 1;
  flex-shrink: 0;
}

.item-card.list-view {
  display: flex;
  flex-direction: row;
}

.item-card .card-body {
  padding: 0.8rem 1rem;
  flex: 1;
  min-width: 0;
}

.item-card .card-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-card .card-category {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.15rem 0.5rem;
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
}

.item-card .card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}

.item-card .card-tag {
  background: var(--surface2);
  color: var(--text-muted);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
}

.item-card .card-prompt {
  font-size: 0.78rem;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.item-card .card-actions {
  display: flex;
  gap: 0.4rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.item-card .card-status {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-left: auto;
  align-self: center;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-lg {
  max-width: 700px;
}

.modal-sm {
  max-width: 400px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.2rem;
  line-height: 1;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.5rem;
}

/* ===== FORM ===== */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
}

.required {
  color: var(--danger);
}

.form-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--primary);
}

.form-textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.6rem 0.8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
  transition: border-color 0.2s;
}

.form-textarea:focus {
  border-color: var(--primary);
}

.form-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.form-row .form-group {
  flex: 1;
}

.form-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.form-actions {
  display: flex;
  gap: 0.8rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* ===== FILE DROP ZONE ===== */
.file-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-drop-content {
  pointer-events: none;
}

.file-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.file-drop-content p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.file-hint {
  font-size: 0.75rem !important;
  color: var(--text-dim) !important;
  margin-top: 0.3rem;
}

.file-preview {
  pointer-events: none;
}

.file-preview img {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

.file-info {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* ===== TAGS INPUT ===== */
.tags-input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.tags-display {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 500;
}

.tag-remove {
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.tag-remove:hover {
  opacity: 1;
}

.tags-input-row {
  position: relative;
}

.tag-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 150px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}

.tag-suggestions.show {
  display: block;
}

.tag-suggestion {
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.2s;
}

.tag-suggestion:hover {
  background: var(--primary-light);
}

/* ===== UPLOAD PROGRESS ===== */
.upload-progress {
  margin-bottom: 1rem;
}

.progress-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s;
}

.upload-progress p {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* ===== CATEGORY LIST ===== */
.category-list {
  margin-top: 1rem;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: var(--surface2);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

.category-item .cat-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.category-item .cat-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

.category-item .cat-actions {
  display: flex;
  gap: 0.3rem;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.8rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 2000;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast.success {
  background: var(--success);
  color: #fff;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

.toast.warning {
  background: var(--warning);
  color: #000;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .header-top {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
  }

  .search-wrapper {
    flex: 1;
    min-width: 150px;
  }

  .header-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    flex-wrap: wrap;
  }

  .view-toggle {
    margin-left: 0;
  }

  .item-grid.grid-view {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .modal-content {
    max-width: 100%;
    margin: 0.5rem;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .dashboard-header {
    padding: 0.8rem;
  }

  .dashboard-main {
    padding: 0.8rem;
  }

  .item-grid.grid-view {
    grid-template-columns: 1fr;
  }

  .item-card.list-view .card-image {
    width: 80px;
  }

  .header-stats {
    gap: 0.3rem;
  }

  .stat-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
  }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}