@font-face {
  font-family: 'Bowery Lane';
  src: url('../fonts/BoweryLane-Medium.woff') format('woff');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Bogart';
  src: url('../fonts/Bogart-Semibold.woff') format('woff');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Tomato Grotesk';
  src: url('../fonts/TomatoGrotesk-Regular.woff') format('woff');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Tomato Grotesk';
  src: url('../fonts/TomatoGrotesk-Medium.woff') format('woff');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Produkt';
  src: url('../fonts/Produkt-Regular.woff') format('woff');
  font-weight: 400;
  font-display: swap;
}

:root {
  --navy-950: #050b18;
  --navy-900: #0a1730;
  --navy-800: #10203f;
  --navy-700: #182d4e;
  --navy-600: #223c63;
  --silver: #b9c4d6;
  --silver-dim: #7c8aa3;
  --white: #f4f6fa;
  --good: #199e70;
  --warn: #c98500;
  --accent: #3987e5;
  --radius: 14px;
  --font-body: 'Tomato Grotesk', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: 'Bowery Lane', var(--font-body);
  --font-serif: 'Bogart', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy-950);
  color: var(--white);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  background: radial-gradient(circle at 20% -10%, var(--navy-700), var(--navy-950) 60%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
}

a { color: var(--accent); }

.screen {
  flex: 1;
  display: none;
  flex-direction: column;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px calc(100px + env(safe-area-inset-bottom));
}
.screen.active { display: flex; }

/* ---------- Login ---------- */
#screen-login {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 18px;
}
.login-logo {
  width: min(280px, 78%);
  height: auto;
  margin-bottom: 8px;
  /* source artwork is navy-on-transparent; force it white for our dark background */
  filter: brightness(0) invert(1);
}
.brand-sub { color: var(--silver-dim); font-size: 13px; text-transform: uppercase; letter-spacing: 0.18em; font-weight: 600; }

.login-card {
  width: 100%;
  background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
  border: 1px solid var(--navy-600);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

label { font-size: 12px; color: var(--silver); text-transform: uppercase; letter-spacing: 0.08em; text-align: left; }

input, select, textarea {
  background: var(--navy-950);
  border: 1px solid var(--navy-600);
  color: var(--white);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 14px 18px;
  min-height: 48px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; border: 1px solid var(--navy-600); color: var(--white); }
.btn-block { width: 100%; }

.error-text { color: #e35b5b; font-size: 13px; min-height: 16px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 26px;
}
.topbar-logo { height: 88px; width: auto; }
.icon-btn {
  background: var(--navy-800);
  border: 1px solid var(--navy-600);
  color: var(--silver);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 4px;
}

.rep-block { margin-bottom: 24px; }
.rep-block .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 32px;
  line-height: 1.08;
  letter-spacing: 0.01em;
}
.rep-block .rep-label {
  color: var(--silver-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
  margin-top: 4px;
}

/* ---------- Landing / stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}
.stat-card {
  background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
  border: 1px solid var(--navy-600);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .label { color: var(--silver-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }

.cta-row { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.cta-btn {
  background: linear-gradient(135deg, var(--accent), #2a63a8);
  border: none;
  border-radius: var(--radius);
  color: white;
  padding: 20px;
  font-size: 18px;
  font-weight: 700;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.cta-btn small { display: block; font-weight: 400; font-size: 12px; opacity: 0.85; margin-top: 4px; }
.cta-btn.secondary { background: var(--navy-800); border: 1px solid var(--navy-600); }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--silver-dim);
  margin: 4px 0 10px;
}

.order-history { display: flex; flex-direction: column; gap: 8px; }
.order-row {
  background: var(--navy-800);
  border: 1px solid var(--navy-600);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.order-row .oname { font-weight: 600; }
.order-row .osub { color: var(--silver-dim); font-size: 12px; }
.order-row.clickable { cursor: pointer; transition: border-color 0.15s ease; }
.order-row.clickable:active { border-color: var(--accent); }
.pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 100px;
  background: var(--navy-600);
  color: var(--white);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pill.pending { background: rgba(201, 133, 0, 0.25); color: var(--warn); }
.pill.confirmed, .pill.invoiced { background: rgba(25, 158, 112, 0.25); color: var(--good); }

.empty-note { color: var(--silver-dim); font-size: 13px; text-align: center; padding: 20px 0; }

/* ---------- Product picker ---------- */
.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.product-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--navy-800);
  border: 1px solid var(--navy-600);
  border-radius: var(--radius);
  padding: 14px 10px 16px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
.product-tile:active { transform: scale(0.97); }
.product-tile.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 135, 229, 0.35);
}
.tile-check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile-logo {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background-color: var(--navy-900);
  background-image: radial-gradient(circle at 50% 30%, var(--navy-700), var(--navy-900) 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 8px;
}
.tile-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10px;
}
.tile-name { font-size: 15px; font-weight: 700; text-align: center; line-height: 1.2; }
.tile-sub { color: var(--silver-dim); font-size: 11px; text-align: center; }

.product-details-card {
  border-radius: var(--radius);
  border: 1px solid var(--navy-600);
  background: var(--navy-800);
  overflow: hidden;
  margin-bottom: 12px;
  padding: 14px;
}
.details-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; }

