/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary:    #0d1117;
  --bg-secondary:  #161b22;
  --bg-card:       #1c2130;
  --bg-hover:      #212736;
  --bg-input:      #141923;
  --border:        #30363d;
  --border-light:  #21272e;
  --text-primary:  #e6edf3;
  --text-secondary:#8b949e;
  --text-muted:    #484f58;
  --accent:        #2966F3;
  --accent-hover:  #1a52d6;
  --accent-dim:    rgba(41,102,243,0.15);
  --success:       #3fb950;
  --success-dim:   rgba(63,185,80,0.12);
  --danger:        #f85149;
  --danger-dim:    rgba(248,81,73,0.12);
  --warning:       #d29922;
  --warning-dim:   rgba(210,153,34,0.12);
  --info:          #58a6ff;
  --info-dim:      rgba(88,166,255,0.12);
  --radius:        8px;
  --radius-lg:     12px;
  --shadow:        0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg:     0 8px 32px rgba(0,0,0,0.5);
  --sidebar-width: 240px;
  --header-height: 60px;
  --font:          'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== LAYOUT ===== */
#app { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}
.sidebar-logo {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo svg { color: var(--accent); flex-shrink: 0; }
.sidebar-logo-text { font-size: 1rem; font-weight: 700; letter-spacing: -0.02em; }
.sidebar-logo-text span { color: var(--accent); }

.nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}
.nav-section {
  padding: 16px 16px 4px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  margin: 1px 8px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  user-select: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-username { font-size: 0.875rem; font-weight: 600; truncate: nowrap; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-role { font-size: 0.7rem; color: var(--text-muted); }
.btn-logout {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-logout:hover { background: var(--danger-dim); color: var(--danger); border-color: var(--danger); }

/* ===== MAIN CONTENT ===== */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1rem; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
}
.menu-toggle:hover { background: var(--bg-hover); }

/* ===== PAGE CONTENT ===== */
.page {
  display: none;
  padding: 24px;
  flex: 1;
  animation: fadeIn 0.2s ease;
}
.page.active { display: block; }

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.02em; }
.page-subtitle { font-size: 0.875rem; color: var(--text-secondary); margin-top: 2px; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: 0.9rem; font-weight: 600; }
.card-body { padding: 20px; }

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.stat-icon.blue  { background: var(--accent-dim); color: var(--accent); }
.stat-icon.green { background: var(--success-dim); color: var(--success); }
.stat-icon.red   { background: var(--danger-dim); color: var(--danger); }
.stat-icon.yellow{ background: var(--warning-dim); color: var(--warning); }
.stat-icon.info  { background: var(--info-dim); color: var(--info); }

.stat-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }
.stat-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-sub   { font-size: 0.75rem; color: var(--text-secondary); }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th[data-sort] {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
thead th[data-sort]:hover { color: var(--text-primary); }
thead th .sort-ind { color: var(--accent); font-size: 0.7rem; }
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}
tbody td:first-child { color: var(--text-primary); font-weight: 500; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-hover); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-card); border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger-dim); color: var(--danger); border: 1px solid transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success-dim); color: var(--success); border: 1px solid transparent; }
.btn-success:hover { background: var(--success); color: #fff; }
.btn-ghost { background: none; color: var(--text-secondary); border: none; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-icon { padding: 7px; border-radius: var(--radius); }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-row.cols-3 { grid-template-columns: repeat(3, 1fr); }

label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
label .required { color: var(--danger); margin-left: 2px; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.875rem;
  transition: border-color 0.15s;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
select option { background: var(--bg-card); }
textarea { resize: vertical; min-height: 80px; }

.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.form-check-label { font-size: 0.875rem; color: var(--text-secondary); }

/* ===== SEARCH / FILTER BAR ===== */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-input {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  gap: 8px;
  flex: 1;
  min-width: 200px;
}
.search-input svg { color: var(--text-muted); flex-shrink: 0; }
.search-input input { background: none; border: none; padding: 8px 0; flex: 1; color: var(--text-primary); font-size: 0.875rem; outline: none; }
.filter-select { padding: 8px 12px; min-width: 130px; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-green   { background: var(--success-dim); color: var(--success); }
.badge-red     { background: var(--danger-dim); color: var(--danger); }
.badge-blue    { background: var(--accent-dim); color: var(--accent); }
.badge-yellow  { background: var(--warning-dim); color: var(--warning); }
.badge-gray    { background: rgba(139,148,158,0.12); color: var(--text-secondary); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeOverlay 0.2s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes fadeOverlay { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideModal 0.25s ease;
}
.modal-lg { max-width: 760px; }

.sale-item-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.sale-item-row:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

@keyframes slideModal { from { opacity: 0; transform: scale(0.96) translateY(-8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.modal-header {
  padding: 20px 24px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  transition: all 0.15s;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
}

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  min-width: 260px;
  max-width: 380px;
  animation: slideToast 0.25s ease;
  border-left: 3px solid var(--border);
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.info    { border-left-color: var(--accent); }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success svg { color: var(--success); }
.toast.error svg   { color: var(--danger); }
.toast.info svg    { color: var(--accent); }

@keyframes slideToast { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 0.875rem; }

/* ===== PROFIT DISPLAY ===== */
.profit-positive { color: var(--success); font-weight: 600; }
.profit-negative { color: var(--danger); font-weight: 600; }
.profit-zero { color: var(--text-muted); }

/* ===== LOADING ===== */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row td { text-align: center; padding: 32px; color: var(--text-muted); }

/* ===== SETTINGS TABS ===== */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 20px;
  width: fit-content;
}
.tab {
  padding: 7px 16px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
  border: none;
  background: none;
}
.tab.active { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow); }

/* ===== ACTIVITY FEED ===== */
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.activity-icon.sale    { background: var(--success-dim); color: var(--success); }
.activity-icon.removal { background: var(--warning-dim); color: var(--warning); }
.activity-icon.return  { background: var(--info-dim); color: var(--info); }
.activity-text { flex: 1; min-width: 0; }
.activity-name { font-size: 0.875rem; font-weight: 500; }
.activity-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* ===== SECTION DIVIDER ===== */
.section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 24px;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.login-logo svg { color: var(--accent); }
.login-logo h1 { font-size: 1.25rem; font-weight: 700; }
.login-logo h1 span { color: var(--accent); }
.login-title { font-size: 1.125rem; font-weight: 700; margin-bottom: 4px; }
.login-sub { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 28px; }
.login-error {
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.875rem;
  color: var(--danger);
  margin-bottom: 16px;
  display: none;
}

/* ===== OVERLAY MOBILE ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .section-grid { grid-template-columns: 1fr; }
  .form-row.cols-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 260px; }

  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-overlay.open { display: block; }
  .menu-toggle { display: flex; }

  .main { margin-left: 0; }

  .page { padding: 16px; }
  .page-header { flex-direction: column; align-items: flex-start; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-input { min-width: unset; }

  .modal { margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 95vh; }
  .modal-overlay { align-items: flex-end; padding: 0; }

  #toast-container { bottom: 16px; right: 16px; left: 16px; }
  .toast { max-width: 100%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  table { font-size: 0.8rem; }
  thead th, tbody td { padding: 10px 10px; }
}

/* ===== LIGHTBOX ===== */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.93);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox-overlay.hidden { display: none; }
.lightbox-overlay img {
  max-width: 90vw;
  max-height: calc(90vh - 80px);
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  cursor: default;
}
.lightbox-bar {
  display: flex;
  gap: 12px;
  cursor: default;
}
.lightbox-bar .btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.2);
  color: #fff;
  font-size: .875rem;
}
.lightbox-bar .btn:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.35);
  color: #fff;
}

/* ===== REMOVAL PHOTO THUMBS ===== */
.removal-photo-thumb:hover img {
  opacity: 0.85;
}
.removal-photo-thumb img {
  transition: opacity .15s;
}
