/* Fargard Tailoring — one stylesheet. RTL, tokens, phone (375px) and A4 print. */
:root {
  --brand: #1fbf5c;
  --brand-dark: #138a41;
  --brand-soft: #e6f8ee;
  --nav: #13294b;
  --nav-2: #1b3966;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #667085;
  --line: #dde2ea;
  --ink-blue: #1849a9;   /* owed to us */
  --ink-red: #c0262d;    /* we owe */
  --ok: #157f3c;
  --warn-bg: #fff6d6;
  --warn-line: #e8c547;
  --err-bg: #fdecec;
  --err-line: #e7a1a1;
  --ok-bg: #e7f7ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: "Vazirmatn", Tahoma, sans-serif;
  --font-title: "Noto Naskh Arabic", "Vazirmatn", Tahoma, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.6; }
a { color: var(--ink-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-title); line-height: 1.35; margin: 0 0 .6rem; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
small, .muted { color: var(--muted); }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin: 0 0 1rem; }
legend { padding: 0 .4rem; font-weight: 600; }
img { max-width: 100%; }

/* ---------- layout */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .6rem;
  background: var(--nav); color: #fff; padding: .45rem .9rem; min-height: 52px; }
.topbar a { color: #fff; }
.topbar .brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; white-space: nowrap; }
.topbar .brand img { height: 32px; width: auto; background: #fff; border-radius: 6px; padding: 2px; }
.topbar .company { font-family: var(--font-title); font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .85rem; opacity: .9; white-space: nowrap; }
.topbar form { margin: 0; }
.menu-btn { display: none; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 8px;
  padding: .25rem .6rem; font: inherit; cursor: pointer; }
.layout { display: flex; align-items: flex-start; min-height: calc(100vh - 52px); }
.sidebar { width: 235px; flex: none; background: var(--card); border-left: 1px solid var(--line);
  position: sticky; top: 52px; max-height: calc(100vh - 52px); overflow-y: auto; padding: .5rem 0 2rem; }
.sidebar details { border-bottom: 1px solid var(--line); }
.sidebar summary { cursor: pointer; padding: .55rem 1rem; font-weight: 600; list-style: none; display: flex; align-items: center; gap: .5rem; }
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary::after { content: "‹"; margin-inline-start: auto; transition: transform .15s; color: var(--muted); }
.sidebar details[open] summary::after { transform: rotate(-90deg); }
.sidebar nav a { display: flex; gap: .5rem; align-items: center; padding: .38rem 1.4rem .38rem 1rem; color: var(--text); font-size: .93rem; }
.sidebar nav a:hover { background: var(--brand-soft); text-decoration: none; }
.sidebar nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; border-right: 3px solid var(--brand); }
.sidebar .ver { padding: .8rem 1rem; font-size: .78rem; color: var(--muted); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
main.content { flex: 1; min-width: 0; padding: 1rem 1.2rem 3rem; }
.page-head { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }

/* ---------- cards, grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem .5rem; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.tile .icon { width: 28px; height: 28px; color: var(--brand-dark); }
.tile:hover { border-color: var(--brand); text-decoration: none; background: var(--brand-soft); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.35rem; font-weight: 700; }
.stat a.value { display: block; color: inherit; }

/* ---------- forms */
label { display: block; font-size: .88rem; color: #344054; margin-bottom: .2rem; font-weight: 500; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=tel], input[type=search],
input:not([type]), select, textarea {
  width: 100%; font: inherit; padding: .48rem .6rem; border: 1px solid #c9d0db; border-radius: 8px; background: #fff; color: var(--text); min-width: 0; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,191,92,.35); border-color: var(--brand); }
input.num, input.money { direction: ltr; text-align: left; }
.field { margin-bottom: .75rem; min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .1rem .8rem; }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 400; margin: .2rem 0; }
.check input { width: auto; }
.inline-form { display: inline; margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .7rem; margin-bottom: 1rem; }
.filters .field { margin: 0; flex: 1 1 140px; }
.filters .field.wide { flex: 2 1 220px; }
.hint { font-size: .82rem; color: var(--muted); }

/* measurement boxes (like the tailor's form) */
.measure-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .55rem; }
.measure-grid .field { margin: 0; border: 1.5px solid #a77bd6; border-radius: 10px; padding: .3rem .55rem; background: #faf7fe; }
.measure-grid .field label { font-weight: 700; color: #4d2c78; margin: 0; }
.measure-grid input { border: none; background: transparent; padding: .15rem 0; font-size: 1.1rem; font-weight: 600; outline: none; }
.measure-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .35rem; }
.measure-view div { border: 1px solid #d9c8ef; border-radius: 8px; padding: .2rem .5rem; background: #fcfaff; }
.measure-view b { display: block; font-size: .8rem; color: #5b3c86; }
.measure-view span { font-size: 1.05rem; font-weight: 700; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .92rem;
  padding: .45rem .9rem; border-radius: 8px; border: 1px solid #c9d0db; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; background: #f5f7fa; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--ink-red); border-color: var(--err-line); }
.btn-wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn-sm { padding: .2rem .55rem; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkish { background: none; border: none; color: var(--ink-blue); font: inherit; cursor: pointer; padding: 0; }

/* ---------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .45rem .55rem; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th { background: #f6f8fb; font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: #fafcff; }
tfoot td { font-weight: 700; background: #f6f8fb; }
td.n, th.n { text-align: left; direction: ltr; white-space: nowrap; }
td .d { display: block; white-space: nowrap; }
td .wd, .wd { display: block; font-size: .75rem; color: var(--muted); white-space: nowrap; }
.row-rev td { color: var(--muted); text-decoration: line-through; }
.row-neg td { color: var(--ink-red); }
.empty { text-align: center; color: var(--muted); padding: 1.2rem; }
.owed { color: var(--ink-blue); font-weight: 700; }
.weowe { color: var(--ink-red); font-weight: 700; }

/* ---------- badges, messages */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: #eef1f5; color: #344054; }
.st-new { background: #eef4ff; color: #1849a9; }
.st-sewing { background: #fff3e0; color: #a15c00; }
.st-finishing { background: #f3e8ff; color: #6b21a8; }
.st-ready { background: #e3f7ea; color: #157f3c; }
.st-delivered { background: #e6e9ee; color: #344054; }
.st-cancelled { background: #fdecec; color: #b42318; }
.badge-trial { background: #eef4ff; color: #1849a9; } .badge-active { background: #e3f7ea; color: #157f3c; }
.badge-grace { background: #fff3e0; color: #a15c00; } .badge-readonly { background: #fdecec; color: #b42318; }
.badge-suspended { background: #344054; color: #fff; }
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: .6rem; border: 1px solid; }
.flash-success { background: var(--ok-bg); border-color: #9fd8b1; }
.flash-error { background: var(--err-bg); border-color: var(--err-line); }
.flash-warning { background: var(--warn-bg); border-color: var(--warn-line); }
.flash-info { background: #eef4ff; border-color: #b2ccff; }
.banner { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; padding: .55rem 1rem; border-radius: 8px; margin-bottom: .7rem; }
.banner-red { background: #b42318; color: #fff; } .banner-orange { background: #fff3e0; border: 1px solid #f5c27a; }
.banner-blue { background: #eef4ff; border: 1px solid #b2ccff; } .banner-green { background: var(--ok-bg); border: 1px solid #9fd8b1; }
.banner .btn { font-size: .82rem; padding: .2rem .6rem; }
.note-box { background: #fff9c4; border: 1px solid #ecd96b; border-radius: 8px; padding: .5rem .75rem; margin: .4rem 0; white-space: pre-wrap; }
.balance-line { margin: .3rem 0; font-size: .92rem; }
.preview { background: #f6f8fb; border: 1px dashed #b7c0cd; border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0; }

/* ---------- order item rows */
.item-row { border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem; margin-bottom: .7rem; background: #fcfdff; position: relative; }
.item-row .row-num { font-weight: 700; color: var(--brand-dark); }
.item-row .line-total { font-weight: 700; }
.totals-box { display: grid; grid-template-columns: auto auto; gap: .25rem 1rem; justify-content: start; font-size: .95rem; }
.totals-box .big { font-size: 1.2rem; font-weight: 800; }
.design-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.design-card img { width: 100%; height: 170px; object-fit: cover; border-radius: 8px; background: #f2f4f7; }
.design-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .8rem; }
.design-card .noimg { height: 170px; display: flex; align-items: center; justify-content: center; background: #f2f4f7; border-radius: 8px; color: var(--muted); }

/* select search box */
.select-search { margin-bottom: .3rem; }

/* login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: linear-gradient(160deg, #13294b 0%, #1b3966 55%, #138a41 140%); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 1.6rem 1.4rem; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-card .logo { display: block; width: 150px; margin: 0 auto .6rem; }
.login-card h1 { text-align: center; font-size: 1.25rem; }
.login-card .ver { text-align: center; font-size: .8rem; color: var(--muted); margin-top: 1rem; }

.pagination { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin: .5rem 0 1rem; }
.pagination a, .pagination span { padding: .2rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pagination .cur { background: var(--brand); color: #fff; border-color: var(--brand); }

.print-only { display: none; }
.print-head { display: none; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .3rem 0; border-bottom: 1px dashed var(--line); font-size: .88rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .8rem; }
.tabs a { padding: .3rem .8rem; border-radius: 99px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: .88rem; }
.tabs a.on { background: var(--nav); color: #fff; border-color: var(--nav); }
dialog { border: none; border-radius: 12px; padding: 1rem; max-width: min(520px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(16,24,40,.45); }

/* ---------- phone (screen only: never affects A4 print) */
@media screen and (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-block; }
  .sidebar { position: fixed; top: 52px; right: 0; bottom: 0; z-index: 40; transform: translateX(105%); transition: transform .2s;
    box-shadow: -4px 0 20px rgba(0,0,0,.15); max-height: none; }
  body.menu-open .sidebar { transform: none; }
  .topbar .who { display: none; }
  main.content { padding: .8rem .75rem 3rem; }
}
@media screen and (max-width: 480px) {
  body { font-size: 14.5px; }
  .topbar .brand span { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .value { font-size: 1.1rem; }
  .measure-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .page-head h1 { font-size: 1.2rem; }
}

/* ---------- print (A4) */
@page { size: A4; margin: 12mm 10mm; }
@media print {
  body { background: #fff; font-size: 11.5pt; }
  .topbar, .sidebar, .no-print, .filters, .pagination, .flash, .banner, .actions, .menu-btn, dialog { display: none !important; }
  .print-only { display: block; }
  .print-head { display: flex; align-items: center; gap: 10px; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 10px; }
  .print-head img { height: 48px; }
  .print-head .t { flex: 1; }
  .print-head .t b { font-size: 14pt; display: block; }
  main.content { padding: 0; }
  .layout { display: block; }
  .card { box-shadow: none; border: 1px solid #999; break-inside: avoid; }
  .table-wrap { overflow: visible; border: none; }
  table { font-size: 9.5pt; }
  th, td { padding: 3px 4px; border: 1px solid #999; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
  a { color: #000; }
  .measure-grid .field, .measure-view div { border-color: #666; background: #fff; }
}

/* ================= version 2.0.0 ================= */
.sidebar nav .icon, .sidebar summary .icon { color: var(--brand); }
.sidebar nav a.active .icon { color: var(--brand-dark); }
.pg-hidden { display: none; }
.topbar .top-actions { display: flex; gap: .35rem; align-items: center; }
.topbar .top-actions .btn { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.3); }
.topbar .top-actions .btn:hover { background: rgba(255,255,255,.18); }
.topbar .top-actions .icon { color: #7ee2a4; }
.jpicker { position: absolute; z-index: 100; width: 260px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(16,24,40,.2); padding: .5rem; direction: rtl; }
.jp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .3rem; }
.jp-head button, .jp-foot button { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: .1rem .6rem; cursor: pointer; }
.jp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jp-wd { font-size: .78rem; color: var(--muted); padding: .2rem 0; }
.jp-day { font: inherit; border: none; background: none; border-radius: 6px; padding: .3rem 0; cursor: pointer; }
.jp-day:hover { background: var(--brand-soft); }
.jp-day.today { outline: 1px solid var(--brand); }
.jp-day.on { background: var(--brand); color: #fff; }
.jp-foot { display: flex; justify-content: space-between; margin-top: .35rem; }
input.jdate { direction: ltr; text-align: right; }
.bulk-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; background: #f6fbf8; border: 1px solid #b9e8cb;
  border-radius: var(--radius); padding: .6rem .7rem; margin-bottom: .6rem; }
.bulk-bar .field { margin: 0; flex: 1 1 160px; }
.about-hero { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.about-hero img { width: 140px; }
.contact-list { list-style: none; padding: 0; margin: 0; }
.contact-list li { padding: .35rem 0; border-bottom: 1px dashed var(--line); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.person-tag { display: inline-block; background: #eef4ff; color: #1849a9; border-radius: 99px; padding: 0 .5rem; font-size: .8rem; font-weight: 700; }
@media screen and (max-width: 900px) {
  .topbar .top-actions .btn span { display: none; }
  .topbar .company { display: none; }
}
@media print {
  .pg-hidden { display: table-row !important; }
  .jpicker { display: none !important; }
}

/* ================= version 2.1.0 ================= */
.user-menu { position: relative; }
.user-menu > summary { list-style: none; background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.3); }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary .icon { color: #7ee2a4; }
.user-menu > summary span { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-list { position: absolute; left: 0; top: calc(100% + 6px); min-width: 220px; background: #fff; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(16,24,40,.22); padding: .35rem; z-index: 60; }
.user-menu-head { padding: .4rem .6rem .5rem; border-bottom: 1px solid var(--line); margin-bottom: .3rem; font-weight: 700; }
.user-menu-head small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.user-menu-list a, .user-menu-list button { display: flex; width: 100%; gap: .5rem; align-items: center; padding: .45rem .6rem;
  border-radius: 8px; color: var(--text); background: none; border: none; font: inherit; cursor: pointer; text-align: right; }
.user-menu-list a:hover, .user-menu-list button:hover { background: var(--brand-soft); text-decoration: none; }
.user-menu-list .icon { color: var(--brand); }
.user-menu-list form { margin: 0; border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .3rem; }
.user-menu-list button[data-top="logout"] { color: var(--ink-red); }
.user-menu-list button[data-top="logout"] .icon { color: var(--ink-red); }
.actions-cell { white-space: nowrap; }
.order-detail > td { background: #f7fbf9; }
.detail-box { padding: .3rem 0; }
.detail-box .actions { margin-top: .4rem; }
tr.is-open > td { background: #eefaf3; }
.guide-img { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; }
@media screen and (max-width: 900px) {
  .user-menu > summary span { display: none; }
}
