/* SangShekan - base styles (RTL, no external dependencies so it works offline on the shop PC) */

/* ---------- font: IRANSans (files in Content/fonts, served from this site, no internet needed) ---------- */
@font-face { font-family: "IRANSans"; font-weight: 300; font-style: normal; font-display: swap;
  src: url("fonts/IRANSans-Light.woff2") format("woff2"), url("fonts/IRANSans-Light.woff") format("woff"); }
@font-face { font-family: "IRANSans"; font-weight: 400; font-style: normal; font-display: swap;
  src: url("fonts/IRANSans-Regular.woff2") format("woff2"), url("fonts/IRANSans-Regular.woff") format("woff"); }
@font-face { font-family: "IRANSans"; font-weight: 500; font-style: normal; font-display: swap;
  src: url("fonts/IRANSans-Medium.woff2") format("woff2"), url("fonts/IRANSans-Medium.woff") format("woff"); }
@font-face { font-family: "IRANSans"; font-weight: 700; font-style: normal; font-display: swap;
  src: url("fonts/IRANSans-Bold.woff2") format("woff2"), url("fonts/IRANSans-Bold.woff") format("woff"); }

/* The same letters with Persian digits (۱۲۳). Not used by default: see --font below. */
@font-face { font-family: "IRANSansFaNum"; font-weight: 400; font-style: normal; font-display: swap;
  src: url("fonts/IRANSans-FaNum.woff2") format("woff2"), url("fonts/IRANSans-FaNum.woff") format("woff"); }

