/* ============================================================
   Orderzy Invoice & Courier — app styles
   Brand: teal mascot (#1fb5ba) + ink wordmark (#16212e)
   Mobile-first. Print layout for invoice slips kept identical
   to the proven original (8 slips per A4: 2 cols × 4 rows).
   ============================================================ */

:root {
  --ink: #16212e;
  --ink-2: #2b3c50;
  --teal: #1fb5ba;
  --teal-deep: #0f8e93;
  --teal-soft: #e1f5f6;
  --paper: #eef4f5;
  --card: #ffffff;
  --line: #dbe5e9;
  --muted: #5d7185;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --danger: #c92a2a;
  --danger-soft: #fdeaea;
  --radius: 14px;
  --shadow: 0 2px 14px rgba(22, 33, 46, 0.08);
  --font-body: 'Noto Sans Bengali', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-display: 'Baloo 2', 'Noto Sans Bengali', system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  background: var(--paper);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}

img { max-width: 100%; }

/* ---------------- top bar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand img { height: 38px; display: block; }

.topnav {
  display: flex;
  align-items: center;
  gap: 2px;
}

.topnav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 56px;
  padding: 6px 8px;
  border-radius: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.topnav a .nav-ico { font-size: 1.15rem; line-height: 1; }
.topnav a.active { color: var(--teal-deep); background: var(--teal-soft); }
.topnav a:hover { color: var(--ink); }
.topnav a.active:hover { color: var(--teal-deep); }
.topnav .nav-logout { color: var(--muted); }

@media (min-width: 720px) {
  .brand img { height: 44px; }
  .topnav { gap: 6px; }
  .topnav a {
    flex-direction: row;
    gap: 7px;
    font-size: 0.95rem;
    padding: 9px 16px;
  }
}

/* ---------------- layout ---------------- */

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 12px 60px;
}

@media (min-width: 720px) {
  .container { padding: 26px 20px 80px; }
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.45rem;
  margin: 0;
}

.page-sub, .card-sub {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 2px 0 0;
}

/* ---------------- cards (slip motif: dashed tear-line on top) ---------------- */

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin-bottom: 18px;
}

.card::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 16px;
  right: 16px;
  border-top: 2px dashed var(--line);
}

.card-flush { padding: 0; overflow: hidden; }
.card-flush::before { display: none; }

.card-title {
  font-family: var(--font-display);
  font-size: 1.12rem;
  margin: 6px 0 2px;
}

@media (min-width: 720px) {
  .card { padding: 22px 22px; }
}

/* ---------------- forms ---------------- */

.field { display: block; }

.field > span, .field-label {
  display: block;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ink-2);
  margin-bottom: 5px;
}

.field .saved-mask {
  font-style: normal;
  font-weight: 500;
  color: var(--teal-deep);
  background: var(--teal-soft);
  border-radius: 6px;
  padding: 1px 7px;
  margin-left: 6px;
  font-size: 0.76rem;
}

input[type="text"], input[type="password"], input[type="url"],
input[type="number"], input[type="tel"], textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
  color: var(--ink);
  background: #fbfdfd;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus-visible, textarea:focus-visible {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(31, 181, 186, 0.18);
}

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

.invalid input, input.invalid, textarea.invalid {
  border-color: var(--danger);
  background: #fffafa;
}

.field-error {
  color: var(--danger);
  font-size: 0.76rem;
  margin-top: 3px;
  display: block;
}

.form-grid { display: grid; gap: 14px; }
.header-controls { display: grid; gap: 12px; margin-bottom: 14px; }

