/* Admin Panel – Korean Auto Spare Parts */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #c8102e;
  --primary-dark: #a00d24;
  --dark: #111827;
  --sidebar-bg: #1e2330;
  --sidebar-w: 240px;
  --white: #ffffff;
  --light: #f9fafb;
  --border: #e5e7eb;
  --gray: #6b7280;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--light);
  color: var(--dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── LOGIN SCREEN ─── */
.login-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--dark) 0%, #1e2330 100%);
}
.login-box {
  background: var(--white);
  border-radius: 16px;
  padding: 2.5rem 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 40px rgba(0,0,0,.25);
  text-align: center;
}
.login-logo {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--dark);
  margin-bottom: .25rem;
}
.login-logo span { color: var(--primary); }
.login-sub {
  font-size: .85rem;
  color: var(--gray);
  margin-bottom: 2rem;
}
.login-label {
  display: block;
  text-align: left;
  font-size: .82rem;
  font-weight: 600;
  color: var(--dark);
  margin-bottom: .4rem;
}
.login-input {
  width: 100%;
  padding: .7rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  outline: none;
  margin-bottom: 1rem;
  transition: border-color .2s;
}
.login-input:focus { border-color: var(--primary); }
.login-btn {
  width: 100%;
  padding: .8rem;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s;
  margin-top: .25rem;
}
.login-btn:hover { background: var(--primary-dark); }
.login-error {
  color: var(--danger);
  font-size: .82rem;
  margin-top: .5rem;
  min-height: 1.2rem;
}

/* ─── APP SHELL ─── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--white);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
}
.sidebar-brand {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo-text {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--white);
}
.sidebar-brand .logo-sub {
  font-size: .72rem;
  color: rgba(255,255,255,.4);
  margin-top: .1rem;
}
.sidebar-brand .logo-text span { color: var(--primary); }
.sidebar-nav { flex: 1; padding: 1rem 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1.25rem;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--white); background: rgba(255,255,255,.06); }
.nav-item.active { color: var(--white); background: rgba(200,16,46,.18); border-left-color: var(--primary); }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-footer a {
  display: flex; align-items: center; gap: .5rem;
  color: rgba(255,255,255,.5);
  font-size: .82rem;
  text-decoration: none;
}
.sidebar-footer a:hover { color: var(--white); }

/* ─── MAIN CONTENT ─── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-title { font-size: 1.15rem; font-weight: 700; }
.topbar-user {
  display: flex; align-items: center; gap: .5rem;
  font-size: .85rem; color: var(--gray);
}
.topbar-user .avatar {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 50%;
  color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem;
}
.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem .75rem;
  font-size: .8rem;
  cursor: pointer;
  color: var(--gray);
  transition: all .2s;
}
.logout-btn:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.page-content { flex: 1; padding: 1.75rem; }

/* ─── STATS CARDS ─── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1rem;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-icon.red { background: rgba(200,16,46,.12); }
.stat-icon.blue { background: rgba(59,130,246,.12); }
.stat-icon.green { background: rgba(16,185,129,.12); }
.stat-icon.purple { background: rgba(139,92,246,.12); }
.stat-val { font-size: 1.7rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: .78rem; color: var(--gray); margin-top: .2rem; }

/* ─── TOOLBAR (above table) ─── */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.toolbar-left { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.search-input {
  padding: .55rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .88rem;
  outline: none;
  width: 240px;
  transition: border-color .2s;
}
.search-input:focus { border-color: var(--primary); }
.select-filter {
  padding: .55rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .88rem;
  outline: none;
  background: #fff;
  cursor: pointer;
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem 1.25rem;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all .2s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.9); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.9); }
.btn-outline { background: transparent; color: var(--dark); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--dark); }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; border-radius: 6px; }
.btn-icon-only { padding: .35rem .5rem; }

/* ─── TABLE ─── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  background: var(--light);
  padding: .75rem 1rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 700;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: .75rem 1rem;
  font-size: .88rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }

.product-thumb {
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--light);
}
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 20px;
  font-size: .73rem;
  font-weight: 700;
}
.badge-hyundai { background: #e0f2fe; color: #0369a1; }
.badge-kia { background: #fef9c3; color: #854d0e; }
.badge-ssangyong { background: #f3e8ff; color: #7e22ce; }
.badge-daewoo { background: #dcfce7; color: #166534; }
.badge-chevrolet { background: #fee2e2; color: #b91c1c; }
.badge-other { background: #f1f5f9; color: #475569; }

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-box {
  background: var(--white);
  border-radius: 14px;
  width: 100%;
  max-width: 700px;
  overflow: visible;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
  padding: .85rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  background: transparent; border: none;
  font-size: 1.4rem; cursor: pointer; color: var(--gray);
  line-height: 1; padding: .2rem .4rem;
}
.modal-close:hover { color: var(--dark); }
.modal-body { padding: .75rem 1rem; overflow: visible; flex: 1; }
.modal-footer {
  padding: .75rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: .75rem;
}

/* ─── FORM ─── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.form-group { display: flex; flex-direction: column; gap: .2rem; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: .95rem; font-weight: 600; color: var(--dark); }
.form-label span { color: var(--danger); }
.form-input, .form-select {
  padding: .45rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  outline: none;
  font-family: var(--font);
  transition: border-color .2s;
  background: #fff;
}
.form-input:focus, .form-select:focus { border-color: var(--primary); }
.form-hint { font-size: .82rem; color: var(--gray); }
.input-upper { text-transform: uppercase; }

/* ─── IMAGE PREVIEW ─── */
.img-preview {
  width: 100%;
  height: 90px;
  border-radius: 8px;
  border: 1.5px dashed var(--border);
  display: none;
  align-items: center; justify-content: center;
  overflow: hidden;
  background: var(--light);
  margin-top: .35rem;
}
.img-preview.has-image { display: flex; }
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-placeholder { color: var(--gray); font-size: .82rem; }

