/* ============================================================
   EMM SaaS Design System — base.css
   RTL-first reset + typography + forms. Assumes dir="rtl" on <html>.
   Uses CSS logical properties so light/dark and RTL/LTR both hold.
   ============================================================ */

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

* { margin: 0; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

img, svg, video, canvas { display: block; max-width: 100%; height: auto; }

input, button, textarea, select { font: inherit; color: inherit; }

p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }

ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }

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

/* Latin digits / phones / amounts always read LTR inside RTL text */
.num, .amount, input[ dir="ltr"], input[type="tel"], input[type="url"] {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--font-num);
  display: inline-block;
}

::selection { background: var(--accent); color: var(--cta-fg); }

/* ---------- Accessibility ---------- */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  inset-inline-start: var(--space-md);
  top: -48px;
  background: var(--surface);
  color: var(--text);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: var(--z-toast);
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus { top: var(--space-sm); text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  line-height: var(--leading-heading);
  color: var(--text);
  text-wrap: balance;
}

h1 { font-size: var(--text-4xl); font-weight: var(--weight-black); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

@media (max-width: 640px) {
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-lg); }
}

.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-accent { color: var(--accent-ink); }
.text-center { text-align: center; }
.font-bold { font-weight: var(--weight-bold); }

/* ---------- Layout helpers ---------- */
.container {
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-md);
}

.container-narrow {
  max-width: var(--container-narrow);
  margin-inline: auto;
  padding-inline: var(--space-md);
}

.section { padding-block: var(--space-3xl); }
.section-navy {
  background: var(--navy);
  color: var(--on-navy);
}
.section-navy h2, .section-navy h3 { color: var(--on-navy); }
.section-navy .text-muted { color: var(--on-navy-muted); }

@media (max-width: 640px) {
  .section { padding-block: var(--space-2xl); }
}

/* ---------- Forms ---------- */
.field { margin-block-end: var(--space-md); }

.label {
  display: block;
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  margin-block-end: var(--space-xs);
}

.required { color: var(--accent-ink); }

.hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-block-start: var(--space-2xs);
}

.error-text {
  font-size: var(--text-xs);
  color: var(--danger);
  margin-block-start: var(--space-2xs);
}
.error-text::before { content: "⚠ "; font-size: var(--text-sm); }

.input, .select, .textarea {
  width: 100%;
  padding: 12px var(--space-md);
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  min-height: 44px; /* touch target */
}

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

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

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

.input[aria-invalid="true"], .input.error {
  border-color: var(--danger);
}

.input:disabled, .select:disabled, .textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--surface-2);
}

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

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(0% + 18px) calc(50% - 2px), calc(0% + 13px) calc(50% + 3px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-inline-start: var(--space-xl);
  padding-inline-end: var(--space-md);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  font-size: var(--text-sm);
}
.checkbox-row input[type="checkbox"] {
  width: 20px; height: 20px;
  margin-block-start: 2px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* Search input with icon (icon on the RTL start side) */
.search-box { position: relative; }
.search-box .input { padding-inline-start: 44px; }
.search-box svg {
  position: absolute;
  inset-inline-start: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px; height: 20px;
  color: var(--text-muted);
  pointer-events: none;
}

/* ---------- Tables (base) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--surface);
}

.table th, .table td {
  padding: 10px var(--space-md);
  text-align: start;
  border-block-end: 1px solid var(--border);
}

.table thead th {
  background: var(--surface-2);
  font-weight: var(--weight-bold);
  white-space: nowrap;
}

.table tbody tr:hover { background: var(--surface-2); }
