:root {
  /* Enterprise Slate Palette */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* Brand Colors */
  --brand: #e11d48; /* Premium Crimson */
  --brand-dark: #be123c;
  --brand-surface: #fff1f2;
  
  /* Modern Tokens */
  --bg: var(--slate-50);
  --panel: #ffffff;
  --panel-alt: var(--slate-100);
  --text: var(--slate-900);
  --text-soft: var(--slate-500);
  --line: var(--slate-200);
  --radius: 12px;
  
  /* Refined Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  
  --content-max: 1120px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg);
  background-image: radial-gradient(at 0% 0%, hsla(339,49%,30%,0.03) 0, transparent 50%), 
                    radial-gradient(at 50% 0%, hsla(225,39%,30%,0.02) 0, transparent 50%);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 24px;
  background: var(--slate-900);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #fff;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.025em;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 2px 4px rgba(225, 29, 72, 0.2);
}

.nav-toggle {
  display: none;
  border: none;
  background: transparent;
  width: 40px;
  height: 40px;
  position: relative;
  cursor: pointer;
  padding: 0;
}

.hamburger {
  width: 20px;
  height: 2px;
  background: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: background 0.2s;
}

.hamburger::before,
.hamburger::after {
  content: ' ';
  display: block;
  width: 20px;
  height: 2px;
  background: #fff;
  position: absolute;
  left: 0;
  transition: transform 0.2s;
}

.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

.nav-toggle[aria-expanded="true"] .hamburger {
  background: transparent;
}

.nav-toggle[aria-expanded="true"] .hamburger::before {
  transform: translateY(6px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .hamburger::after {
  transform: translateY(-6px) rotate(-45deg);
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav a {
  color: var(--slate-400);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.nav a.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.nav .logout-link {
  margin-left: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 32px 24px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

h2 {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--slate-900);
}

h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--slate-800);
}

.muted {
  color: var(--slate-500);
  font-size: 0.875rem;
}

/* Card System */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.section-card {
  padding: 24px;
  margin-bottom: 24px;
}

.inset-card {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  padding: 20px;
  margin-top: 16px;
}

/* Dashboard Metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.metric-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 140px;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-500);
}

.metric-value {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--brand);
  line-height: 1;
  margin: 12px 0;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.btn-primary:hover {
  background: var(--brand-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-secondary {
  background: #fff;
  color: var(--slate-700);
  border-color: var(--slate-200);
}

.btn-secondary:hover {
  background: var(--slate-50);
  border-color: var(--slate-300);
}

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

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

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--slate-700);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: #fff;
  border: 1px solid var(--slate-300);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 1rem;
  transition: all 0.2s;
  color: var(--slate-900);
}

.form-control:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-surface);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.message {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #f1bcc8;
  background: #fff0f3;
  color: #8d1028;
}

.message.success {
  border-color: #b6e2c7;
  background: #ecf9f1;
  color: #1e5b37;
}

.message.error {
  border-color: #f1bcc8;
  background: #fff0f3;
  color: #8d1028;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li {
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}

.list li:last-child {
  border-bottom: none;
}

.item-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: #6b7280;
}

.item-list li {
  border: none;
  padding: 2px 0;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.beat-details {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
}

.beat-summary {
  cursor: pointer;
}

.beat-details > summary {
  list-style: none;
}

.beat-details > summary::-webkit-details-marker {
  display: none;
}

.filter-details {
  margin-top: 16px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
  display: none; /* Controlled by [open] or JS toggle */
}

.filter-details[open] {
  display: block;
  animation: slideDown 0.2s ease-out;
}

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

.filter-summary {
  display: none; /* Hide the default details summary */
}

.filter-details[open] .filter-summary::after {
  content: "▲";
  font-size: 10px;
  color: #64748b;
}

.filter-details .filter-summary::after {
  content: "▼";
  font-size: 10px;
  color: #64748b;
}

.filter-details > summary {
  list-style: none;
}

.filter-details > summary::-webkit-details-marker {
  display: none;
}

.filter-quick {
  margin-bottom: 20px;
}

.filter-quick .muted {
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-400);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--slate-600);
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
}

.filter-pill:hover {
  border-color: var(--slate-300);
  background: var(--slate-50);
  color: var(--slate-900);
}

.filter-pill.active {
  background: var(--brand-surface);
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(225, 29, 72, 0.1);
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: #fdecef;
  color: #8a1730;
  font-size: 0.8rem;
  border: 1px solid #f5c4cf;
}

