/* ═══════════════════════════════════════════════════════════════════════
   Reset, typography, forms, buttons
   ═══════════════════════════════════════════════════════════════════════ */

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

* { margin: 0; padding: 0; }

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

img, svg, video { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  color: var(--text);
  letter-spacing: -0.011em;
}

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

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

/* Money and counts use tabular figures so columns line up exactly. */
.num,
.money,
td.num,
th.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  text-align: right;
}

.urdu {
  font-family: var(--font-urdu);
  direction: rtl;
  text-align: right;
}

.text-muted     { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-xs        { font-size: var(--text-xs); }
.text-sm        { font-size: var(--text-sm); }
.text-lg        { font-size: var(--text-lg); }
.text-xl        { font-size: var(--text-xl); }
.text-2xl       { font-size: var(--text-2xl); }
.fw-medium      { font-weight: var(--weight-medium); }
.fw-semibold    { font-weight: var(--weight-semibold); }
.fw-bold        { font-weight: var(--weight-bold); }
.text-center    { text-align: center; }
.text-right     { text-align: right; }
.truncate       { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Visible for keyboard users, invisible for mouse users. */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

.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;
}

/* ─── Forms ──────────────────────────────────────────────────────────── */

.field { margin-bottom: var(--space-4); }

.label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.label .optional {
  color: var(--text-muted);
  font-weight: var(--weight-normal);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: var(--text-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease);
}

.input::placeholder,
.textarea::placeholder { color: var(--text-muted); }

.input:hover,
.select:hover,
.textarea:hover { border-color: var(--neutral); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(13 148 136 / 0.12);
}

.input[readonly],
.input:disabled {
  background: var(--surface-soft);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus { box-shadow: 0 0 0 3px rgb(239 68 68 / 0.12); }

.input-money {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' 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: right 0.625rem center;
  padding-right: 2rem;
}

.textarea { min-height: 84px; resize: vertical; }

.field-error {
  display: block;
  font-size: var(--text-sm);
  color: var(--danger-text);
  margin-top: var(--space-1);
}

.field-hint {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-base);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ─── Buttons ────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.5rem 0.875rem;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: 1.25;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--fast) var(--ease),
              border-color var(--fast) var(--ease),
              transform var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease);
  text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-soft);
  color: var(--text);
}

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-soft);
  color: var(--text);
}

.btn-danger { background: var(--danger); color: var(--text-inverse); }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-success { background: var(--success); color: var(--text-inverse); }

.btn-sm { padding: 0.3125rem 0.625rem; font-size: var(--text-sm); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { padding: 0.625rem 1.25rem; font-size: var(--text-md); }
.btn-block { width: 100%; }

.btn-icon {
  padding: 0.375rem;
  width: 32px; height: 32px;
  border-radius: var(--radius);
}
.btn-icon.btn-sm { width: 28px; height: 28px; padding: 0.25rem; }

/* ─── Layout helpers ─────────────────────────────────────────────────── */

.stack   { display: flex; flex-direction: column; gap: var(--space-4); }
.row     { display: flex; align-items: center; gap: var(--space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.wrap    { flex-wrap: wrap; }
.grow    { flex: 1 1 auto; min-width: 0; }
.gap-1   { gap: var(--space-1); }
.gap-2   { gap: var(--space-2); }
.gap-4   { gap: var(--space-4); }
.gap-6   { gap: var(--space-6); }
.mt-2    { margin-top: var(--space-2); }
.mt-4    { margin-top: var(--space-4); }
.mt-6    { margin-top: var(--space-6); }
.mb-2    { margin-bottom: var(--space-2); }
.mb-4    { margin-bottom: var(--space-4); }
.mb-6    { margin-bottom: var(--space-6); }
.hidden  { display: none !important; }
