/* ===== RESET & VARIABLES ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.12);
  --transition: 200ms ease;
  --sidebar-w: 240px;
}

html { font-size: 14px; }
body {
  font-family: var(--font); color: var(--text); background: var(--bg);
  display: flex; min-height: 100vh; overflow-x: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg);
  color: var(--sidebar-text); display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform var(--transition);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 20px 16px;
  font-size: 15px; font-weight: 700; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.nav { padding: 12px 8px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 6px; color: var(--sidebar-text); text-decoration: none;
  font-size: 13px; font-weight: 500; transition: all var(--transition); cursor: pointer;
}
.nav-link:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link svg { flex-shrink: 0; }

/* ===== MAIN LAYOUT ===== */
.main-wrapper {
  margin-left: var(--sidebar-w); flex: 1;
  display: flex; flex-direction: column; min-height: 100vh;
}
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.menu-btn {
  display: none; background: none; border: none; cursor: pointer;
  color: var(--text-2); padding: 4px;
}
.page-title { font-size: 16px; font-weight: 600; }
.app-content { padding: 24px; flex: 1; }

/* ===== STAT CARDS ===== */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.stat-card .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-card .sub { font-size: 12px; color: var(--text-2); margin-top: 6px; }
.stat-card.primary { border-left: 3px solid var(--primary); }
.stat-card.success { border-left: 3px solid var(--success); }
.stat-card.warning { border-left: 3px solid var(--warning); }
.stat-card.danger  { border-left: 3px solid var(--danger); }

/* ===== CARDS ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600; display: flex;
  align-items: center; justify-content: space-between;
}
.card-body { padding: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  border: 1px solid transparent; cursor: pointer;
  transition: all var(--transition); text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: #b91c1c; }
.btn-ghost   { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover   { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== FORM ELEMENTS ===== */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block; font-size: 11px; font-weight: 600; color: var(--text-2);
  margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em;
}
.form-input, .form-select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-family: var(--font); font-size: 13px;
  color: var(--text); background: var(--surface);
  transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
textarea.form-input { resize: vertical; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ===== SEARCH BAR ===== */
.search-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.search-input-wrap { flex: 1; position: relative; }
.search-input-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none;
}
.search-input {
  width: 100%; padding: 10px 12px 10px 40px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; font-family: var(--font);
  background: var(--surface); color: var(--text);
}
.search-input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ===== FILTER BAR ===== */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filter-bar select {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; font-family: var(--font); color: var(--text);
  background: var(--surface); cursor: pointer;
}

/* ===== BULK EDIT PANEL ===== */
.bulk-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.bulk-panel .form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.bulk-panel .form-group { flex: 1; min-width: 180px; }
.bulk-panel .form-label { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; margin-bottom: 4px; display: block; }
.bulk-panel .form-input, .bulk-panel .form-select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; font-family: var(--font);
}

.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.4); z-index: 1000;
}

/* ===== DATA TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--bg); }
th {
  padding: 10px 12px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-3);
  border-bottom: 2px solid var(--border); white-space: nowrap;
  cursor: pointer; user-select: none;
}
th:hover { color: var(--text); }
td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: #f8fafc; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--primary-light); }
.cust-link { color: var(--primary); text-decoration: none; font-weight: 500; }
.cust-link:hover { text-decoration: underline; }

/* ===== STATUS BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge-inventory { background: var(--primary-light); color: var(--primary); }
.badge-inventory::before { background: var(--primary); }
.badge-sold { background: var(--success-light); color: var(--success); }
.badge-sold::before { background: var(--success); }
.badge-rma { background: var(--warning-light); color: var(--warning); }
.badge-rma::before { background: var(--warning); }
.badge-retired { background: var(--danger-light); color: var(--danger); }
.badge-retired::before { background: var(--danger); }

/* ===== PAGINATION ===== */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px; font-size: 13px; color: var(--text-2);
}
.page-btns { display: flex; gap: 4px; }
.page-btn {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); font-size: 12px; cursor: pointer;
  font-family: var(--font); transition: all var(--transition);
}
.page-btn:hover { background: var(--bg); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== DROP ZONE ===== */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px; text-align: center; transition: all var(--transition); cursor: pointer;
}
.drop-zone:hover, .drop-zone.hover {
  border-color: var(--primary); background: var(--primary-light);
}
.drop-zone p { color: var(--text-2); font-size: 14px; }
.drop-zone .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.drop-zone input[type="file"] { display: none; }