.tag-success {
  background: #e7f7ee;
  color: #137a43;
  border-color: #bfe8cf;
}

.tag-muted {
  background: #f2f4f7;
  color: #667085;
  border-color: #e4e7ec;
}

.amount {
  font-weight: 700;
  color: #8a1730;
}

.sku-list {
  display: grid;
  gap: 8px;
}

.sku-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.95rem;
}

.sku-row .qty {
  max-width: 92px;
}

.network-chip {
  display: inline-block;
  margin: 0 0 10px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid #f1bcc8;
  color: #8d1028;
  background: #fff0f3;
}

.network-chip.offline {
  color: #6e4d00;
  border-color: #edd899;
  background: #fff6db;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-wrap {
  width: 100%;
  max-width: 420px;
}

.login-card {
  padding: 18px;
}

.login-btn {
  width: 100%;
  margin-top: 8px;
}

.cached-note {
  margin-top: 8px;
  color: var(--warn);
  font-size: 0.83rem;
}

/* Bottom Navigation for Mobile */
.bottom-nav {
  display: none;
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 64px;
  background: #ffffff;
  border-top: 1px solid var(--line);
  z-index: 9999;
  padding: 0 12px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
}

.bottom-nav-inner {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-around;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: var(--slate-500);
  padding: 6px;
  min-width: 64px;
  transition: color 0.2s;
}

.bottom-nav-item i {
  font-size: 20px;
  opacity: 0.8;
}

.bottom-nav-item span {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.bottom-nav-item.active {
  color: var(--brand);
}

@media (max-width: 880px) {
  .nav {
    display: flex;
    position: absolute;
    top: 64px;
    left: 20px;
    right: 20px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 90;
  }

  .nav.nav-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .nav a {
    color: var(--slate-700);
    padding: 12px 16px;
    width: 100%;
  }

  .nav a:hover,
  .nav a.active {
    background: var(--slate-50);
    color: var(--brand);
  }

  .nav .logout-link {
    margin: 8px 0 0 0;
    border: 1px solid var(--line);
  }

  .topbar {
    padding: 8px 20px;
    height: 64px;
  }

  .nav-toggle {
    display: block;
  }

  .content {
    padding: 20px 16px 80px; /* Space for bottom nav */
  }

  .bottom-nav {
    display: block;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .page-header .btn {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .shop-row {
    align-items: flex-start;
  }

  .shop-row .row-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
  }

  .shop-row .row-actions .btn {
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 6px;
  }

  .shop-row .row-actions .tag {
    font-size: 0.65rem;
    padding: 2px 6px;
  }
}

.shop-row {
  align-items: center;
}

.shop-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.shop-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f7eef1;
  flex: 0 0 auto;
}

.shop-thumb-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #8a1730;
}

.photo-preview-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.photo-preview {
  width: 70px;
  height: 70px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f7eef1;
}

.duplicate-status {
  margin-top: 6px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f7fbfa;
}

.duplicate-idle {
  color: var(--text-soft);
}

.duplicate-ok {
  color: #8d1028;
  border-color: #f2c2cc;
  background: #fff2f5;
}

.duplicate-found {
  color: #8f250f;
  border-color: #f1c1b7;
  background: #fff0ed;
  font-weight: 600;
}

.duplicate-error {
  color: #8b5f00;
  border-color: #ecd391;
  background: #fff7de;
}

.mapping-grid {
  margin-top: 10px;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fbfdfc;
}

.mapping-row {
  display: grid;
  grid-template-columns: 24px 1fr 86px;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #edf2f0;
}

.mapping-row:last-child {
  border-bottom: none;
}

.sequence-input {
  max-width: 80px;
}

.beat-shop-list {
  margin: 6px 0 0 18px;
  padding: 0;
}

.beat-shop-list li {
  margin: 3px 0;
}

.dsr-row-form {
  margin-top: 0;
}

.dsr-fields {
  display: flex;
  gap: 14px;
  margin: 8px 0;
  font-size: 0.9rem;
}

@media (max-width: 880px) {
  .mapping-row {
    grid-template-columns: 24px 1fr;
  }

  .mapping-row .sequence-input {
    grid-column: 2;
    max-width: 120px;
  }

  .dsr-fields {
    flex-direction: column;
    gap: 6px;
  }
}
