:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --dark: #111827;
  --blue: #2563eb;
  --green: #087f23;
  --red: #991b1b;
  --red-bg: #fee2e2;
  --amber-bg: #fef3c7;
  --amber-text: #92400e;
  --green-bg: #dcfce7;
  --green-text: #166534;
  --border: #d1d5db;
  --soft-border: #e5e7eb;
  --shadow: 0 8px 24px rgba(0,0,0,0.06);
  --radius: 18px;
  --tap: 48px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: clamp(16px, 2.5vw, 18px);
}

a {
  color: inherit;
}

main {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 14px;
}

h1 {
  font-size: clamp(1.45rem, 5vw, 2rem);
  line-height: 1.1;
}

h2 {
  font-size: clamp(1.2rem, 4vw, 1.55rem);
}

.page-header,
.order-header {
  background: var(--card);
  padding: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.page-header {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.page-header h1,
.order-header h1 {
  margin: 0;
}

.order-header {
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.logout,
.small-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 800;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}

.muted,
.meta {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.35;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.button,
button {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 13px 16px;
  background: var(--dark);
  color: #fff;
  text-decoration: none;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.button-blue {
  background: var(--blue);
}

input,
select {
  width: 100%;
  min-height: var(--tap);
  padding: 13px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 800;
}

.error {
  background: var(--red-bg);
  color: var(--red);
  padding: 12px;
  border-radius: 14px;
  margin-bottom: 16px;
}

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

.login-card {
  width: min(420px, 100%);
  background: var(--card);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0,0,0,0.08);
}

.login-card h1 {
  margin: 0 0 8px;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
}

.order-body {
  padding-bottom: 96px;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

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

.product-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 94px 1fr;
  gap: 12px;
  align-items: start;
}

.product-image {
  width: 94px;
  height: 94px;
  background: #e5e7eb;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--muted);
  overflow: hidden;
  font-weight: 800;
  font-size: 0.82rem;
  text-align: center;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-title {
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1.2;
  margin-bottom: 8px;
}

.qty-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 10px;
  align-items: center;
}

.add-btn {
  width: 100%;
}

.sticky-basket {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid #ddd;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.08);
  padding: 10px 12px;
  z-index: 20;
}

.basket-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.basket-status {
  font-weight: 900;
}

.basket-message {
  color: var(--green);
  font-size: 0.88rem;
  margin-top: 2px;
  max-width: 58vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.basket-lines {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.basket-line {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: #f9fafb;
  border: 1px solid var(--soft-border);
  border-radius: 14px;
}

.basket-qty {
  padding: 12px;
}

.remove-line {
  background: var(--red);
}

.dashboard-actions,
.page-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 18px 0;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 18px;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: #fff;
}

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

.data-table th {
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-pill {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 900;
  background: #e5e7eb;
  color: var(--text);
}

.status-draft {
  background: var(--amber-bg);
  color: var(--amber-text);
}

.status-sent {
  background: var(--green-bg);
  color: var(--green-text);
}

.status-cancelled {
  background: var(--red-bg);
  color: var(--red);
}

.order-summary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

.email-preview {
  background: #f9fafb;
  border: 1px solid var(--soft-border);
  border-radius: 14px;
  padding: 16px;
}

.email-preview pre {
  white-space: pre-wrap;
  margin: 14px 0 0;
  font-family: Arial, sans-serif;
  line-height: 1.5;
}

@media (min-width: 520px) {
  main {
    padding: 18px;
  }

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

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

  .product-image {
    width: 100%;
    height: 130px;
  }

  .dashboard-actions,
  .page-actions {
    display: flex;
    flex-wrap: wrap;
  }

  .basket-line {
    grid-template-columns: 1fr 120px auto;
  }

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

@media (min-width: 760px) {
  .page-header {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .filters {
    grid-template-columns: 1fr 240px;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  }

  .order-summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

@media (max-width: 420px) {
  .top-row {
    grid-template-columns: 1fr;
  }

  .logout {
    justify-content: flex-start;
  }

  .basket-inner {
    grid-template-columns: 1fr;
  }

  .basket-message {
    max-width: 100%;
  }

  .sticky-basket .button {
    width: 100%;
  }
}

/* /////////////////////////////////////
   MOBILE LOGIN FIX
///////////////////////////////////// */

.login-body {
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px 14px;
}

.login-card {
  width: min(430px, 100%);
  padding: clamp(20px, 5vw, 30px);
}

.login-card form {
  display: grid;
  gap: 12px;
}

.login-card label {
  margin: 4px 0 0;
}

.login-card input {
  min-height: 52px;
}

.login-card button {
  width: 100%;
  min-height: 54px;
  margin-top: 8px;
}

@media (max-height: 620px) {
  .login-body {
    align-items: flex-start;
  }

  .login-card {
    margin-top: 12px;
    margin-bottom: 12px;
  }
}

@media (max-width: 380px) {
  .login-card {
    padding: 18px;
    border-radius: 16px;
  }

  .login-card h1 {
    font-size: 1.45rem;
  }

  .login-card p {
    margin-bottom: 16px;
  }
}

/* /////////////////////////////////////
   ADMIN PRODUCT MANAGER
///////////////////////////////////// */

.admin-filter-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 18px 0;
}

.admin-edit-form {
  display: grid;
  gap: 18px;
}

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

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

.form-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
}

.site-check-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.checkbox-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f9fafb;
  border: 1px solid var(--soft-border);
  border-radius: 14px;
  padding: 12px;
  font-weight: 800;
}

.checkbox-card input[type="checkbox"] {
  width: 22px;
  min-height: 22px;
  height: 22px;
  flex: 0 0 22px;
}

.mobile-product-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.mobile-admin-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #f9fafb;
  border: 1px solid var(--soft-border);
  border-radius: 16px;
}

.admin-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.desktop-table {
  display: none;
}

@media (min-width: 700px) {
  .admin-filter-form {
    grid-template-columns: 1fr 190px auto;
    align-items: center;
  }

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

  .form-actions {
    display: flex;
    flex-wrap: wrap;
  }

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

  .mobile-product-list {
    display: none;
  }

  .desktop-table {
    display: block;
  }
}

@media (min-width: 1000px) {
  .site-check-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* /////////////////////////////////////
   VIEW ORDER MOBILE FIX
///////////////////////////////////// */

.mobile-order-lines {
  display: grid;
  gap: 10px;
  margin: 14px 0 20px;
}

.mobile-order-line-card {
  background: #f9fafb;
  border: 1px solid var(--soft-border);
  border-radius: 14px;
  padding: 12px;
}

.mobile-order-line-main {
  display: grid;
  gap: 5px;
}

.mobile-order-line-main strong {
  line-height: 1.2;
}

.mobile-order-line-main span {
  font-weight: 900;
  color: var(--blue);
}

.desktop-order-lines {
  display: none;
}

.email-preview {
  overflow-wrap: anywhere;
}

.email-preview pre {
  font-size: 0.95rem;
}

@media (min-width: 760px) {
  .mobile-order-lines {
    display: none;
  }

  .desktop-order-lines {
    display: block;
  }
}

/* /////////////////////////////////////
   EMAIL SEND UI
///////////////////////////////////// */

.send-email-form {
  margin-top: 18px;
}

.send-email-form .button {
  width: 100%;
}

.success-box {
  background: var(--green-bg);
  color: var(--green-text);
  padding: 12px;
  border-radius: 14px;
  font-weight: 900;
  margin: 16px 0;
}

@media (min-width: 700px) {
  .send-email-form .button {
    width: auto;
  }
}

/* /////////////////////////////////////
   MODERN CLEAN UI POLISH
   Lighter headings, softer buttons, cleaner cards
///////////////////////////////////// */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --dark: #1f2937;
  --blue: #2563eb;
  --soft-blue: #eff6ff;
  --green: #087f23;
  --soft-border: #e6e8ee;
  --border: #d8dce3;
  --shadow: 0 6px 18px rgba(16, 24, 40, 0.06);
}

body {
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-weight: 400;
}

h1,
h2,
h3 {
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.page-header,
.order-header {
  box-shadow: none;
  border-bottom: 1px solid var(--soft-border);
}

.page-header h1,
.order-header h1 {
  font-weight: 600;
}

.card,
.product-card,
.login-card,
.mobile-admin-card,
.mobile-order-line-card,
.email-preview {
  box-shadow: var(--shadow);
  border: 1px solid var(--soft-border);
}

.product-title,
.basket-status,
.mobile-admin-card strong,
.mobile-order-line-main strong {
  font-weight: 600;
}

.button,
button {
  font-weight: 600;
  border-radius: 12px;
  box-shadow: none;
}

.button-blue {
  background: var(--blue);
}

.logout,
.small-link {
  font-weight: 600;
}

input,
select {
  border-color: var(--border);
  background: #fff;
}

input:focus,
select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--blue);
}

.data-table th {
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  background: #f9fafb;
}

.data-table td {
  font-weight: 400;
}

.status-pill {
  font-weight: 600;
}

.sticky-basket {
  box-shadow: 0 -6px 18px rgba(16, 24, 40, 0.08);
}

.basket-message {
  font-weight: 400;
}

.admin-filter-form {
  box-shadow: none;
}

.checkbox-card {
  font-weight: 500;
}

.email-preview strong {
  font-weight: 600;
}

.email-preview pre {
  font-weight: 400;
  color: var(--text);
}

/* smaller, cleaner admin buttons */
.admin-card-actions .button,
.remove-line {
  font-weight: 600;
}

/* softer desktop table spacing */
@media (min-width: 760px) {
  .data-table th,
  .data-table td {
    padding: 11px 12px;
  }
}

/* /////////////////////////////////////
   MAIN APP NAVIGATION
///////////////////////////////////// */

.app-topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--soft-border);
  padding: 12px 14px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.app-title-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.app-title-wrap h1 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.7rem);
  font-weight: 600;
}

