:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #667eea;
  --primary-2: #764ba2;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 12px;
}

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

html, body {
  height: 100%;
}

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

/* Layout */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100vh;
  background: linear-gradient(180deg, #1f2a44 0%, #172033 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

.sidebar-header {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 700;
  letter-spacing: 0.2px;
}

.sidebar-header i {
  color: #8ea2ff;
  font-size: 1.1rem;
}

.sidebar-nav {
  padding: 12px;
  display: grid;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #dbe3ff;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  transition: all 0.2s ease;
}

.nav-item i {
  width: 18px;
  text-align: center;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-item.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  color: #fff;
}

.main-content {
  margin-left: 260px;
  min-height: 100vh;
  padding: 20px;
}

/* Header */
.header {
  height: 72px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.menu-toggle {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  color: var(--muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.menu-toggle:hover {
  background: #eef2ff;
  color: var(--primary);
}

.header-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  height: 42px;
}

.header-search i {
  color: var(--muted);
}

.header-search input {
  border: none;
  outline: none;
  width: 100%;
  background: transparent;
  font-size: 0.95rem;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.store-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
}

.store-switcher label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.store-selector {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  min-width: 170px;
}

.active-store-badge {
  background: #edf2f7;
  color: #2d3748;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--primary);
  border-color: #cbd5e1;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  display: grid;
  place-items: center;
  padding: 0 5px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
}

.user-profile img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

/* Sections */
.content-section {
  display: none;
}

.content-section.active {
  display: block;
}

.section-header {
  margin-bottom: 16px;
}

.section-header h1 {
  font-size: 1.65rem;
  margin-bottom: 4px;
}

.section-header p {
  color: var(--muted);
}

/* Cards / Grids */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1rem;
}

.stat-info h3 {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.stat-number {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 2px 0 4px;
}

.stat-change {
  font-size: 0.8rem;
}

.stat-change.positive { color: var(--success); }
.stat-change.neutral { color: var(--muted); }
.stat-change.negative { color: var(--danger); }

.charts-grid,
.activity-grid,
.reports-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}

.chart-card,
.activity-card,
.report-card,
.table-container,
.settings-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.chart-card,
.activity-card,
.report-card {
  padding: 14px;
}

.report-card {
  text-align: center;
}

.report-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin: 0 auto 10px;
  background: #eef2ff;
  display: grid;
  place-items: center;
  color: var(--primary);
}

.report-card h3 { margin-bottom: 6px; }
.report-card p { color: var(--muted); margin-bottom: 12px; }

.chart-container {
  height: 280px;
}

.card-header,
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.view-all {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
}

/* Tables */
.table-container {
  padding: 14px;
  overflow: hidden;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0 10px;
  min-width: 220px;
}

.search-box i { color: var(--muted); }

.search-box input,
.filter-select,
.settings-form input,
.settings-form select {
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.9rem;
  color: var(--text);
}

.filter-select,
.settings-form input,
.settings-form select {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

/* Inventory / categories / settings */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.category-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 14px;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.category-card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
}

.category-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #d5defb;
}

.category-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1rem;
  margin-bottom: 10px;
}

.category-card h3 {
  margin: 0 0 6px;
  font-size: 1.2rem;
  text-transform: capitalize;
}

.category-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.45;
  min-height: 54px;
}

.category-meta {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-weight: 700;
}

.inventory-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.inventory-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.inventory-stat-card i {
  font-size: 1.2rem;
}

.inventory-stat-card h4 {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 2px;
}

.inventory-stat-card p {
  font-weight: 700;
  font-size: 1.2rem;
}

.settings-container {
  display: grid;
  grid-template-columns: 220px 1fr;
  overflow: hidden;
}

.settings-nav {
  border-right: 1px solid var(--border);
  padding: 12px;
  background: var(--surface-2);
}

.settings-nav-item {
  display: block;
  text-decoration: none;
  color: var(--text);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 6px;
}

.settings-nav-item.active,
.settings-nav-item:hover {
  background: #e8edff;
  color: var(--primary);
}

.settings-content {
  padding: 16px;
}

.settings-panel {
  display: none;
}

.settings-panel.active {
  display: block;
}

