/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 240px;
  --topbar-h:  60px;

  --bg-sidebar:  #18181b;
  --bg-main:     #f4f4f5;
  --bg-card:     #ffffff;
  --bg-hover:    #27272a;
  --bg-active:   #3f3f46;

  --text-primary:   #09090b;
  --text-secondary: #71717a;
  --text-sidebar:   #a1a1aa;
  --text-sidebar-a: #ffffff;

  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --danger:       #dc2626;
  --danger-hover: #b91c1c;
  --success:      #16a34a;

  --border:       #e4e4e7;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', monospace;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── LOGIN PAGE ──────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg-sidebar);
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,.3);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand .wordmark {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.login-brand .sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-card);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

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

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

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

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

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

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon {
  padding: 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg-main); color: var(--text-primary); }
.btn-icon.danger:hover { background: #fef2f2; color: var(--danger); }

.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.login-error.show { display: block; }

/* ── DASHBOARD LAYOUT ────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid #27272a;
}

.sidebar-brand .wordmark {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: #fff;
}

.sidebar-brand .sub {
  font-size: 11px;
  color: #52525b;
  margin-top: 2px;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #52525b;
  padding: 20px 20px 8px;
}

.sidebar-nav {
  flex: 1;
  list-style: none;
  padding: 4px 10px;
}

.sidebar-nav li { margin-bottom: 2px; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .12s, color .12s;
}

.sidebar-nav a:hover {
  background: var(--bg-hover);
  color: #fff;
}

.sidebar-nav a.active {
  background: var(--bg-active);
  color: var(--text-sidebar-a);
}

.sidebar-nav .icon {
  width: 18px;
  height: 18px;
  opacity: .7;
  flex-shrink: 0;
}

.sidebar-nav a.active .icon,
.sidebar-nav a:hover .icon { opacity: 1; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid #27272a;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 4px;
}

.avatar {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user .name {
  font-size: 13px;
  color: #d4d4d8;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #71717a;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: background .12s, color .12s;
  text-align: left;
}

.btn-logout:hover { background: var(--bg-hover); color: #fff; }

/* Main content */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

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

/* Content area */
.content {
  padding: 28px;
  flex: 1;
}

/* Page header */
.page-header {
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.page-header p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.page-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.image-count {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── IMAGE GRID ──────────────────────────────────────────────────────────── */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.image-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow .15s, transform .15s;
  position: relative;
  cursor: grab;
}

.image-card:active { cursor: grabbing; }

.image-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.image-card.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.image-card.dragging { opacity: .4; }

.image-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  background: var(--bg-main);
}

.image-info {
  padding: 12px;
}

.image-name {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 2px;
}

.image-alt {
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-style: italic;
  min-height: 1.3em;
}

.image-alt:empty::before {
  content: 'Tidak ada alt text';
  color: var(--text-secondary);
  font-style: normal;
}

.image-actions {
  display: flex;
  gap: 4px;
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.drag-hint {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,.5);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}

.image-card:hover .drag-hint { opacity: 1; }

/* Status badge aktif/draft */
.status-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
}

.badge-active {
  background: #16a34a;
  color: #fff;
}

.badge-draft {
  background: rgba(0,0,0,.45);
  color: #fff;
}

/* Card aktif — border hijau */
.image-card.card-active {
  outline: 2px solid #16a34a;
  outline-offset: 2px;
}

/* Empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: .4;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-state p { font-size: 14px; }

/* ── UPLOAD ZONE ─────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-bottom: 24px;
}

.upload-zone:hover,
.upload-zone.drag-active {
  border-color: var(--accent);
  background: rgba(37,99,235,.04);
}

.upload-zone svg {
  width: 36px;
  height: 36px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.upload-zone p {
  font-size: 14px;
  color: var(--text-secondary);
}

.upload-zone strong { color: var(--accent); cursor: pointer; }

.upload-zone small {
  display: block;
  font-size: 12px;
  color: #a1a1aa;
  margin-top: 4px;
}

/* ── MODAL ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, visibility .2s;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  transform: translateY(10px);
  transition: transform .2s;
}

.modal-backdrop.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-body { padding: 20px 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.modal-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--bg-main);
  margin-bottom: 16px;
}

/* ── TOAST ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--text-primary);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  animation: slideIn .25s ease;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

.toast.removing { animation: slideOut .25s ease forwards; }

/* ── LOADING SPINNER ─────────────────────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

.spinner-dark {
  border-color: rgba(0,0,0,.1);
  border-top-color: var(--accent);
}

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

.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── FORM WITHIN MODAL ───────────────────────────────────────────────────── */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-card);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.field .hint {
  font-size: 12px;
  color: #a1a1aa;
  margin-top: 4px;
}

/* upload preview strip inside modal */
.upload-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.upload-preview-img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--bg-main);
}

/* ── RESPONSIVE ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); width: 240px; }
  .main { margin-left: 0; }
}