/* ─── FILE UPLOAD ─── */
.file-upload-wrap {
  display: flex;
  gap: .5rem;
  align-items: stretch;
  flex-wrap: nowrap;
}
.file-upload-wrap .form-input { flex: 1; }
.file-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .59rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .83rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--light);
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color .2s, color .2s;
  color: var(--dark);
}
.file-upload-btn:hover { border-color: var(--primary); color: var(--primary); }
.file-upload-btn input[type="file"] { display: none; }

/* ─── TOAST ─── */
#toast {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  background: var(--dark);
  color: #fff;
  padding: .75rem 1.25rem;
  border-radius: 8px;
  font-size: .88rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  transition: all .3s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.success { background: var(--success); }
#toast.error { background: var(--danger); }

/* ─── CONFIRM DIALOG ─── */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.confirm-box {
  background: var(--white);
  border-radius: 14px;
  padding: 2rem;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.confirm-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.confirm-title { font-size: 1.1rem; font-weight: 700; margin-bottom: .5rem; }
.confirm-msg { color: var(--gray); font-size: .9rem; margin-bottom: 1.5rem; }
.confirm-actions { display: flex; gap: .75rem; justify-content: center; }

/* ─── EMPTY STATE ─── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--gray);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--dark); margin-bottom: .4rem; }

/* ─── PAGINATION ─── */
.pagination {
  display: flex; align-items: center; gap: .5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: .85rem; color: var(--gray);
}
.pagination-btn {
  padding: .35rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: .82rem;
  transition: all .2s;
}
.pagination-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination-btn:disabled { opacity: .4; cursor: not-allowed; }
.pagination-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .search-input { width: 160px; }
}
@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
}

/* ─── BRAND LOGO MINI (brands management table) ─── */
.brand-logo-mini {
  width: 36px; height: 36px;
  background: var(--primary); color: #fff;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1rem;
}

/* ─── PHASE 18: ADMIN UX ENHANCEMENTS ─── */

/* Sortable column headers */
th.sortable { cursor: pointer; user-select: none; transition: background .15s; }
th.sortable:hover { background: rgba(200,16,46,.05); }
th.sortable .sort-ind { color: var(--primary); font-weight: bold; font-size: .75rem; margin-left: .15rem; }

/* Inline quantity cell */
.qty-cell {
  display: inline-block;
  min-width: 36px;
  padding: .15rem .5rem;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  border: 1px dashed transparent;
}
.qty-cell:hover { border-color: var(--primary); background: rgba(200,16,46,.05); }
.qty-ok  { color: var(--dark); }
.qty-low { color: var(--warning); background: rgba(245,158,11,.08); }
.qty-out { color: var(--danger); background: rgba(239,68,68,.08); }
.qty-input {
  width: 70px; padding: .2rem .4rem;
  border: 1.5px solid var(--primary);
  border-radius: 6px; font-weight: 700; font-size: .9rem;
  outline: none;
}
.row-out { opacity: .6; }
.row-out:hover { opacity: 1; }

/* Stock tag badges */
.stock-tag {
  margin-left: .35rem;
  font-size: .65rem; font-weight: 800;
  padding: .1rem .35rem; border-radius: 4px;
  letter-spacing: .04em;
  vertical-align: middle;
}
.stock-low { background: var(--warning); color: #fff; }
.stock-out { background: var(--danger); color: #fff; }

/* Page size selector */
.pagesize-sel {
  margin-left: auto; margin-right: .5rem;
  padding: .3rem .5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .82rem;
  background: #fff; color: var(--dark);
  cursor: pointer;
}

/* Sidebar count badges */
.nav-badge {
  display: inline-block;
  margin-left: auto;
  background: var(--primary); color: #fff;
  font-size: .68rem; font-weight: 700;
  padding: .1rem .4rem; border-radius: 999px;
  min-width: 18px; text-align: center;
}
.nav-item { display: flex; align-items: center; }
