/* ---------------------------------------------------------------------------
 * Reset, typography and form controls.
 *
 * The document is `dir="rtl"`. Every rule below uses logical properties
 * (`margin-inline-start`, `padding-inline`, `inset-inline-end`) rather than
 * left/right, so the layout mirrors correctly without a second stylesheet.
 * ------------------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-ar);
  font-size: var(--fs-md);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5 {
  color: var(--text-heading);
  line-height: 1.4;
  font-weight: 700;
}

h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

ul, ol { list-style: none; }

/* Latin fragments — invoice numbers, SKUs, amounts — read left-to-right
   inside Arabic sentences and align on the decimal point in tables. */
.num,
.mono {
  font-family: var(--font-en);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
}
.mono { font-family: var(--font-mono); }

.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger-fg); }
.text-success { color: var(--success-fg); }
.text-warning { color: var(--warning-fg); }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }

/* ==================== FORM CONTROLS ==================== */

label {
  display: block;
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 6px;
}

.field { margin-bottom: var(--space-4); }
.field .hint {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 400;
}
.field .error-text {
  font-size: var(--fs-xs);
  color: var(--danger-fg);
  margin-top: 4px;
  font-weight: 600;
}
.req { color: var(--danger); margin-inline-start: 2px; }

input[type='text'],
input[type='password'],
input[type='number'],
input[type='date'],
input[type='search'],
input[type='tel'],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
  font-family: var(--font-ar);
  color: var(--text-heading);
  background: var(--input-bg);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type='number'],
input[type='date'] {
  direction: ltr;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

select {
  /* The native arrow sits on the wrong side in RTL on some engines, so it is
     suppressed and redrawn as a background chevron on the inline-start edge. */
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 10px center;
  padding-inline-start: 32px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

input:disabled,
select:disabled,
textarea:disabled,
input[readonly] {
  background: var(--input-disabled-bg);
  color: var(--text-muted);
  cursor: not-allowed;
}

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

textarea { resize: vertical; min-height: 78px; line-height: 1.7; }

::placeholder { color: var(--text-muted); font-weight: 400; }

input[type='checkbox'],
input[type='radio'] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  vertical-align: middle;
}

.check-label,
.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: var(--fs-md);
  color: var(--text);
  cursor: pointer;
  margin-bottom: 0;
}

/* ==================== LAYOUT UTILITIES ==================== */

.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.w-full { width: 100%; }
.text-center { text-align: center; }

.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* Screen-reader-only text for icon-only controls. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