.app-subtitle {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 3px;
}

.nav-toggle {
  min-height: 42px;
  padding: 10px 14px;
  background: var(--blue);
  border-radius: 12px;
  font-size: 0.95rem;
}

.app-nav {
  display: none;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.app-nav.open {
  display: grid;
}

.app-nav a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 500;
  color: var(--text);
  background: #f9fafb;
  border: 1px solid var(--soft-border);
}

.app-nav a.active {
  background: var(--soft-blue);
  color: var(--blue);
  border-color: rgba(37, 99, 235, 0.22);
}

.app-nav .nav-logout {
  color: #991b1b;
}

.order-filter-header {
  top: auto;
  position: sticky;
  z-index: 20;
}

@media (min-width: 820px) {
  .app-topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 18px;
    align-items: center;
    padding: 14px 24px;
  }

  .nav-toggle {
    display: none;
  }

  .app-nav,
  .app-nav.open {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 0;
    justify-content: flex-end;
  }

  .app-nav a {
    min-height: 40px;
    padding: 9px 12px;
    background: transparent;
  }

  .app-nav a:hover {
    background: #f9fafb;
  }
}

/* /////////////////////////////////////
   SITE / USER MANAGER
///////////////////////////////////// */

textarea {
  width: 100%;
  min-height: 120px;
  padding: 13px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  font-family: Arial, sans-serif;
  resize: vertical;
}

textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--blue);
}

.app-nav a[href="/admin-sites.php"],
.app-nav a[href="/admin-users.php"] {
  white-space: nowrap;
}

/* /////////////////////////////////////
   ADMIN SITE SWITCHER FOR ORDERING
///////////////////////////////////// */

.admin-site-switcher {
  background: #ffffff;
  border-bottom: 1px solid var(--soft-border);
  padding: 12px 14px;
}

.admin-site-switcher form {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.admin-site-switcher label {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
}

.admin-site-switcher select {
  min-height: 44px;
}

@media (min-width: 700px) {
  .admin-site-switcher form {
    grid-template-columns: 180px 280px;
    align-items: center;
  }
}

/* /////////////////////////////////////
   TOPBAR SITE SWITCHER
///////////////////////////////////// */

.topbar-site-switcher {
  display: grid;
  grid-template-columns: 42px minmax(150px, 1fr);
  gap: 8px;
  align-items: center;
}

.topbar-site-switcher label {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.topbar-site-switcher select {
  min-height: 40px;
  padding: 8px 34px 8px 10px;
  border-radius: 12px;
  font-size: 0.95rem;
}

.admin-site-switcher {
  display: none !important;
}

@media (max-width: 819px) {
  .app-title-wrap {
    grid-template-columns: 1fr auto;
  }

  .topbar-site-switcher {
    grid-column: 1 / -1;
    grid-template-columns: 42px 1fr;
    order: 3;
  }

  .nav-toggle {
    order: 2;
  }
}

@media (min-width: 820px) {
  .app-title-wrap {
    grid-template-columns: auto minmax(180px, 260px);
  }

  .topbar-site-switcher {
    justify-self: end;
  }
}

/* /////////////////////////////////////
   DESKTOP CENTERED WIDTH LAYOUT
///////////////////////////////////// */

:root {
  --page-max: 1180px;
  --page-pad: clamp(14px, 2vw, 28px);
}

/* Main content centered */
main {
  width: min(var(--page-max), calc(100% - (var(--page-pad) * 2)));
  margin-left: auto;
  margin-right: auto;
  padding-left: 0;
  padding-right: 0;
}

/* Topbar content centered inside full-width header */
.app-topbar {
  display: block;
}

.app-topbar > .app-title-wrap,
.app-topbar > .app-nav {
  width: min(var(--page-max), calc(100% - (var(--page-pad) * 2)));
  margin-left: auto;
  margin-right: auto;
}

/* Order filters centered */
.order-filter-header {
  padding-left: 0;
  padding-right: 0;
}

.order-filter-header .filters {
  width: min(var(--page-max), calc(100% - (var(--page-pad) * 2)));
  margin-left: auto;
  margin-right: auto;
}

/* Sticky basket content centered */
.sticky-basket {
  padding-left: 0;
  padding-right: 0;
}

.sticky-basket .basket-inner {
  width: min(var(--page-max), calc(100% - (var(--page-pad) * 2)));
  margin-left: auto;
  margin-right: auto;
}

/* Admin site selector centered if still present anywhere */
.admin-site-switcher form {
  width: min(var(--page-max), calc(100% - (var(--page-pad) * 2)));
}

/* Cards never become silly wide internally */
.card {
  width: 100%;
}

/* Desktop nav still aligns nicely */
@media (min-width: 820px) {
  .app-topbar {
    padding-left: 0;
    padding-right: 0;
  }

  .app-topbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .app-topbar > .app-title-wrap {
    display: grid;
    grid-template-columns: 1fr minmax(180px, 260px);
    align-items: center;
  }

  .app-topbar > .app-nav {
    justify-content: flex-start;
  }
}

/* Large desktop: slightly narrower content feels cleaner */
@media (min-width: 1400px) {
  :root {
    --page-max: 1120px;
  }
}

/* Small screens keep breathing room */
@media (max-width: 700px) {
  main,
  .app-topbar > .app-title-wrap,
  .app-topbar > .app-nav,
  .order-filter-header .filters,
  .sticky-basket .basket-inner,
  .admin-site-switcher form {
    width: calc(100% - 24px);
  }
}

/* /////////////////////////////////////
   STOP PAGE SHIFT WHEN SCROLLBAR APPEARS
///////////////////////////////////// */

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  min-height: 100vh;
}

/* Keep centred desktop layout stable */
main,
.app-topbar > .app-title-wrap,
.app-topbar > .app-nav,
.order-filter-header .filters,
.sticky-basket .basket-inner {
  box-sizing: border-box;
}