:root {
  /* To show Persian digits everywhere, put "IRANSansFaNum" first in this list. */
  --font: "IRANSans", Tahoma, "Segoe UI", sans-serif;
  --bg: #f4f1ec;
  --surface: #ffffff;
  --text: #2b2a28;
  --muted: #6f6a62;
  --line: #ddd7cc;
  --brand: #8a5a2b;
  --brand-dark: #6d4520;
  --ok: #2e7d4f;
  --danger: #b3261e;
  --radius: 8px;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

a { color: var(--brand-dark); }

/* ---------- top bar ---------- */
.topbar {
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.25rem;
  min-height: 3.25rem;
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; color: #fff; text-decoration: none; }
.topbar nav { display: flex; gap: .25rem; flex: 1; }
.topbar nav a { color: #f1e6d8; text-decoration: none; padding: .35rem .8rem; border-radius: var(--radius); }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.topbar .who { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.topbar .who .role { opacity: .75; }
.topbar form { margin: 0; }
.link-btn {
  background: none; border: 1px solid rgba(255,255,255,.5); color: #fff; cursor: pointer;
  border-radius: var(--radius); padding: .25rem .75rem; font: inherit;
}
.link-btn:hover { background: rgba(255,255,255,.14); }

/* ---------- page ---------- */
.container { max-width: 62rem; margin: 1.5rem auto; padding: 0 1rem; }
.container.narrow { max-width: 26rem; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}

/* ---------- forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field input[type=text], .field input[type=password], .field select {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.field.check label { display: inline; font-weight: 400; margin-inline-start: .4rem; }
.field-error, .field-validation-error { color: var(--danger); font-size: .85rem; display: block; }
.input-validation-error { border-color: var(--danger) !important; }
.validation-summary-errors { background: #fdecea; color: var(--danger); border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: 1rem; }
.validation-summary-errors ul { margin: 0; padding-inline-start: 1.1rem; }
.validation-summary-valid { display: none; }
.hint { color: var(--muted); font-size: .85rem; }
.ltr { direction: ltr; text-align: left; unicode-bidi: plaintext; }

.field textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; background: #fff; resize: vertical;
}
.field textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.search { display: flex; gap: .5rem; margin-bottom: 1rem; }
.search input[type=text] {
  flex: 1; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: var(--radius); font: inherit; background: #fff;
}
.search input[type=text]:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; color: var(--muted); }
td.num { font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: .5rem 1.1rem; border-radius: var(--radius); font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: transparent; color: var(--brand-dark); }
.btn.secondary:hover { background: #efe6da; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { padding: .2rem .65rem; font-size: .85rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* ---------- table ---------- */
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td { padding: .6rem .8rem; text-align: right; border-bottom: 1px solid var(--line); }
table.grid th { background: #efe9df; font-weight: 600; }
table.grid tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-size: .8rem; background: #e9e3d9; }
.badge.ok { background: #dcf0e3; color: var(--ok); }
.badge.off { background: #f3dedc; color: var(--danger); }

/* ---------- alerts ---------- */
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert.success { background: #dcf0e3; color: #1d5a37; }
.alert.error { background: #fdecea; color: var(--danger); }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: .5rem 1rem; }
  table.grid { display: block; overflow-x: auto; }
}

/* ======================= invoice screens ======================= */
[hidden] { display: none !important; }

.card.section { margin-bottom: 1rem; }
.card.section h2 { font-size: 1.05rem; margin: 0 0 .9rem; color: var(--brand-dark); }
h3 { font-size: .98rem; margin: 1.2rem 0 .5rem; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0 1rem; }
.field .static { padding: .55rem .2rem; }
.field input[type=text].line-qty, .field input[type=text].inst-date { width: 100%; }

table.lines select, table.lines input[type=text], table.installments input[type=text] {
  width: 100%; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: var(--radius); font: inherit; background: #fff;
}
table.lines td:nth-child(1) { min-width: 11rem; }
table.lines td:nth-child(2) { min-width: 8rem; white-space: nowrap; }
table.lines td.num, table.installments td.num { text-align: left; direction: ltr; }
table.lines { margin-bottom: .75rem; }

.chip { display: inline-flex; align-items: center; gap: .6rem; background: #efe6da; border-radius: 999px; padding: .3rem .5rem .3rem 1rem; margin-bottom: .6rem; }
.results { list-style: none; margin: 0 0 .75rem; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; max-height: 16rem; overflow: auto; }
.results li button { display: flex; justify-content: space-between; width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); padding: .55rem .8rem; font: inherit; cursor: pointer; text-align: right; }
.results li button:hover { background: #f7f1e8; }
.results li.empty { padding: .6rem .8rem; color: var(--muted); }
.search .btn { white-space: nowrap; }

.totals { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; margin-top: .9rem; padding: .8rem 1rem; background: #f7f1e8; border-radius: var(--radius); }
.totals > div { display: flex; align-items: center; gap: .5rem; }
.totals span { color: var(--muted); }
.totals .grand strong { font-size: 1.25rem; }
.totals input[type=text] { width: 9rem; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: var(--radius); font: inherit; }
.totals .ok { color: var(--ok); }
.totals .bad { color: var(--danger); }
.totals .due strong { color: var(--danger); }
.totals.right { justify-content: flex-start; }

.seg { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.seg-item { border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem 1rem; cursor: pointer; background: #fff; }
.seg-item:has(input:checked) { border-color: var(--brand); background: #f4e9dc; font-weight: 600; }
.split { display: inline-flex; gap: .4rem; align-items: center; margin-inline-start: 1rem; }
.split input { width: 3.2rem; padding: .3rem .4rem; border: 1px solid var(--line); border-radius: var(--radius); text-align: center; font: inherit; }
.inline-check { display: inline-flex; align-items: center; gap: .4rem; }

.btn.big { padding: .7rem 2.2rem; font-size: 1.05rem; }
.btn:disabled { opacity: .6; cursor: wait; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 70%, transparent); padding: 1rem 0; }
.topbar nav a.nav-primary { background: rgba(255,255,255,.18); font-weight: 600; }

.filters .actions { margin-top: .25rem; }
.filters { margin-bottom: 1rem; }

/* ======================= invoice view / print ======================= */
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 2px solid var(--brand-dark); padding-bottom: .8rem; margin-bottom: 1rem; }
.invoice-head .company { font-size: 1.3rem; font-weight: 700; }
.invoice-meta { text-align: left; }
.invoice-meta > div { margin-bottom: .1rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .4rem 1.5rem; margin-bottom: 1rem; }
.facts > div { display: flex; gap: .6rem; }
.facts span { color: var(--muted); min-width: 6rem; }
.signatures { display: flex; justify-content: space-around; margin-top: 3rem; color: var(--muted); }
.signatures > div { border-top: 1px solid var(--line); padding-top: .4rem; min-width: 10rem; text-align: center; }

@media print {
  body { background: #fff; font-size: 12pt; }
  .topbar, .no-print, .alert, .pager, .sticky-actions { display: none !important; }
  .container { max-width: none; margin: 0; padding: 0; }
  .card { border: 0; padding: 0; }
  table.grid { border: 1px solid #999; }
  table.grid th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .totals { background: none; border: 1px solid #999; }
  a { color: inherit; text-decoration: none; }
}

/* ---------- one font everywhere ---------- */
/* Form controls do not inherit the page font by themselves. */
input, select, textarea, button, optgroup, option { font-family: inherit; }
h1, h2, h3, h4, th, strong, b, label { font-weight: 700; }
.field label, .ticket-grid .field label, .mini-grid .field label { font-weight: 500; }
.brand, .topbar nav a.nav-primary { font-weight: 700; }