/* ===== HORIZONTAL BAR CHART ===== */
.bar-list { list-style: none; }
.bar-item { margin-bottom: 12px; }
.bar-label { display: flex; justify-content: space-between; font-size: 12px; font-weight: 500; margin-bottom: 4px; }
.bar-label .count { color: var(--text-2); font-weight: 600; }
.bar-track { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--primary); transition: width 800ms cubic-bezier(.4,0,.2,1); }

/* ===== DEVICE DETAIL SLIDE-OVER ===== */
.detail-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.4);
  z-index: 200; transition: opacity 300ms ease;
}
.detail-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 500px; max-width: 100vw;
  background: var(--surface); z-index: 201;
  box-shadow: -8px 0 32px rgba(0,0,0,.15);
  overflow-y: auto; transform: translateX(100%); transition: transform 300ms cubic-bezier(.4,0,.2,1);
}
.detail-panel.open { transform: translateX(0); }
.detail-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.detail-header h2 { font-size: 18px; font-weight: 700; font-family: 'Courier New', monospace; letter-spacing: .02em; }
.detail-close {
  width: 32px; height: 32px; border-radius: 6px; border: none;
  background: var(--bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); font-size: 16px; transition: all var(--transition);
}
.detail-close:hover { background: var(--danger-light); color: var(--danger); }
.detail-section { padding: 16px 24px; border-bottom: 1px solid var(--border); }
.detail-section:last-child { border-bottom: none; }
.detail-section h3 {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-3); margin-bottom: 12px;
}
.detail-grid { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
.detail-grid dt { color: var(--text-3); font-weight: 500; }
.detail-grid dd { color: var(--text); font-weight: 500; }

/* ===== REPAIR TIMELINE ===== */
.repair-timeline { list-style: none; }
.repair-item {
  position: relative; padding: 12px 0 12px 24px;
  border-left: 2px solid var(--border);
}
.repair-item:last-child { border-left-color: transparent; }
.repair-item::before {
  content: ''; position: absolute; left: -5px; top: 18px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warning); border: 2px solid var(--surface);
}
.repair-item .r-date { font-size: 11px; color: var(--text-3); font-weight: 600; letter-spacing: .03em; }
.repair-item .r-rma { font-size: 14px; font-weight: 600; margin: 2px 0; }
.repair-item .r-issue { font-size: 12px; color: var(--text-2); }
.repair-item .r-meta { font-size: 11px; color: var(--text-3); margin-top: 3px; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 20px; border-radius: var(--radius);
  background: var(--text); color: #fff;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); z-index: 999;
  transform: translateY(20px); opacity: 0;
  transition: all 300ms cubic-bezier(.4,0,.2,1); pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(241,245,249,.8);
  display: flex; align-items: center; justify-content: center; z-index: 300;
}
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 600ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== CONFIRM DIALOG ===== */
.confirm-dialog {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; z-index: 400;
}
.confirm-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px; max-width: 380px; width: 90%; box-shadow: var(--shadow-lg);
}
.confirm-card p { font-size: 14px; margin-bottom: 20px; line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ===== IMPORT PREVIEW ===== */
.preview-table { max-height: 280px; overflow-y: auto; margin: 16px 0; border-radius: 6px; border: 1px solid var(--border); }
.preview-table table { font-size: 12px; }
.preview-table th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.import-summary {
  font-size: 13px; padding: 12px 16px; background: var(--primary-light);
  border-radius: 6px; margin: 12px 0; color: var(--primary); font-weight: 500;
}

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty-state p { font-size: 14px; }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.mono { font-family: 'Courier New', monospace; }
.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .menu-btn { display: flex; }
  .topbar { padding: 0 16px; }
  .app-content { padding: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .detail-panel { width: 100vw; }
  .form-row { flex-direction: column; gap: 0; }
}