@media (min-width: 720px) {
  .form-grid-3, .header-controls { grid-template-columns: 1fr 1fr 1fr; }
  .form-grid-3 .form-actions, .form-grid .form-actions { grid-column: 1 / -1; }
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hint { color: var(--muted); font-size: 0.85rem; margin: 8px 0 0; min-height: 1em; }

/* ---------------- buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.98rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, transform 0.08s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 3px solid rgba(31, 181, 186, 0.45); outline-offset: 1px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover:not([disabled]) { background: var(--teal-deep); }

.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover:not([disabled]) { background: #223349; }

.btn-ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--ink-2);
}
.btn-ghost:hover:not([disabled]) { border-color: var(--teal); color: var(--teal-deep); }

.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 0.85rem; border-radius: 9px; }
.btn-block { width: 100%; }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 14px;
}

.btn-clear { margin-left: auto; }

/* ---------------- alerts & toasts ---------------- */

.alert {
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.9rem;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert a { color: inherit; font-weight: 700; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cb; }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: #f3ddb5; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: #f2c4c4; }

#toastWrap {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(94vw, 420px);
}

.toast {
  background: var(--ink);
  color: #fff;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 0.9rem;
  box-shadow: 0 6px 22px rgba(22, 33, 46, 0.35);
  animation: toast-in 0.22s ease-out;
}
.toast-ok { background: var(--ok); }
.toast-danger { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- login ---------------- */

.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 14px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 22px;
  text-align: center;
}

.auth-logo { height: 86px; }
.auth-title { font-family: var(--font-display); font-size: 1.35rem; margin: 4px 0 2px; }
.auth-sub { color: var(--muted); font-size: 0.88rem; margin: 0 0 18px; }
.auth-form { display: grid; gap: 13px; text-align: left; }
.auth-hint { margin-top: 16px; text-align: left; font-size: 0.84rem; }

/* ---------------- generated invoice slips (screen) ---------------- */

#outputArea {
  margin: 26px auto 40px;
  width: 100%;
  max-width: 1100px;
}

.page {
  display: flex;
  flex-wrap: wrap;
  width: 7.27in;
  height: 10.5in;
  margin: 0 auto 18px;
  page-break-after: always;
  box-sizing: border-box;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0.3in 0.4in;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 0.18in;
}

.box {
  position: relative;
  width: 3.35in;
  height: 2.3in;
  margin: 0 0 0.12in 0;
  border-radius: 0.25in;
  border: 1.2px solid #e2e8f0;
  background: #fbfcfe;
  box-shadow: 0 2.5px 15px #e5ebf3;
  padding: 0.09in 0.13in;
  box-sizing: border-box;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  overflow: hidden;
  break-inside: avoid;
  page-break-inside: avoid;
}

.box .header {
  font-weight: bold;
  text-align: center;
  font-size: 14px;
  margin-bottom: 14px;
  color: #234e87;
  letter-spacing: 0.01em;
}

.box .invoice-number { font-weight: 700; }

.box .content {
  white-space: pre-line;
  line-height: 1.3;
  flex-grow: 1;
  font-size: 12px;
}

.company-logo-invoice {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 70px;
  height: 45px;
  max-height: 50px;
  opacity: 0.89;
  object-fit: contain;
  z-index: 2;
  pointer-events: none;
}

/* per-slip send button + sent chip (never printed/exported) */
.box-send {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  min-height: 32px;
  min-width: 32px;
  padding: 2px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(22, 33, 46, 0.12);
}
.box-send:hover { border-color: var(--teal); }

.box-sent-chip {
  position: absolute;
  top: 9px;
  left: 9px;
  z-index: 3;
  background: var(--ok-soft);
  color: var(--ok);
  border-radius: 7px;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 7px;
}

/* small screens: slips become fluid cards */
@media (max-width: 820px) {
  .page {
    width: 100% !important;
    height: auto !important;
    gap: 12px !important;
    padding: 12px !important;
  }
  .box {
    width: 100% !important;
    height: auto !important;
    min-height: 2.1in;
    margin: 0 !important;
  }
}

/* ---------------- review modal (bottom sheet on mobile) ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(22, 33, 46, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop[hidden] { display: none; }

.sheet {
  background: var(--card);
  width: 100%;
  max-height: 92dvh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: sheet-up 0.22s ease-out;
}

@media (min-width: 720px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .sheet { max-width: 720px; border-radius: 18px; max-height: 86vh; }
}

@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 0;
}

.sheet-head h2 { font-family: var(--font-display); font-size: 1.15rem; margin: 0; }

.sheet-close {
  border: none;
  background: var(--paper);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--ink-2);
}

.sheet-sub { color: var(--muted); font-size: 0.83rem; margin: 4px 18px 8px; }

.sheet-body {
  overflow-y: auto;
  padding: 4px 14px 10px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.sheet-foot {
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
}

.sheet-progress { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; margin-bottom: 7px; }

/* review rows: each one styled like a little courier slip */
.review-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: #fcfefe;
}

.review-row + .review-row { position: relative; }

.review-row.row-off { opacity: 0.55; }
.review-row.row-done { border-color: #bfe5cb; background: var(--ok-soft); }
.review-row.row-fail { border-color: #f2c4c4; }

.review-top {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.review-top label.inc {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-family: var(--font-display);
}

.review-top input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--teal); }

.dup-badge {
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 7px;
  padding: 2px 8px;
}

.dup-resend {
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--warn);
}

