:root {
  --bg: #f3efe4;
  --panel: #fffdf7;
  --text: #1d2433;
  --muted: #6c6f74;
  --accent: #0f766e;
  --accent-strong: #0b4f4c;
  --accent-soft: #d5efe8;
  --border: #ddcfba;
  --shadow: 0 20px 60px rgba(42, 50, 67, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Segoe UI Variable Text", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.1), transparent 30%),
    radial-gradient(circle at bottom right, rgba(197, 138, 77, 0.15), transparent 25%),
    linear-gradient(135deg, #f5ead6 0%, #f3efe4 50%, #ebe7da 100%);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Auth page ─────────────────────────────────────────── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-shell {
  width: 100%;
  max-width: 420px;
}

.auth-card {
  border: 1px solid rgba(221, 207, 186, 0.85);
  border-radius: 28px;
  padding: 36px;
  background: rgba(255, 254, 248, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.auth-brand h1 {
  margin: 8px 0 6px;
  font-size: 2rem;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.1;
}

.auth-tagline {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255, 254, 248, 0.7);
  color: var(--muted);
  cursor: pointer;
}

.auth-tab.is-active {
  background: linear-gradient(135deg, var(--accent), #134e4a);
  color: #fff;
  border-color: transparent;
}

.reg-mode-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.reg-mode-btn {
  flex: 1;
  padding: 10px 8px;
  font-size: .85rem;
  font-weight: 600;
  border: none;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.reg-mode-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-form label span {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
}

.auth-form label small {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.auth-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
  background: #fffef9;
}

.auth-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.primary-button {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 14px;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #134e4a);
  cursor: pointer;
  margin-top: 4px;
}

.primary-button:hover {
  opacity: 0.9;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 16px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-soft);
  cursor: pointer;
}

.auth-message {
  margin: 0;
  font-size: 0.88rem;
  min-height: 1.2em;
  color: var(--muted);
}

.auth-message.is-error {
  color: #b91c1c;
}

.auth-message.is-success {
  color: var(--accent-strong);
}

/* ── Dashboard ─────────────────────────────────────────── */

.dash-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 32px;
  border-bottom: 1px solid rgba(221, 207, 186, 0.6);
  background: rgba(255, 254, 248, 0.88);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.dash-brand strong {
  display: block;
  margin-top: 2px;
  font-size: 1.1rem;
  font-family: Georgia, "Times New Roman", serif;
}

.dash-main {
  flex: 1;
  padding: 28px 32px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

.dash-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-chip {
  border: 1px solid rgba(221, 207, 186, 0.85);
  border-radius: 18px;
  padding: 16px 22px;
  background: rgba(255, 254, 248, 0.88);
  box-shadow: var(--shadow);
  min-width: 140px;
}

.stat-chip span {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 600;
}

.stat-chip strong {
  display: block;
  margin-top: 6px;
  font-size: 1.6rem;
  font-family: Georgia, "Times New Roman", serif;
}

.address-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-radius: 14px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  margin-bottom: 18px;
}
.address-banner[hidden] { display: none; }
.address-banner-icon { font-size: 1.5rem; }
.address-banner-text { flex: 1; }
.address-banner-text strong { display: block; font-size: .95rem; color: #92400e; }
.address-banner-text p { margin: 2px 0 0; font-size: .85rem; color: #a16207; }

.address-card { margin-bottom: 18px; }

.dash-card {
  border: 1px solid rgba(221, 207, 186, 0.85);
  border-radius: 22px;
  background: rgba(255, 254, 248, 0.88);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dash-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid rgba(221, 207, 186, 0.6);
}

.dash-card-head h2 {
  margin: 0;
  font-size: 1.3rem;
  font-family: Georgia, "Times New Roman", serif;
}

.muted-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid rgba(221, 207, 186, 0.5);
  text-align: left;
  vertical-align: middle;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 700;
  background: rgba(245, 239, 225, 0.4);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(213, 239, 232, 0.2);
}

.empty-cell {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

.item-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  display: block;
}

.no-photo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: rgba(245, 239, 225, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
}

.status-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(213, 239, 232, 0.5);
  color: var(--accent-strong);
  white-space: nowrap;
}

.egp-amount {
  font-weight: 700;
  font-family: Georgia, "Times New Roman", serif;
  white-space: nowrap;
}

/* ── Lightbox ─────────────────────────────────────────── */

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, 0.85);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.lightbox.is-open {
  display: flex;
}

.lightbox img {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: 12px;
  object-fit: contain;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
  position: fixed;
  top: 20px;
  right: 24px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Shop page ────────────────────────────────────────── */

.shop-header {
  margin-bottom: 24px;
}

.shop-title {
  margin: 0 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.6rem;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.shop-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.shop-card {
  background: rgba(255, 254, 248, 0.92);
  border: 1px solid rgba(221, 207, 186, 0.85);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
}

.shop-card:hover {
  box-shadow: 0 10px 36px rgba(42, 50, 67, 0.14);
  transform: translateY(-2px);
}

.shop-card-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: rgba(245, 239, 225, 0.6);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.shop-card-no-photo {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.shop-card-body {
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.shop-card-brand {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
}

.shop-card-desc {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.shop-card-price {
  display: block;
  margin-top: 6px;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--accent-strong);
}


/* ── Portal invoices ──────────────────────────────────── */

.portal-invoice-row {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

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

.portal-invoice-row:hover {
  background: rgba(15, 118, 110, 0.04);
}

.portal-invoice-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.portal-invoice-row-main strong {
  font-size: 1rem;
}

.portal-invoice-row-main .muted-note {
  display: block;
  margin-top: 2px;
}

.portal-invoice-row-totals {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 0.88rem;
}

.portal-invoice-row-totals > div {
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.portal-invoice-row-totals span {
  color: var(--muted);
}

.invoice-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.invoice-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.invoice-detail-card {
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.invoice-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.invoice-detail-head strong {
  display: block;
  font-size: 1.1rem;
  margin-top: 2px;
}

.invoice-detail-body {
  padding: 18px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.invoice-detail-body h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.invoice-detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px 16px;
  padding: 12px 14px;
  background: rgba(15, 118, 110, 0.04);
  border-radius: 10px;
  font-size: 0.88rem;
}

.invoice-detail-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.invoice-detail-totals {
  padding: 14px 16px;
  background: rgba(15, 118, 110, 0.04);
  border-radius: 10px;
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.invoice-detail-totals > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.invoice-detail-totals span {
  color: var(--muted);
}

.invoice-detail-total-line {
  font-weight: 600;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 4px;
}

.invoice-detail-balance-line {
  font-weight: 700;
}

/* ─────────────────────────────────────────────────────────────
   MOBILE — phones (≤700px)
   ───────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  /* Header: brand + nav stack vertically, nav buttons wrap */
  .dash-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .dash-header > div:last-child {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px !important;
    width: 100%;
    justify-content: flex-start;
  }
  .dash-header .ghost-button,
  .dash-header button {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    font-size: 0.8rem;
    padding: 8px 10px;
    text-align: center;
  }
  .dash-brand strong { font-size: 0.95rem; }
  .dash-brand .eyebrow { font-size: 0.65rem; }

  .dash-main {
    padding: 14px;
  }

  /* Auth screens (sign in / register) */
  .auth-card {
    padding: 22px 18px;
  }

  /* Stat chips wrap to 2-per-row */
  .dash-stats {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
  }
  .stat-chip {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    padding: 12px 14px;
    border-radius: 14px;
  }
  .stat-chip strong { font-size: 1rem; word-break: break-word; }
  .stat-chip span { font-size: 0.7rem; }

  /* Cards & headings */
  .dash-card-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .dash-card-head h2 { font-size: 1.1rem; }

  /* Tables: keep horizontal scroll, smaller font */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 0.8rem; }
  th, td { padding: 8px 6px; }
  .item-thumb, .no-photo { max-width: 50px; }

  /* Invoice list rows */
  .portal-invoice-row {
    padding: 12px;
  }
  .portal-invoice-row-main {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .portal-invoice-row-totals {
    flex-direction: column;
    gap: 4px;
    width: 100%;
  }
  .portal-invoice-row-totals > div {
    display: flex;
    justify-content: space-between;
    width: 100%;
  }

  /* Invoice detail modal */
  .invoice-detail-card {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 92vh;
    overflow-y: auto;
    padding: 16px;
  }
  .invoice-detail-totals > div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
  }
  .invoice-detail-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* Address banner + form */
  .address-banner {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
  }
  .address-banner button {
    width: 100%;
    margin-top: 6px;
  }

  /* Shop grid → bigger thumbs on phone */
  .shop-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  /* Lightbox image */
  .lightbox img { max-width: 95vw; max-height: 90vh; }

  /* Touch targets */
  .ghost-button,
  button[type="submit"] {
    min-height: 38px;
  }
}

/* Very narrow (<420px) tightening */
@media (max-width: 420px) {
  .dash-main { padding: 10px; }
  .stat-chip { flex: 1 1 100%; }
  th, td { padding: 6px 4px; font-size: 0.75rem; }
  .dash-header > div:last-child .ghost-button {
    flex: 1 1 100%;
  }
}
