/* ==========================================================================
   Beautifly Shop — Stylesheet (v3, mobile-first redesign)

   Design tokens
   Color   bg #FAF5F3 (warm blush white) · surface #FFFFFF · ink #2A2023
           accent #A23B5C (berry rose — primary brand color) · muted #8B7377
   Type    display: Georgia (elegant serif, boutique feel, no external font
           load needed — this app must work fully offline)
           body: system sans-serif, for everything functional/data-entry
   Shape   soft 12-14px radii, thin 1px warm-toned borders, minimal shadow

   Print rules below (slip layout, @page, @media print) are UNCHANGED from
   the tested/verified version — do not adjust their dimensions casually,
   they were tuned against real printer output.
   ========================================================================== */

:root {
  --bg: #FAF5F3;
  --surface: #FFFFFF;
  --ink: #2A2023;
  --muted: #8B7377;
  --muted-soft: #B8A6A9;
  --accent: #A23B5C;
  --accent-dark: #832C48;
  --accent-soft: #F4E1E6;
  --line: #ECE0DE;
  --line-strong: #DCCBC8;
  --success: #4F7A5B;
  --success-soft: #E8F1EA;
  --warn: #B23A2E;
  --warn-soft: #FBEAE7;
  --info: #3B5A7E;
  --info-soft: #E9EFF4;
  --r: 14px;
  --r-sm: 9px;
  --r-pill: 999px;
  --shadow: 0 1px 2px rgba(42, 32, 35, 0.04), 0 4px 16px rgba(42, 32, 35, 0.06);
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { overflow-x: hidden; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
  width: 100%;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* ------------------------------- top bar ------------------------------ */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
  border: 1.5px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 17px; color: var(--accent);
}
.brand-text { min-width: 0; }
.brand h1 {
  font-family: var(--font-display); font-size: 18px; font-weight: 700; margin: 0;
  color: var(--ink); letter-spacing: 0.2px; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.subtitle { margin: 0; font-size: 11px; color: var(--muted); }
.status-line {
  font-size: 11.5px; white-space: nowrap; font-weight: 600;
  background: var(--accent-soft); color: var(--accent-dark);
  padding: 5px 11px; border-radius: var(--r-pill);
}

/* ------------------------------- layout ------------------------------- */
.layout {
  max-width: 1250px; margin: 0 auto; padding: 16px 14px calc(40px + var(--safe-bottom));
  display: grid; grid-template-columns: 1fr; gap: 16px;
  min-width: 0;
}
@media (min-width: 1000px) {
  .layout { grid-template-columns: 400px 1fr; align-items: start; padding-top: 22px; gap: 20px; }
}

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; min-width: 0; box-shadow: var(--shadow);
}
.panel-head { margin-bottom: 13px; }
.panel-head h2 {
  font-family: var(--font-display); font-size: 17px; font-weight: 700; margin: 0 0 4px;
  color: var(--ink);
}
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.tiny-note { font-size: 11.5px; color: var(--muted-soft); line-height: 1.6; margin: 10px 0 0; }
.tiny-note code { background: var(--accent-soft); color: var(--accent-dark); padding: 1px 5px; border-radius: 4px; }

/* ------------------------------ segmented control ---------------------- */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 4px; margin-bottom: 12px;
}
.segmented-opt {
  display: flex; align-items: center; justify-content: center;
  padding: 9px 8px; border-radius: var(--r-pill); cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--muted); text-align: center;
  transition: background .15s ease, color .15s ease;
}
.segmented-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented-opt:has(input:checked) { background: var(--surface); color: var(--accent-dark); box-shadow: var(--shadow); }

/* ---------------------------------- forms ------------------------------- */
#rawInput {
  width: 100%; min-height: 200px; resize: vertical;
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px;
  font-size: 15px; font-family: var(--font-mono); line-height: 1.55;
  background: var(--bg);
}
#rawInput:focus, input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button-row-secondary { margin-top: 8px; }
.export-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.btn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 10px 15px; border-radius: var(--r-sm); font-size: 13.5px; font-weight: 600;
  cursor: pointer; font-family: var(--font-body); line-height: 1.3;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
  min-height: 44px;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }
