* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.8;
  overflow-wrap: anywhere;
  overflow-x: hidden;
}

a { color: var(--ink); text-decoration-color: var(--brass); text-underline-offset: 3px; }
a:hover { color: var(--brass); }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

h1, h2, h3 { color: var(--ink); font-weight: 800; line-height: 1.35; margin: 0 0 .5em; }
h1 { font-size: clamp(22px, 4vw, 30px); }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p { margin: 0 0 .8em; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 24px; padding-bottom: 64px; min-width: 0; }
.muted { color: var(--muted); }
.sub { color: var(--muted); font-size: 14px; }
.mono { font-family: ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: isolate; }
.prewrap { white-space: pre-line; }
.notice { color: var(--ok); background: var(--ok-soft); border-radius: 8px; padding: 10px 12px; }
.crumb { font-size: 15px; margin-bottom: 4px; }
.crumb a { text-decoration: none; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.3;
  text-align: center;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-2); color: #fff; }
.btn-outline { background: transparent; color: var(--ink); }
.btn-outline:hover { border-color: var(--brass); color: var(--brass); }
.btn-ghost { background: transparent; color: var(--ink); border-color: transparent; padding: 8px 10px; }
.btn-block { width: 100%; }

/* top bar */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); }
.brand svg { width: 26px; height: 26px; flex: none; }
.wordmark { font-weight: 800; font-size: 19px; }
.top-user { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.who { font-weight: 700; color: var(--ink-2); }
.top-link { font-size: 15px; }
.inline-form { display: inline; margin: 0; }

/* figures */
.summary { margin-top: 8px; }
.figures { display: grid; gap: 12px; margin: 16px 0 24px; }
.fig {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 4px;
  min-width: 0;
}
.fig-label { color: var(--muted); font-size: 14px; }
.fig-value { font-weight: 800; font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; }
.fig-value.muted { font-size: 16px; font-weight: 400; color: var(--muted); }

.filter { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
.filter label { font-weight: 700; }
select, input[type="text"], input[type="date"], input[type="password"], input[type="file"], textarea {
  font: inherit;
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.filter select { width: auto; min-width: 180px; }
input:focus, select:focus, textarea:focus { border-color: var(--brass); outline: 3px solid var(--brass-soft); outline-offset: 0; }

/* forms */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field label, .money legend { font-weight: 700; color: var(--ink); }
.field-row { display: grid; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 700; }
.money { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; margin: 0; min-width: 0; background: var(--card); }
.form-error { color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 10px 12px; margin: 0; }
.new-job { margin-bottom: 24px; }
.new-job > summary { list-style: none; display: inline-block; }
.new-job > summary::-webkit-details-marker { display: none; }
.new-job[open] > summary { margin-bottom: 14px; }
.new-job .form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

/* chips and settlement */
.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.chip-muted { background: #ECEAE4; color: var(--muted); }
.settle { font-size: 15px; }
.settle-ok { color: var(--ok); font-weight: 700; }
.settle-warn { color: var(--warn); font-weight: 700; }
.settle-muted { color: var(--muted); }

/* ledger table */
.ledger-section { margin-top: 8px; }
.ledger { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.ledger th, .ledger td { text-align: start; padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ledger th { font-size: 14px; color: var(--muted); font-weight: 700; }
.ledger tbody tr:hover { background: var(--brass-soft); }
.ledger td .sub { display: block; }
.ledger td a { font-weight: 700; }
.ledger tbody tr:last-child td { border-bottom: 0; }

/* narrow screens: each row becomes a card */
@media (max-width: 719px) {
  .ledger thead { display: none; }
  .ledger, .ledger tbody { display: block; background: transparent; border: 0; }
  .ledger tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 6px 12px;
  }
  .ledger tbody tr:hover { background: var(--card); }
  .ledger td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 6px 0;
    min-width: 0;
  }
  .ledger td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 14px;
    flex: none;
  }
  .ledger td > * { text-align: start; min-width: 0; }
}

/* deal page */
.deal-head { margin-top: 8px; }
.deal-head .meta { color: var(--muted); }
.deal-grid { display: grid; gap: 16px; margin-bottom: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}
.card h2 { margin-bottom: 10px; }
.ledger-list { margin: 0; display: grid; gap: 0; }
.ledger-list > div { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ledger-list > div:last-child { border-bottom: 0; }
.ledger-list dt { color: var(--muted); }
.ledger-list dd { margin: 0; font-weight: 700; text-align: end; font-variant-numeric: tabular-nums; }
.report-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.report-row:last-child { border-bottom: 0; }
.report-label { font-weight: 700; margin: 0; }
.report-row p { margin: 0; }
.messages { margin-top: 16px; }
.entry { padding: 14px 0; border-bottom: 1px solid var(--line); }
.entry:last-of-type { border-bottom: 0; }
.entry-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.entry p { margin: 6px 0; }
.file-link { display: inline-block; margin-top: 4px; margin-inline-end: 12px; font-weight: 700; }
.entry-form { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }

/* admin */
.admin-grid { display: grid; gap: 16px; margin-top: 16px; }
.request-item, .client-block, .deal-line { padding: 12px 0; border-bottom: 1px solid var(--line); }
.request-item:last-child, .client-block:last-child, .deal-line:last-child { border-bottom: 0; }
.deal-line { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.deal-line p { margin: 2px 0 0; }
.plain { list-style: none; padding: 0; margin: 0 0 8px; }
.card h3 { margin-top: 18px; }

/* login and error page */
.login-page { min-height: 100vh; }
.login-wrap { min-height: 80vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  display: grid;
  gap: 16px;
}
.login-mark { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.login-mark svg { width: 32px; height: 32px; }
.login-mark .wordmark { font-size: 22px; }
.error-code { font-size: 40px; font-weight: 800; color: var(--ink); margin: 0; }

@media (min-width: 720px) {
  .deal-grid { grid-template-columns: 1fr 1fr; }
  .field-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .admin-grid { grid-template-columns: 1fr 1fr; }
  .figures { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