.settings-form {
  margin-top: 10px;
  display: grid;
  gap: 12px;
  max-width: 500px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.88rem;
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  height: 40px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn i {
  margin-right: 6px;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
}

.btn-primary:hover {
  filter: brightness(1.03);
}

.btn-outline {
  border-color: #cbd5e1;
  background: #fff;
  color: var(--text);
}

.btn-outline:hover {
  background: #f8fafc;
}

.btn-sm {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  height: 30px;
  padding: 0 10px;
  cursor: pointer;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1200;
}

.modal.active {
  display: block;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-content {
  position: relative;
  width: min(860px, 94vw);
  margin: 5vh auto 0;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 18px;
  max-height: calc(90vh - 70px);
  overflow-y: auto;
}

.friendly-form {
  display: grid;
  gap: 14px;
}

.form-section {
  border: 1px solid var(--border);
  background: #fbfdff;
  border-radius: 12px;
  padding: 14px;
}

.form-section h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
  color: #1f2a44;
}

.form-section-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-group {
  margin-bottom: 10px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.84rem;
  color: #334155;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  border: 1px solid #d7deea;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.92rem;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

.form-group input,
.form-group select {
  min-height: 42px;
}

.form-group textarea {
  min-height: 88px;
  resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #9db3ff;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

.form-group input[readonly] {
  background: #f3f6ff;
  color: #475569;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.modal-actions.sticky {
  position: sticky;
  bottom: -18px;
  background: linear-gradient(to top, #ffffff 75%, rgba(255,255,255,0.9) 100%);
  border-top: 1px solid var(--border);
  margin: 0 -18px -18px;
  padding: 12px 18px;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

/* Toast */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 1300;
}

/* Action button styles for table/card actions */
.action-btn {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  margin-left: 4px;
}

.action-btn.edit {
  color: var(--primary);
}

.action-btn.edit:hover {
  background: rgba(102, 126, 234, 0.1);
}

.action-btn.delete {
  color: var(--danger);
}

.action-btn.delete:hover {
  background: rgba(239, 68, 68, 0.1);
}

.action-btn.refresh {
  color: var(--primary);
  padding: 4px;
  margin-left: 4px;
}

.action-btn.refresh:hover {
  background: rgba(102, 126, 234, 0.1);
}

/* Responsive */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .charts-grid,
  .activity-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: min(82vw, 300px);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding: 14px;
  }

  .header {
    height: auto;
    padding: 10px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .header-search {
    order: 2;
    width: 100%;
    min-width: 0;
  }

  .header-actions {
    order: 3;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    align-items: center;
  }

  .store-switcher {
    width: 100%;
    justify-content: space-between;
    min-width: 0;
  }

  .store-selector {
    min-width: 0;
    width: 100%;
  }

  .active-store-badge {
    max-width: 38vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .inventory-stats {
    grid-template-columns: 1fr;
  }

  .settings-container {
    grid-template-columns: 1fr;
  }

  .settings-nav {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .table-container {
    overflow-x: auto;
  }

  .data-table {
    min-width: 760px;
  }
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.report-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.report-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #f3f6ff;
  color: #4c63d2;
}

#suppliers .table-container,
#inventory .table-container {
  overflow-x: auto;
}

#suppliers .data-table,
#inventory .data-table {
  min-width: 860px;
}

@media (max-width: 900px) {
  .reports-grid {
    grid-template-columns: 1fr;
  }
}

#adjustStockBtn {
  min-width: 150px;
}

@media (max-width: 640px) {
  .main-content {
    padding: 10px;
  }

  .section-header h1 {
    font-size: 1.25rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-card,
  .inventory-stat-card,
  .chart-card,
  .activity-card,
  .report-card,
  .table-container {
    padding: 12px;
  }

  .search-box {
    min-width: 100%;
    width: 100%;
  }

  .table-actions {
    width: 100%;
    display: grid;
    gap: 8px;
  }

  .table-header {
    display: grid;
    gap: 10px;
  }

  .table-header > .btn,
  #adjustStockBtn,
  #addSupplierBtn,
  #addCategoryBtn,
  #addProductBtn,
  #addUserBtn {
    width: 100%;
    justify-content: center;
    min-width: 0;
  }

  .header-actions {
    grid-template-columns: 1fr;
  }

  .store-switcher {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px;
    align-items: center;
  }

  .active-store-badge {
    grid-column: 1 / -1;
    justify-self: start;
    max-width: 100%;
  }

  .icon-btn {
    width: 100%;
    height: 40px;
  }

  .user-profile {
    justify-content: center;
    width: 100%;
    border-radius: 10px;
  }

  .user-profile span {
    display: none;
  }

  .data-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .btn,
  .filter-select,
  .store-selector,
  .search-box input,
  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal-content {
    width: 96vw;
    margin-top: 2vh;
  }

  .report-card .btn {
    width: 100%;
    justify-content: center;
  }
}