.review-grid { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.review-grid .span-2 { grid-column: 1 / -1; }
.review-grid .field > span { font-size: 0.72rem; margin-bottom: 2px; }
.review-grid input, .review-grid textarea { padding: 7px 10px; border-radius: 8px; }
.review-grid textarea { min-height: 52px; }

.row-result { font-size: 0.8rem; margin-top: 7px; min-height: 1em; }
.row-result.ok { color: var(--ok); font-weight: 700; }
.row-result.fail { color: var(--danger); font-weight: 600; }

/* ---------------- courier history ---------------- */

.balance-pill {
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 8px 16px;
  font: inherit;
  font-weight: 700;
  color: var(--teal-deep);
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.balance-pill .balance-label { color: var(--muted); font-weight: 500; font-size: 0.8rem; }

.orders-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.orders-table th {
  text-align: left;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.orders-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.orders-table tr:last-child td { border-bottom: none; }

.row-date, .row-muted { display: block; color: var(--muted); font-size: 0.76rem; }
.row-addr { max-width: 280px; }
.cod { font-weight: 700; }

.track-link { color: var(--teal-deep); font-weight: 700; text-decoration: none; white-space: nowrap; }
.track-link:hover { text-decoration: underline; }

.status-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 11px;
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--paper);
  color: var(--ink-2);
  text-transform: capitalize;
}
.status-badge[data-status*="delivered"] { background: var(--ok-soft); color: var(--ok); }
.status-badge[data-status*="cancel"], .status-badge[data-status*="return"] { background: var(--danger-soft); color: var(--danger); }
.status-badge[data-status*="review"], .status-badge[data-status*="pending"] { background: var(--warn-soft); color: var(--warn); }

.cell-action { text-align: right; }

/* mobile: table rows become cards */
@media (max-width: 720px) {
  .orders-table thead { display: none; }
  .orders-table, .orders-table tbody, .orders-table tr, .orders-table td { display: block; width: 100%; }
  .orders-table tr { border-bottom: 8px solid var(--paper); padding: 6px 0; }
  .orders-table td { border: none; padding: 6px 14px; }
  .orders-table td[data-th="COD"]::before,
  .orders-table td[data-th="Consignment"]::before,
  .orders-table td[data-th="Status"]::before {
    content: attr(data-th) ": ";
    color: var(--muted);
    font-size: 0.76rem;
  }
  .cell-action { text-align: left; padding-bottom: 12px; }
}

.empty-state { text-align: center; padding: 38px 18px; }
.empty-ico { font-size: 2.4rem; }
.empty-state .btn { margin-top: 12px; }

/* ---------------- settings extras ---------------- */

.webhook-box { margin-top: 20px; border-top: 1px dashed var(--line); padding-top: 14px; }

.copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.copy-row code {
  flex: 1 1 240px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 0.76rem;
  word-break: break-all;
}

.test-result { font-size: 0.86rem; font-weight: 700; }
.test-result.ok { color: var(--ok); }
.test-result.fail { color: var(--danger); }

/* ---------------- export mode: force desktop slip layout for PDF capture ---------------- */

body.exporting #controls,
body.exporting .topbar,
body.exporting .alert,
body.exporting .no-print { display: none !important; }

body.exporting .page {
  width: 7.27in !important;
  height: 10.5in !important;
  gap: 0.3in 0.4in !important;
  padding: 0 !important;
  border: none !important;
  box-shadow: none !important;
  margin: 0 auto !important;
}

body.exporting .box {
  width: 3.35in !important;
  height: 2.3in !important;
  margin: 0 0 0.12in 0 !important;
}

body.exporting { background: #fff; padding-bottom: 0; }

/* ---------------- reduced motion ---------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------- PRINT: proven 8-per-page layout (unchanged) ---------------- */

@media print {
  .topbar, #controls, .button-row, .alert, .no-print,
  .box-send, .box-sent-chip, #toastWrap, .modal-backdrop { display: none !important; }

  body { background: #fff !important; padding: 0; }

  #outputArea { margin: 0; width: auto; max-width: none; }

  .page {
    width: 7.27in !important;
    height: 10.5in !important;
    display: flex !important;
    flex-wrap: wrap !important;
    box-sizing: border-box !important;
    padding: 0in !important;
    margin: 0 auto !important;
    gap: 0.3in 0.4in !important;
    page-break-after: always !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  .box {
    width: 3.35in !important;
    height: 2.3in !important;
    border: 1px solid #000 !important;
    background: #fff !important;
    box-shadow: none !important;
    padding: 0.08in 0.1in !important;
    margin: 0 0 0.12in 0 !important;
    border-radius: 0.25in !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
  }
}
