:root {
  --primary: #1A73E8;
  --primary-dark: #0D47A1;
  --accent: #00C853;
  --danger: #E53935;
  --warning: #FFA000;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --text: #212121;
  --text2: #757575;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 80px;
}

/* Header */
.header {
  background: var(--primary);
  color: white;
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.header .btn-icon {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 11px;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  transition: all 0.2s;
}

.nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

.nav-item .icon {
  font-size: 22px;
}

/* Pages */
.page {
  display: none;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.page.active {
  display: block;
}

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

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.stats-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  flex: 1;
  background: white;
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card .value {
  font-size: 16px;
  font-weight: 700;
  margin: 6px 0 2px;
}

.stat-card .label {
  font-size: 11px;
  color: var(--text2);
}

.stat-card.blue .value { color: var(--primary); }
.stat-card.green .value { color: var(--accent); }
.stat-card.orange .value { color: var(--warning); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-success {
  background: var(--accent);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text2);
}

.form-control {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #E0E0E0;
  border-radius: 10px;
  font-size: 15px;
  background: white;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

/* Product list */
.product-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  cursor: pointer;
}

.product-item img,
.product-item .no-photo {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  background: #EEE;
  flex-shrink: 0;
}

.product-item .no-photo {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #BBB;
}

.product-item .info {
  flex: 1;
  min-width: 0;
}

.product-item .name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-item .meta {
  font-size: 13px;
  color: var(--text2);
  margin-top: 2px;
}

.product-item .price {
  color: var(--primary);
  font-weight: 600;
}

/* Sizes grid */
.sizes-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.size-input {
  text-align: center;
}

.size-input label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.size-input input {
  width: 100%;
  padding: 8px 4px;
  text-align: center;
  border: 1.5px solid #E0E0E0;
  border-radius: 8px;
  font-size: 14px;
}

/* Photo upload */
.photo-box {
  width: 120px;
  height: 120px;
  border: 2px dashed #CCC;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  cursor: pointer;
  overflow: hidden;
  background: #FAFAFA;
  position: relative;
}

.photo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-box .placeholder {
  color: #999;
  font-size: 13px;
  text-align: center;
}

.photo-box input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Search */
.search-box {
  position: relative;
  margin-bottom: 16px;
}

.search-box input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 1.5px solid #E0E0E0;
  border-radius: 10px;
  font-size: 15px;
  background: white;
}

.search-box .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  font-size: 18px;
}

/* Cart */
.cart-bar {
  position: fixed;
  bottom: 70px;
  left: 0;
  right: 0;
  background: white;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
  padding: 12px 16px;
  z-index: 90;
  display: none;
}

.cart-bar.visible {
  display: block;
}

.cart-items {
  max-height: 160px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid #F0F0F0;
}

.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cart-total .sum {
  font-size: 18px;
  font-weight: 700;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: white;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: #DDD;
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

.size-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.chip {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1.5px solid #DDD;
  background: white;
  font-size: 14px;
  cursor: pointer;
}

.chip.selected {
  background: rgba(26,115,232,0.15);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.chip.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.qty-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 16px 0;
}

.qty-control button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid #DDD;
  background: white;
  font-size: 20px;
  cursor: pointer;
}

.qty-control span {
  font-size: 20px;
  font-weight: 700;
  min-width: 30px;
  text-align: center;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text2);
}

.empty .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* Report cards */
.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.period-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.period-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border-radius: 8px;
  border: 1.5px solid #E0E0E0;
  background: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.period-tab.active {
  background: rgba(26,115,232,0.12);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

/* History item */
.sale-item {
  background: white;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.sale-item.cancelled {
  opacity: 0.6;
}

.sale-item .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sale-item .amount {
  font-size: 17px;
  font-weight: 700;
}

.sale-item .profit {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
}

.sale-item .date {
  font-size: 13px;
  color: var(--text2);
  margin-top: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.badge-danger {
  background: #FFEBEE;
  color: var(--danger);
}

/* Inventory sizes */
.size-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.size-tag {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  background: rgba(26,115,232,0.1);
  color: var(--primary);
  font-weight: 500;
}

.size-tag.empty {
  background: #F5F5F5;
  color: #AAA;
}

/* FAB */
.fab {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 28px;
  box-shadow: 0 4px 12px rgba(26,115,232,0.4);
  cursor: pointer;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Utility */
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.fw-600 { font-weight: 600; }
.text-muted { color: var(--text2); }
.text-sm { font-size: 13px; }
.hidden { display: none !important; }

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text2);
}

/* Product menu (3 dots) */
.product-menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.product-menu-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: #666;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-menu-btn:active {
  background: #F0F0F0;
}

.product-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 36px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  z-index: 50;
  min-width: 160px;
  overflow: hidden;
}

.product-menu.open {
  display: block;
}

.product-menu button {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: white;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}

.product-menu button:active {
  background: #F5F5F5;
}

.product-menu button.danger {
  color: var(--danger);
}

/* Photo viewer fullscreen */
.photo-viewer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.photo-viewer.open {
  display: flex;
}

.photo-viewer img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
}

.photo-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.2);
  color: white;
  font-size: 22px;
  cursor: pointer;
  z-index: 301;
}

/* Out of stock product */
.product-item.out-of-stock {
  background: #FFEBEE;
  border: 1px solid #FFCDD2;
}

.product-item.out-of-stock .name {
  color: #C62828;
}

/* ========== DARK / NIGHT MODE ========== */
body.dark {
  --primary: #5B9BFF;
  --primary-dark: #3D7DD6;
  --accent: #00E676;
  --danger: #FF5252;
  --warning: #FFB74D;
  --bg: #121212;
  --card: #1E1E1E;
  --text: #EEEEEE;
  --text2: #AAAAAA;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
}

body.dark .header {
  background: #1A1A2E;
}

body.dark .bottom-nav {
  background: #1E1E1E;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.4);
}

body.dark .form-control,
body.dark .search-box input,
body.dark .period-tab,
body.dark .chip,
body.dark .stat-card,
body.dark .product-item,
body.dark .sale-item,
body.dark .modal,
body.dark .cart-bar,
body.dark .product-menu {
  background: #2A2A2A;
  color: var(--text);
  border-color: #444;
}

body.dark .product-item.out-of-stock {
  background: #3D1F1F;
  border-color: #6B2B2B;
}

body.dark .product-item.out-of-stock .name {
  color: #FF8A80;
}

body.dark .size-tag {
  background: rgba(91,155,255,0.2);
  color: #5B9BFF;
}

body.dark .size-tag.empty {
  background: #333;
  color: #777;
}

body.dark .photo-box {
  background: #2A2A2A;
  border-color: #555;
}

body.dark .btn-outline {
  border-color: var(--primary);
  color: var(--primary);
}

body.dark .period-tab.active,
body.dark .chip.selected {
  background: rgba(91,155,255,0.25);
  border-color: var(--primary);
  color: var(--primary);
}

body.dark .modal-overlay {
  background: rgba(0,0,0,0.75);
}

body.dark .qty-control button {
  background: #2A2A2A;
  border-color: #555;
  color: var(--text);
}

body.dark input,
body.dark .form-control {
  color-scheme: dark;
}

/* Dark mode toggle switch */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.switch {
  position: relative;
  width: 52px;
  height: 30px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #CCC;
  border-radius: 30px;
  transition: 0.25s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 24px;
  width: 24px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.25s;
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}
