:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --soft: #eef4ff;
  --text: #121826;
  --muted: #637083;
  --line: #e3e8ef;
  --green: #0a8f3d;
  --green-2: #25d366;
  --blue: #2563eb;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 18px 45px rgba(18, 24, 38, 0.09);
  --radius: 12px;
}

.dark {
  --bg: #0f172a;
  --panel: #111827;
  --soft: #172033;
  --text: #f8fafc;
  --muted: #a7b0c0;
  --line: #263244;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: Inter, Arial, sans-serif;
}

html {
  color-scheme: light;
  overflow-x: hidden;
}

.dark {
  color-scheme: dark;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
}

/* Dashboard content stays hidden until Firebase confirms the seller is authenticated. */
body[data-page="dashboard"]:not(.auth-ready) .app-shell {
  visibility: hidden;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  align-items: center;
  padding: 24px 0;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

table,
pre,
code {
  max-width: 100%;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* Mobile menu controls are hidden on desktop so the existing desktop UI stays unchanged. */
.menu-toggle {
  display: none;
}

.site-header,
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.dark .site-header,
.dark .app-topbar {
  background: rgba(17, 24, 39, 0.88);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--green), var(--blue));
  font-weight: 900;
}

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  align-items: center;
  width: min(1120px, calc(100% - 32px));
  margin: 34px auto 18px;
}

.hero-copy h1 {
  font-size: clamp(34px, 6vw, 68px);
  line-height: 1;
  margin-bottom: 16px;
  letter-spacing: 0;
}

.hero-copy p {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
  max-width: 660px;
}

.hero-card,
.auth-card,
.panel,
.product-card,
.public-card,
.stat-card,
.store-hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-card {
  padding: 24px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 20px;
}

.hero-metrics div {
  padding: 14px;
  background: var(--soft);
  border-radius: var(--radius);
}

.hero-metrics strong {
  display: block;
  font-size: 24px;
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  width: min(1120px, calc(100% - 32px));
  margin: 18px auto 40px;
}

.auth-card {
  padding: 22px;
}