.btn-ghost-inverse { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.btn-ghost-inverse:hover { background: rgba(255,255,255,.12); }
.btn-danger-text { color: var(--warn); }
.btn-danger { border-color: var(--warn); color: var(--warn); }
.btn-block { width: 100%; }
.btn-large { padding: 13px 16px; font-size: 14.5px; margin-top: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon-text { background: transparent; border-color: transparent; color: var(--muted); padding: 10px 10px; }
.btn-icon-text:hover { background: var(--bg); color: var(--ink); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
#searchInput, #sortSelect, #gridSelect, #maxProdSelect {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 14px;
  background: var(--surface); color: var(--ink);
}
#searchInput { flex: 1; min-width: 140px; }

/* ------------------------------ print settings accordion --------------- */
.print-settings { margin-bottom: 12px; }
.print-settings summary {
  cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--muted);
  padding: 9px 2px; list-style: none; display: flex; align-items: center; gap: 6px;
}
.print-settings summary::-webkit-details-marker { display: none; }
.print-settings summary::before { content: "\203A"; font-size: 16px; transition: transform .15s ease; display: inline-block; }
.print-settings[open] summary::before { transform: rotate(90deg); }
.settings-row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-sm); margin-top: 4px;
}
.inline-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
}
.checkbox-label { cursor: pointer; }
.checkbox-label input { width: 16px; height: 16px; accent-color: var(--accent); }

/* -------------------------------- banners ------------------------------- */
.review-banner {
  background: var(--warn-soft); color: var(--warn); border: 1px solid #EBC9C4;
  border-radius: var(--r-sm); padding: 10px 13px; font-size: 12.5px; margin-bottom: 12px; line-height: 1.5;
}
.empty-state { color: var(--muted); font-size: 13.5px; padding: 32px 10px; text-align: center; line-height: 1.7; }

/* ------------------------------ order cards ----------------------------- */
.orders-list { display: grid; grid-template-columns: 1fr; gap: 10px; min-width: 0; }
@media (min-width: 1500px) { .orders-list { grid-template-columns: 1fr 1fr; } }

.order-card {
  border: 1px solid var(--line); border-left: 3px solid var(--line-strong);
  border-radius: var(--r-sm); padding: 13px; background: var(--surface);
  min-width: 0; overflow: hidden;
}
.order-card.review { border-left-color: var(--warn); }

.card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; min-width: 0; }
.card-title {
  font-family: var(--font-display); font-size: 14px; font-weight: 700; flex: 1;
  min-width: 0; overflow-wrap: anywhere; word-break: break-word; color: var(--ink);
}
.card-review-flag {
  font-size: 10px; font-weight: 700; color: var(--warn); background: var(--warn-soft);
  padding: 3px 8px; border-radius: var(--r-pill); text-transform: uppercase; letter-spacing: .3px;
}
.card-delete {
  border: none; background: none; color: var(--muted-soft); cursor: pointer; font-size: 16px;
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; line-height: 1;
}
.card-delete:hover { background: var(--warn-soft); color: var(--warn); }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; min-width: 0; }
@media (min-width: 480px) { .field-grid { grid-template-columns: repeat(4, 1fr); } }
.field-grid.secondary { grid-template-columns: repeat(3, 1fr); }

label {
  display: flex; flex-direction: column; gap: 4px; font-size: 10.5px; color: var(--muted);
  font-weight: 600; letter-spacing: .2px; min-width: 0;
}
label.full-width { margin-bottom: 8px; }
input, textarea, select {
  font-family: inherit; font-size: 16px; color: var(--ink); padding: 9px 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface);
  resize: vertical; width: 100%; min-width: 0; box-sizing: border-box;
  overflow-wrap: anywhere; word-break: break-word;
}
@media (min-width: 640px) { input, textarea, select { font-size: 13.5px; } }

.card-more, .raw-details { margin-top: 2px; }
.card-more summary, .raw-details summary {
  font-size: 11.5px; color: var(--muted); cursor: pointer; padding: 6px 0; font-weight: 600;
}
.card-more[open] summary, .raw-details[open] summary { margin-bottom: 6px; }
.raw-details textarea { width: 100%; margin-top: 4px; font-size: 12px; color: var(--muted); font-family: var(--font-mono); }

.app-footer { text-align: center; font-size: 11px; color: var(--muted-soft); padding: 18px; }

