* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-bg: #1e293b;
  --sidebar-text: #e2e8f0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  transition: transform 0.3s;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
  font-size: 1.2rem;
}

.nav-menu {
  list-style: none;
  padding: 10px 0;
}

.nav-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.2s;
  font-size: 0.9rem;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
}

.nav-item.active {
  background: var(--primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 1.1rem;
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 240px;
  min-height: 100vh;
}

.top-bar {
  background: var(--card-bg);
  padding: 15px 25px;
  display: flex;
  align-items: center;
  gap: 15px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar h1 {
  font-size: 1.3rem;
  flex: 1;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 15px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

.alert-badge {
  background: var(--danger);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

.alert-badge.hidden {
  display: none;
}

#page-content {
  padding: 25px;
}

/* Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 25px;
}

.stat-card {
  background: var(--card-bg);
  padding: 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 5px;
}

.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.success .stat-value { color: var(--success); }

/* Card */
.card {
  background: var(--card-bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.card-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 20px;
}

/* Table */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

tr:hover {
  background: #f1f5f9;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: opacity 0.2s;
}

.btn:hover { opacity: 0.85; }

.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

/* Forms */
.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

select.form-control {
  appearance: auto;
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--card-bg);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 25px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* Image Upload */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-area:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.upload-area.dragging {
  border-color: var(--primary);
  background: #dbeafe;
}

.upload-area img {
  max-width: 300px;
  max-height: 200px;
  margin-top: 10px;
  border-radius: 6px;
}

.upload-area p {
  color: var(--text-muted);
  margin-top: 10px;
}

/* Status badges */
.badge {
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  display: inline-block;
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 8px;
  color: white;
  font-size: 0.9rem;
  z-index: 300;
  animation: slideIn 0.3s;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }

@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-toggle {
    display: block;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .emoji {
  font-size: 3rem;
  margin-bottom: 15px;
}


/* Login Screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-box {
  background: var(--card-bg);
  padding: 40px;
  border-radius: 16px;
  width: 90%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-box h2 {
  margin-bottom: 5px;
  font-size: 1.4rem;
}

.login-box .form-control {
  text-align: center;
  font-size: 1rem;
  padding: 12px;
}


/* ===== MOBILE FULL OVERRIDE ===== */
@media (max-width: 768px) {
  /* Sidebar mobile */
  .sidebar {
    width: 280px;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
  }

  /* Overlay khi mở sidebar */
  .sidebar.open ~ .main-content::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 90;
  }

  /* Top bar mobile */
  .top-bar {
    padding: 12px 15px;
    gap: 10px;
  }

  .top-bar h1 {
    font-size: 1.1rem;
  }

  .top-bar-right {
    font-size: 0.75rem;
    gap: 8px;
  }

  #today-date {
    display: none;
  }

  /* Page content mobile */
  #page-content {
    padding: 12px;
  }

  /* Cards mobile */
  .card {
    border-radius: 8px;
    margin-bottom: 12px;
  }

  .card-header {
    padding: 12px 15px;
    font-size: 0.9rem;
    flex-wrap: wrap;
    gap: 8px;
  }

  .card-body {
    padding: 12px 15px;
  }

  /* Stats grid mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 15px;
  }

  .stat-card {
    padding: 12px;
    border-radius: 8px;
  }

  .stat-card .stat-value {
    font-size: 1.2rem;
  }

  .stat-card .stat-label {
    font-size: 0.75rem;
  }

  /* Forms mobile */
  .form-group {
    margin-bottom: 12px;
  }

  .form-group label {
    font-size: 0.8rem;
    margin-bottom: 4px;
  }

  .form-control {
    padding: 10px;
    font-size: 16px; /* Prevent iOS zoom */
    border-radius: 8px;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* 2 cột cho số lượng + đơn vị */
  .form-row-half {
    grid-template-columns: 1fr 1fr;
  }

  /* Buttons mobile */
  .btn {
    padding: 10px 16px;
    font-size: 0.9rem;
    border-radius: 8px;
    min-height: 44px; /* Touch target */
  }

  .btn-sm {
    padding: 8px 12px;
    font-size: 0.8rem;
    min-height: 36px;
  }

  /* Tables mobile - card style */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -15px;
    padding: 0 15px;
  }

  table {
    font-size: 0.78rem;
    min-width: 500px;
  }

  th, td {
    padding: 8px 6px;
    white-space: nowrap;
  }

  th {
    font-size: 0.7rem;
    position: sticky;
    top: 0;
  }

  /* Upload area mobile */
  .upload-area {
    padding: 20px 15px;
    border-radius: 10px;
  }

  .upload-area .btn {
    width: 100%;
    padding: 14px !important;
    font-size: 1rem !important;
    min-height: 50px;
  }

  /* Modal mobile */
  .modal-overlay {
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 20px 16px;
    max-height: 90vh;
    margin: 0;
  }

  .modal-header h3 {
    font-size: 1rem;
  }

  /* Toast mobile */
  .toast {
    bottom: 70px;
    right: 12px;
    left: 12px;
    text-align: center;
    font-size: 0.85rem;
  }

  /* Login mobile */
  .login-box {
    padding: 30px 24px;
    border-radius: 12px;
  }

  /* Sale items display mobile */
  .sale-item-mobile {
    background: var(--bg);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  /* Search input mobile */
  #search-products {
    max-width: 100% !important;
    margin-bottom: 10px;
  }

  /* Products page mobile - stack actions */
  .product-actions-mobile {
    display: flex;
    gap: 5px;
  }

  /* Image thumbnails mobile */
  .img-thumb-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  /* Bottom safe area for iOS */
  .main-content {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Conversion rows mobile */
  .conversion-row {
    flex-wrap: wrap !important;
    gap: 5px !important;
    padding: 8px;
    background: var(--bg);
    border-radius: 6px;
    margin-bottom: 8px !important;
  }

  .conversion-row .form-control {
    flex: 1 !important;
    width: auto !important;
    min-width: 60px !important;
  }
}


/* Product Cards */
.product-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
}

.product-card-header {
  padding: 12px 15px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.product-card-body {
  padding: 0 15px 10px;
}

.product-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 15px;
}

.product-info-grid .info-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  display: block;
}

.product-info-grid .info-value {
  font-size: 0.85rem;
  font-weight: 500;
  display: block;
}

.product-card-actions {
  padding: 8px 15px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--bg);
}

.product-card-actions .btn {
  flex: 1;
  text-align: center;
}


/* Stat cards with icons */
.stat-card .stat-icon {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

/* Alert cards */
.alert-cards {
  margin-bottom: 15px;
}

.alert-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 15px;
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.1s;
}

.alert-card:active {
  transform: scale(0.98);
}

.alert-card.danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
}

.alert-card.warning {
  background: #fffbeb;
  border: 1px solid #fed7aa;
}

.alert-card.info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.alert-card-icon {
  font-size: 1.5rem;
}

.alert-card div strong {
  font-size: 0.9rem;
  display: block;
}

.alert-card div p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.alert-card-arrow {
  margin-left: auto;
  font-size: 1.5rem;
  color: var(--text-muted);
}

/* List items */
.list-items {
  border-top: 1px solid var(--border);
}

.list-item {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.list-item:last-child {
  border-bottom: none;
}

/* Stat highlight */
.stat-highlight {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.stat-highlight span {
  font-size: 0.85rem;
  color: var(--text-muted);
}