.format-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px 14px;
  border-top: 1px solid var(--navy-700);
  margin-top: 2px;
  padding-top: 12px;
}
.format-row {
  transition: transform 0.15s ease;
}
.format-row:active { transform: scale(0.98); }
.format-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--navy-900);
  border: 1px solid var(--navy-600);
  border-radius: 10px;
  padding: 10px 12px;
}
.format-row .flabel { font-size: 13px; font-weight: 600; }
.format-row .fdetail { font-size: 11px; color: var(--silver-dim); }
.format-row .fcode { font-size: 10px; color: var(--silver-dim); font-family: ui-monospace, SFMono-Regular, monospace; }
.qty-stepper { display: flex; align-items: center; gap: 8px; }
.qty-stepper button {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--navy-600);
  background: var(--navy-800);
  color: var(--white);
  font-size: 16px;
  cursor: pointer;
}
.qty-stepper .qty-val { width: 24px; text-align: center; font-weight: 700; }

/* ---------- Order form ---------- */
.order-summary {
  background: var(--navy-800);
  border: 1px solid var(--navy-600);
  border-radius: var(--radius);
  padding: 14px;
  margin: 16px 0;
}
.order-summary .oline {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--navy-700);
}
.order-summary .oline:last-child { border-bottom: none; }

.sticky-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, rgba(5,11,24,0), var(--navy-950) 30%);
  padding: 16px 20px max(24px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
}
.sticky-footer .inner { max-width: 440px; width: 100%; display: flex; gap: 10px; }

.toast {
  position: fixed;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  background: var(--good);
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }
.toast.error { background: #b33636; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.back-link {
  color: var(--silver);
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  cursor: pointer;
  padding: 6px 0;
}

/* ---------- Small screens ---------- */
@media (max-width: 380px) {
  .screen { padding-left: 16px; padding-right: 16px; }
  .rep-block .name { font-size: 26px; }
  .topbar-logo { height: 72px; }
  .stat-grid { gap: 8px; }
  .stat-card { padding: 12px; }
}

/* ---------- Invoice ---------- */
.invoice-doc {
  background: #fff;
  color: #000;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10.5px;
  border-radius: 10px;
  padding: 18px 16px;
  margin-bottom: 20px;
}
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}
.inv-logo { width: 130px; }
.inv-doc-label { font-size: 13px; color: #808080; margin-top: 2px; }

.inv-info-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  font-size: 10.5px;
  line-height: 1.5;
}
.inv-meta-block { text-align: left; }

.inv-parties {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
  font-size: 10.5px;
  line-height: 1.5;
}
.inv-heading { font-weight: 700; }

/* On-screen: each row renders as a stacked card (thead hidden, td becomes a
   label:value line via data-label) so nothing needs horizontal scrolling on
   a phone. @media print below switches this back to a real table. */
table.inv-items {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 12px;
  display: block;
}
table.inv-items thead { display: none; }
table.inv-items tbody { display: block; }
table.inv-items tr {
  display: block;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
table.inv-items td {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 3px 0;
  border: none;
}
table.inv-items td::before {
  content: attr(data-label);
  color: #8b8c94;
  font-size: 10.5px;
  flex-shrink: 0;
}
table.inv-items td:first-child {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}
table.inv-items td:first-child::before { content: none; }

.inv-totals-wrap { display: flex; justify-content: flex-end; margin-bottom: 30px; }
.inv-totals { width: 100%; max-width: 250px; font-size: 10.5px; }
.inv-totals .row { display: flex; justify-content: space-between; padding: 2.5px 0; }
.inv-totals .row.bold { font-weight: 700; }

.inv-signatures {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 20px;
}
.inv-sig-line { border-top: 1px solid #000; margin-bottom: 4px; }
.inv-sig-label { font-size: 10px; }

.inv-footer-note { text-align: center; font-size: 10.5px; margin-bottom: 14px; }
.inv-terms-note {
  border-top: 1px solid #ccc;
  padding-top: 8px;
  font-size: 9px;
  font-style: italic;
  color: #444;
  text-align: center;
  line-height: 1.5;
}

@media print {
  body * { visibility: hidden; }
  .invoice-doc, .invoice-doc * { visibility: visible; }
  .invoice-doc {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    border-radius: 0;
    padding: 0.4in;
  }
  .inv-info-row, .inv-parties { flex-direction: row; justify-content: space-between; }
  .inv-meta-block { text-align: left; }
  .inv-signatures { flex-direction: row; justify-content: space-between; gap: 60px; }
  table.inv-items { display: table; font-size: 10.5px; }
  table.inv-items thead { display: table-header-group; }
  table.inv-items thead tr { border-top: 1px solid #999; border-bottom: 1px solid #999; }
  table.inv-items th { text-align: left; font-weight: 700; padding: 5px 6px; }
  table.inv-items th.num, table.inv-items td.num { text-align: right; }
  table.inv-items tbody { display: table-row-group; }
  table.inv-items tr { display: table-row; border: none; padding: 0; margin: 0; border-radius: 0; }
  table.inv-items td {
    display: table-cell;
    padding: 5px 6px;
    border: none;
    border-bottom: 1px solid #ccc;
    vertical-align: top;
  }
  table.inv-items td::before { content: none; }
  table.inv-items td:first-child { font-weight: 400; margin-bottom: 0; }
  .no-print { display: none !important; }
}

/* ---------- Accounts map ---------- */
.accounts-map {
  width: 100%;
  height: 320px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--navy-600);
}
.lm-pin {
  width: 24px;
  height: 24px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  position: relative;
}
.lm-pin::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--navy-800);
  color: var(--white);
  border-radius: 8px;
}
.leaflet-popup-content { font-size: 13px; color: var(--white); }