/* --------------------------- preview / settings overlay ----------------- */
.preview-overlay {
  position: fixed; inset: 0; background: rgba(42, 32, 35, .78); z-index: 100;
  display: flex; flex-direction: column; backdrop-filter: blur(2px);
}
.preview-overlay[hidden] { display: none !important; }
.preview-bar {
  display: flex; align-items: center; gap: 11px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--ink); color: #fff; font-size: 14px; font-family: var(--font-display); font-weight: 700;
}
.preview-bar .spacer { flex: 1; }
#previewInfo { color: rgba(255,255,255,.65); font-size: 12px; font-family: var(--font-body); font-weight: 400; }
.preview-scroll { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.preview-scroll .a4-page {
  width: 210mm; min-height: 297mm; background: #fff; padding: 12mm;
  box-sizing: border-box;
  box-shadow: 0 2px 20px rgba(0,0,0,.35); flex-shrink: 0;
  max-width: 100%;
}
.preview-scroll .a4-grid { display: grid; gap: 3mm; height: 273mm; }

/* --------------------------- settings modal ----------------------------- */
.settings-scroll { flex: 1; overflow: auto; padding: 18px; display: flex; justify-content: center; }
.settings-card {
  background: var(--surface); border-radius: var(--r); padding: 20px;
  max-width: 480px; width: 100%; height: fit-content;
}
.settings-field {
  display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; color: var(--muted);
  font-weight: 600; letter-spacing: .2px; margin-bottom: 12px;
}
.settings-field input, .settings-field select { font-size: 16px; }
@media (min-width: 640px) { .settings-field input, .settings-field select { font-size: 14px; } }
.settings-field.checkbox-field { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; font-size: 13px; color: var(--ink); line-height: 1.5; }
.settings-field.checkbox-field span { display: flex; gap: 8px; align-items: flex-start; }
.settings-field.checkbox-field input { width: 17px; height: 17px; margin-top: 2px; flex-shrink: 0; accent-color: var(--accent); }
#pathaoProxyRow { margin-bottom: 12px; }
#pathaoProxyRow .hint { margin-bottom: 10px; }
#pathaoProxyRow code { background: var(--accent-soft); color: var(--accent-dark); padding: 1px 5px; border-radius: 4px; }
.settings-card .btn-block { margin-bottom: 10px; }
.settings-card .button-row { flex-direction: column; }

/* ------------------------- mode note + last-added feedback ------------- */
.last-added {
  margin-top: 10px; padding: 12px 13px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--bg); font-size: 12.5px; line-height: 1.6;
}
.last-added .ok { font-weight: 700; color: var(--success); }
.last-added .warn { color: var(--warn); font-weight: 700; }
.last-added dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.last-added dt { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .3px; font-weight: 600; }
.last-added dd { margin: 0; font-size: 12.5px; word-break: break-word; }

/* ------------------------------ courier UI ------------------------------ */
.courier-card {
  margin-top: 16px; padding: 13px; background: var(--info-soft);
  border: 1px solid #D3DEE7; border-radius: var(--r-sm);
}
.courier-card-label {
  margin: 0 0 9px; font-size: 11px; font-weight: 700; color: var(--info);
  text-transform: uppercase; letter-spacing: .5px;
}
.courier-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-courier { border-color: #B9CBDB; background: #fff; color: var(--info); }
.btn-courier:hover { background: #fff; border-color: var(--info); }
.btn-courier:disabled { border-color: var(--line); color: var(--muted-soft); cursor: not-allowed; background: var(--bg); }
.btn-courier:disabled:hover { background: var(--bg); }

.courier-status {
  margin-top: 10px; padding: 10px 13px; border-radius: var(--r-sm); font-size: 12.5px; line-height: 1.6;
  border: 1px solid var(--line); background: var(--surface);
}
.courier-status.ok { border-color: #BEDAC7; background: var(--success-soft); color: var(--success); }
.courier-status.err { border-color: #EBC9C4; background: var(--warn-soft); color: var(--warn); }
.courier-status.busy { border-color: #B9CBDB; background: var(--info-soft); color: var(--info); }
.courier-status ul { margin: 6px 0 0; padding-left: 18px; }
.courier-status li { margin-bottom: 2px; }

.card-courier-badge {
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: var(--r-pill);
  background: var(--info-soft); color: var(--info); border: 1px solid #C7D6E2; white-space: nowrap;
}

/* ==========================================================================
   SLIP — shared by preview and print. Black on white only.
   (unchanged from the tested/verified layout — do not adjust casually)
   ========================================================================== */
.print-area { display: none; }

.a4-grid { display: grid; gap: 3mm; }
.a4-grid.g3x5 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(5, 1fr); }
.a4-grid.g3x4 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); }
.a4-grid.g2x5 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(5, 1fr); }
.a4-grid.g2x4 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(4, 1fr); }
.a4-grid.g2x3 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(3, 1fr); }