.seo-section {
  width: min(1120px, calc(100% - 32px));
  margin: 22px auto;
  padding: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.seo-section h2 {
  margin-bottom: 10px;
}

.seo-section p {
  color: var(--muted);
  line-height: 1.6;
}

.seo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.seo-grid article {
  padding: 16px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.seo-section details {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.seo-section details:last-child {
  border-bottom: 0;
}

.seo-section summary {
  cursor: pointer;
  font-weight: 900;
}

.auth-card h2,
.panel h2,
.store-hero h1 {
  margin-bottom: 8px;
}

.auth-card p,
.panel p,
.store-hero p {
  color: var(--muted);
  line-height: 1.5;
}

.field,
label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  margin-top: 14px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  padding: 12px 13px;
}

textarea {
  min-height: 104px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(10, 143, 61, 0.12);
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 900;
}

.primary-btn {
  color: #ffffff;
  background: linear-gradient(135deg, var(--green), var(--blue));
}

.secondary-btn {
  color: var(--text);
  background: var(--soft);
  border: 1px solid var(--line);
}

.ghost-btn {
  color: var(--green);
  background: rgba(10, 143, 61, 0.09);
}

.danger-btn {
  color: var(--red);
  background: rgba(220, 38, 38, 0.09);
}

.button-row,
.inline-actions,
.store-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.button-row {
  margin-top: 16px;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.nav-list {
  display: grid;
  gap: 8px;
  margin-top: 24px;
}

.nav-link {
  text-align: left;
  border: 0;
  border-radius: 10px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
}

.nav-link.active,
.nav-link:hover {
  color: var(--green);
  background: rgba(10, 143, 61, 0.09);
}

.main {
  min-width: 0;
  padding: 22px;
}

.grid-4,
.grid-3,
.grid-2 {
  display: grid;
  gap: 16px;
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card,
.panel {
  padding: 18px;
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
}

.panel-section {
  display: none;
}

.active-section {
  display: block;
}

.stack {
  display: grid;
  gap: 16px;
}

.store-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.full {
  grid-column: 1 / -1;
}

.product-toolbar,
.store-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  margin: 16px 0;
}

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

/* Count-aware grids keep 1, 2, 3, and 4 product stores balanced. */
.product-list.product-count-1,
.public-grid.product-count-1 {
  grid-template-columns: minmax(0, min(100%, 420px));
  justify-content: center;
}

.product-list.product-count-2,
.public-grid.product-count-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.public-grid.product-count-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.public-grid.product-count-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.product-card,
.public-card {
  overflow: hidden;
}

.product-card {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  align-items: start;
}

.product-gallery {
  display: grid;
  grid-template-rows: auto auto;
  align-self: start;
  min-width: 0;
  background: var(--soft);
}

.product-main-image,
.product-thumbs img {
  width: 100%;
  object-fit: contain;
  background: var(--soft);
}

.product-main-image {
  height: auto;
  min-height: 0;
  aspect-ratio: 1 / 1;
}

.product-thumbs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
}

.product-thumbs img {
  aspect-ratio: 1 / 1;
  min-height: 0;
}

.product-card > div,
.public-card > div {
  padding: 14px;
  display: grid;
  gap: 8px;
}

.badge {
  display: inline-flex;
  width: max-content;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.order-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.order-row span {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.store-page {
  width: min(1060px, calc(100% - 28px));
  margin: 18px auto 80px;
}

.store-hero {
  overflow: hidden;
  margin-bottom: 16px;
}

.store-banner {
  width: 100%;
  height: 230px;
  object-fit: cover;
}

.store-identity {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
}

.store-logo {
  width: 86px;
  height: 86px;
  border-radius: 18px;
  object-fit: cover;
  border: 4px solid var(--panel);
  box-shadow: var(--shadow);
}

.store-actions {
  padding: 0 18px 18px;
}

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

.public-card {
  display: grid;
}

.public-card .product-main-image {
  aspect-ratio: 1 / 1;
}

.qr-box {
  padding: 0 18px 18px;
}

.whatsapp-float {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  padding: 13px 16px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--green-2);
  text-decoration: none;
  font-weight: 900;
  box-shadow: var(--shadow);
}

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

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.empty-state {
  padding: 26px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 80;
  display: none;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 10px;
  color: #ffffff;
  background: #101828;
  box-shadow: var(--shadow);
  font-weight: 800;
}

.toast.show {
  display: block;
}

.toast[data-type="error"] {
  background: var(--red);
}

@media (max-width: 1050px) {
  .hero,
  .auth-grid,
  .grid-4,
  .grid-3,
  .grid-2,
  .seo-grid,
  .public-grid {
    grid-template-columns: 1fr 1fr;
  }

  .public-grid.product-count-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  body {
    font-size: 15px;
  }

  .hero,
  .auth-grid,
  .grid-4,
  .grid-3,
  .grid-2,
  .seo-grid,
  .store-form-grid,
  .product-list,
  .public-grid {
    grid-template-columns: 1fr;
  }

  .site-header,
  .app-topbar {
    position: sticky;
    align-items: flex-start;
    padding: 12px 14px;
  }

  .site-header .brand,
  .sidebar .brand {
    min-height: 44px;
  }

  .menu-toggle {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: var(--panel);
    font-size: 24px;
    font-weight: 900;
  }

  .site-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .site-header .site-menu {
    display: none;
    grid-column: 1 / -1;
    width: 100%;
    margin-top: 8px;
  }

  .site-header.menu-open .site-menu {
    display: grid;
    gap: 8px;
  }

  .site-header .site-menu > * {
    width: 100%;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    height: auto;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
    padding: 12px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar .nav-list,
  .sidebar > .button-row {
    display: none;
    grid-column: 1 / -1;
    margin-top: 8px;
  }

  .sidebar.menu-open .nav-list,
  .sidebar.menu-open > .button-row {
    display: grid;
  }

  .sidebar > .button-row > * {
    width: 100%;
  }

  .main {
    padding: 12px;
  }

  .hero {
    width: min(100% - 24px, 1120px);
    gap: 16px;
    margin-top: 18px;
  }

  .hero-copy h1 {
    font-size: 34px;
    line-height: 1.06;
  }

  .hero-copy p {
    font-size: 16px;
  }

  .hero-card,
  .auth-card,
  .panel,
  .stat-card,
  .seo-section {
    padding: 16px;
  }

  .hero-metrics {
    grid-template-columns: 1fr;
  }

  .auth-grid,
  .seo-section,
  .store-page {
    width: min(100% - 24px, 1120px);
  }

  .app-topbar {
    position: static;
  }

  .app-topbar .button-row,
  .button-row,
  .inline-actions,
  .store-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .app-topbar input,
  .button-row > *,
  .inline-actions > *,
  .store-actions > * {
    width: 100%;
  }

  .product-toolbar,
  .store-tools {
    grid-template-columns: 1fr;
  }

  .product-card {
    grid-template-columns: 1fr;
  }

  .product-list.product-count-1,
  .product-list.product-count-2,
  .public-grid.product-count-1,
  .public-grid.product-count-2,
  .public-grid.product-count-3,
  .public-grid.product-count-4 {
    grid-template-columns: 1fr;
  }

  .product-gallery {
    grid-template-rows: auto auto;
  }

  .product-main-image {
    height: auto;
    min-height: 0;
    aspect-ratio: 4 / 3;
  }

  .store-banner {
    height: auto;
    max-height: none;
    object-fit: contain;
  }

  .store-identity {
    display: grid;
    gap: 12px;
    padding: 14px;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 620px;
  }
}

@media (max-width: 520px) {
  .brand {
    min-width: 0;
  }

  .brand span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .store-identity {
    align-items: flex-start;
    flex-direction: column;
  }

  .button-row > *,
  .store-actions > * {
    width: 100%;
  }
}

/* Mobile app interface inspired by the supplied reference. Desktop styles above remain unchanged. */
@media (max-width: 780px) {
  :root {
    --mobile-blue: #0b55f4;
    --mobile-green: #17b94f;
    --mobile-surface: #ffffff;
    --mobile-soft: #f4f7fb;
  }

  body {
    background: #f4f7fb;
  }

  .site-header,
  .app-topbar,
  .sidebar {
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(145deg, #1db954, var(--mobile-blue));
    font-size: 15px;
  }

  .hero {
    min-height: calc(100vh - 96px);
    align-content: start;
  }

  .hero-copy h1 {
    max-width: 330px;
    color: #0f172a;
    font-size: 31px;
    line-height: 1.08;
  }

  .hero-copy h1::first-line {
    color: #0f172a;
  }

  .hero-copy p,
  .hero-card p,
  .auth-card p,
  .panel p {
    color: #475569;
  }

  .hero-card,
  .auth-card,
  .panel,
  .stat-card,
  .product-card,
  .public-card,
  .seo-section,
  .order-row {
    border-color: #e6edf5;
    border-radius: 14px;
    box-shadow: 0 10px 32px rgba(15, 23, 42, 0.08);
  }

  .hero-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    overflow: hidden;
    border: 1px solid #e6edf5;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  }

  .hero-metrics div {
    margin: 0;
    border-radius: 0;
    border-right: 1px solid #e6edf5;
    background: #ffffff;
    text-align: center;
  }

  .hero-metrics div:last-child {
    border-right: 0;
  }

  .hero-metrics strong {
    color: var(--mobile-blue);
    font-size: 22px;
  }

  .primary-btn,
  .secondary-btn,
  .ghost-btn,
  .danger-btn {
    min-height: 48px;
    border-radius: 9px;
    font-size: 15px;
  }

  .primary-btn {
    background: linear-gradient(135deg, #064ee8, #1769ff);
  }

  .secondary-btn,
  .ghost-btn {
    border: 1px solid #dce6f2;
    background: #ffffff;
    color: var(--mobile-blue);
  }

  input,
  textarea,
  select {
    min-height: 48px;
    border-radius: 9px;
    border-color: #d8e2ef;
    background: #ffffff;
  }

  .app-shell {
    padding-bottom: 74px;
  }

  .sidebar {
    box-shadow: none;
  }

  .sidebar .nav-list {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    margin: 0;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid #e6edf5;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.08);
  }

  .nav-link {
    min-height: 48px;
    padding: 4px 2px;
    text-align: center;
    border-radius: 10px;
    color: #0f172a;
    font-size: 11px;
  }

  .nav-link::before {
    display: block;
    margin-bottom: 2px;
    color: currentColor;
    font-size: 16px;
  }

  .nav-link[data-section$="Overview"]::before,
  .nav-link[data-section="overviewSection"]::before {
    content: "⌂";
  }

  .nav-link[data-section*="Products"]::before,
  .nav-link[data-section="productsSection"]::before {
    content: "□";
  }

  .nav-link[data-section*="Orders"]::before,
  .nav-link[data-section="ordersSection"]::before {
    content: "▤";
  }

  .nav-link[data-section="storeSection"]::before,
  .nav-link[data-section*="Stores"]::before {
    content: "▣";
  }

  .nav-link[data-section="plansSection"]::before,
  .nav-link[data-section*="Users"]::before {
    content: "⋯";
  }

  .nav-link.active {
    color: var(--mobile-blue);
    background: transparent;
  }

  .main {
    padding: 12px 12px 86px;
  }

  .app-topbar {
    margin: -12px -12px 14px;
    border-bottom: 0;
  }

  .app-topbar h1 {
    font-size: 18px;
    text-align: center;
  }

  .app-topbar p {
    font-size: 13px;
  }

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

  .stat-card {
    min-height: 116px;
    padding: 16px;
  }

  .stat-card span {
    color: #334155;
    font-size: 12px;
  }

  .stat-card strong {
    color: #0f172a;
    font-size: 24px;
  }

  .store-form-grid {
    gap: 12px;
  }

  .product-list,
  .public-grid {
    gap: 12px;
  }

  .product-card {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    align-items: center;
    padding: 10px;
    background: #ffffff;
  }

  .product-card .product-gallery {
    border-radius: 10px;
    overflow: hidden;
  }

  .product-card .product-main-image {
    aspect-ratio: 1 / 1;
  }

  .product-card .product-thumbs {
    display: none;
  }

  .product-card > div {
    padding: 4px 4px 4px 10px;
    gap: 4px;
  }

  .product-card h3,
  .public-card h2 {
    font-size: 15px;
    line-height: 1.25;
  }

  .product-card p {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 13px;
  }

  .inline-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 6px;
  }

  .inline-actions button {
    min-height: 38px;
    font-size: 13px;
  }

  .store-hero {
    border-radius: 16px;
  }

  .store-banner {
    width: 100%;
    height: auto;
    max-height: none;
    aspect-ratio: auto;
    object-fit: contain;
    background: #ffffff;
  }

  .public-card {
    overflow: hidden;
  }

  .public-card .product-gallery {
    border-radius: 0;
  }

  .whatsapp-float {
    right: 14px;
    bottom: 86px;
    min-height: 48px;
    border-radius: 999px;
  }
}
