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

:root {
  --primary:    #1e3a5f;
  --primary-l:  #2d5282;
  --accent:     #3182ce;
  --accent-l:   #4299e1;
  --success:    #38a169;
  --warning:    #d69e2e;
  --danger:     #e53e3e;
  --info:       #3182ce;
  --sidebar-w:  240px;
  --topbar-h:   60px;
  --bg:         #f7fafc;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #2d3748;
  --text-muted: #718096;
  --shadow:     0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,.12);
  --radius:     8px;
  --transition: .18s ease;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .3px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-nav { padding: 12px 0; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: 13.5px;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.13); color: #fff;
                   border-left-color: var(--accent-l); font-weight: 600; }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}
.main.expanded { margin-left: 0; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.btn-menu { background: none; border: none; cursor: pointer; color: var(--text-muted);
            padding: 4px; border-radius: 4px; display: flex; }
.btn-menu:hover { color: var(--text); background: var(--bg); }

.page-title { font-size: 17px; font-weight: 700; color: var(--text); flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.content { flex: 1; padding: 24px; max-width: 1400px; width: 100%; }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 14px;
}
.card-body { padding: 20px; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon.blue   { background: #ebf8ff; color: var(--accent); }
.stat-icon.green  { background: #f0fff4; color: var(--success); }
.stat-icon.yellow { background: #fffff0; color: var(--warning); }
.stat-icon.red    { background: #fff5f5; color: var(--danger); }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all var(--transition);
  text-decoration: none; white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover  { background: var(--accent-l); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { background: #2f855a; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #c53030; }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-warning:hover  { background: #b7791f; }
.btn-outline  { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover  { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: #f0fff4; color: var(--success); }
.badge-warning { background: #fffff0; color: var(--warning); }
.badge-danger  { background: #fff5f5; color: var(--danger); }
.badge-info    { background: #ebf8ff; color: var(--info); }
.badge-gray    { background: #edf2f7; color: var(--text-muted); }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted);
        margin-bottom: 5px; text-transform: uppercase; letter-spacing: .4px; }
input, select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(49,130,206,.15);
}
textarea { resize: vertical; min-height: 80px; }
.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  padding-top: 16px; border-top: 1px solid var(--border); margin-top: 8px;
}

/* ===== SEARCH BAR ===== */
.toolbar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap;
}
.search-box {
  position: relative; flex: 1; min-width: 200px;
}
.search-box input { padding-left: 36px; }
.search-box svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-muted); pointer-events: none;
}

/* ===== PRODUCT IMAGE ===== */
.product-img {
  width: 44px; height: 44px; border-radius: 6px;
  object-fit: cover; border: 1px solid var(--border);
  background: var(--bg);
}
.product-img-placeholder {
  width: 44px; height: 44px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.product-img-placeholder svg { width: 20px; height: 20px; }

/* Upload preview */
.img-preview-wrap { position: relative; display: inline-block; margin-top: 8px; }
.img-preview { max-width: 120px; max-height: 120px; border-radius: var(--radius);
               border: 1px solid var(--border); display: block; object-fit: cover; }
.upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; cursor: pointer;
  color: var(--text-muted); transition: border-color var(--transition);
}
.upload-area:hover { border-color: var(--accent); }
.upload-area input[type=file] { display: none; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 200;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); width: 100%; max-width: 600px;
  max-height: 90vh; display: flex; flex-direction: column;
  animation: slideUp .2s ease;
}
.modal.modal-lg { max-width: 800px; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-size: 16px; font-weight: 700; flex-shrink: 0;
}
.btn-close { background: none; border: none; cursor: pointer; color: var(--text-muted);
             padding: 4px; border-radius: 4px; display: flex; }
.btn-close:hover { color: var(--danger); }
.modal-body { padding: 20px; overflow-y: auto; }

/* ===== TOAST ===== */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999;
                   display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: var(--radius);
  box-shadow: var(--shadow-md); font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  animation: fadeIn .2s ease; min-width: 250px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes fadeIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ===== LOADING ===== */
.loading-spinner { display: flex; justify-content: center; padding: 60px; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: .4; }
.empty-state p { font-size: 15px; }

/* ===== DASHBOARD GRID ===== */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dash-grid .full { grid-column: 1 / -1; }

/* ===== ALERT ROWS ===== */
.alert-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.alert-item:last-child { border-bottom: none; }
.alert-name { font-weight: 500; }
.alert-stock { font-size: 12px; color: var(--danger); }

/* ===== REPORT TABS ===== */
.tab-bar {
  display: flex; gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 18px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; background: none;
  color: var(--text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all var(--transition);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ===== CHIP / STATUS ===== */
.stock-bar-wrap { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.stock-bar { flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.stock-bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.fill-ok      { background: var(--success); }
.fill-warn    { background: var(--warning); }
.fill-danger  { background: var(--danger); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