.slip {
  border: 0.6pt solid #000;
  padding: 1.4mm 1.7mm;
  display: flex; flex-direction: column;
  overflow: hidden;
  /* Bengali-capable fonts must be listed so Windows/macOS/Android pick a
     font that shapes conjuncts (যুক্তাক্ষর) correctly. Arial has no Bengali
     glyphs, so Latin text uses Arial and Bangla falls through to these. */
  font-family: Arial, Helvetica, "Hind Siliguri", "Nirmala UI", "Vrinda",
               "Shonar Bangla", "Kohinoor Bangla", "Bangla MN", "Noto Sans Bengali",
               "SolaimanLipi", "Siyam Rupali", sans-serif;
  color: #000; background: #fff;
  font-size: 7.4pt;
  line-height: 1.22;
}
/* unused positions stay completely blank so the sticker sheet can be reused */
.slip.empty { border: none; }

/* auto-shrink tiers applied by JS based on content length */
.slip.t1 { font-size: 6.9pt; }
.slip.t2 { font-size: 6.4pt; }
.slip.t3 { font-size: 5.9pt; }
.slip.t4 { font-size: 5.5pt; }

.slip-shop {
  font-weight: 700; font-size: 10pt; text-align: center; letter-spacing: .3pt;
  border-bottom: 0.6pt solid #000; padding-bottom: .5mm; margin-bottom: .6mm;
}
.slip-topline { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.slip-name { font-weight: 700; font-size: 10pt; text-transform: uppercase; }
.slip-ordno { font-size: .82em; white-space: nowrap; }
.slip-phone { font-weight: 700; font-size: 10pt; margin-top: .1mm; }
.slip-address {
  font-size: 8pt; margin-top: .35mm; line-height: 1.2;
  word-break: break-word;
}
.slip-products {
  flex: 1; min-height: 0;
  font-size: 8pt; line-height: 1.2; white-space: pre-wrap; word-break: break-word;
  border-top: 0.4pt dashed #000; margin-top: .5mm; padding-top: .4mm;
  overflow: hidden;
}
/* note + due are kept together and pinned to the very bottom of the slip */
.slip-bottom { margin-top: auto; }
.slip-note {
  font-size: 9pt; font-weight: 700; line-height: 1.2;
  margin-top: .4mm; word-break: break-word;
}
.slip-due {
  display: flex; justify-content: space-between; align-items: baseline;
  border-top: 0.6pt solid #000; margin-top: .4mm; padding-top: .4mm;
  font-weight: 700; font-size: 10pt;
}
.slip-due-label { letter-spacing: .5pt; }
.slip-due.paid .slip-due-val { letter-spacing: 1pt; }

.slip-barcode { text-align: center; margin: 0.6mm 0; }
.slip-barcode-id { font-size: 7.5pt; letter-spacing: 0.5pt; margin-bottom: 0.3mm; font-family: ui-monospace, Menlo, Consolas, monospace; }
.slip-barcode-img { display: flex; justify-content: center; }
.slip-barcode-img svg { display: block; max-width: 100%; height: auto; }

/* ------------------------------- PRINT -------------------------------- */
@media print {
  /* 10mm @page margin + a 2mm inner safety inset on every slip page.
     Real printers each have their own small "unprintable zone" at the
     paper edge (varies by model/brand, often uneven — commonly worse on
     the top and trailing edge because of how the paper feeds through).
     A plain 8mm margin was tight enough that some printers clipped the
     top/right row of slips. 12mm total gives real hardware a safety
     buffer while still fitting 15 slips per page comfortably. */
  @page { size: A4 portrait; margin: 10mm; }

  html, body {
    background: #fff !important; margin: 0; padding: 0;
    width: auto !important; overflow-x: visible !important; /* undo the on-screen mobile-fit rules for print */
  }

  .no-print, .topbar, .layout, .app-footer, .preview-overlay { display: none !important; }
  .print-area { display: block !important; }

  * {
    box-shadow: none !important; text-shadow: none !important;
    background: #fff !important; color: #000 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }

  .a4-page {
    width: 100%; box-sizing: border-box; padding: 2mm;
    page-break-after: always; break-after: page;
  }
  .a4-page:last-child { page-break-after: auto; break-after: auto; }
  .a4-grid { height: 273mm; width: 100%; }
}
