/* ============================================================
   form.css — Permit entry form styles
   Hebrew RTL two-column layout
   ============================================================ */

/* ── 1. TOP-LEVEL TWO-COLUMN LAYOUT ──────────────────────── */

/*
  In RTL layout:
    - Right column (grid-column 2): the entry form  ← user fills in data
    - Left column  (grid-column 1): results panel   ← compliance output
*/
.permit-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  grid-template-rows: auto;
  gap: 1.5rem;
  align-items: start;
}

/* Form occupies the right column (column 2 in RTL = visually on the right) */
.form-panel {
  grid-column: 2;
  grid-row: 1;
}

/* Results occupies the left column (column 1 in RTL = visually on the left) */
.results-panel-wrapper {
  grid-column: 1;
  grid-row: 1;
}

/* ── 2. FORM PANEL CARD ───────────────────────────────────── */
.form-panel {
  background-color: var(--color-surface, #FFFFFF);
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
  overflow: hidden;
}

/* ── STICKY SAVE BAR (top of form panel) ─────────────────── */
.form-save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background-color: var(--color-primary, #1E56A0);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.form-save-bar-title {
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.92;
}

.form-save-bar .btn--primary {
  background-color: #fff;
  color: var(--color-primary, #1E56A0);
  border-color: transparent;
  font-weight: 700;
}

.form-save-bar .btn--primary:hover {
  background-color: #e8f0fb;
}

.form-panel-header {
  background-color: var(--color-primary-xlight, #F0F5FC);
  border-bottom: 2px solid var(--color-primary-light, #EBF2FB);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.form-panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary, #1A3A6B);
}

.form-panel-meta {
  font-size: 0.8rem;
  color: var(--color-text-secondary, #6B7280);
}

/* ── 3. FORM SECTIONS (FIELDSETS) ────────────────────────── */
.form-section {
  border: none;
  border-bottom: 1px solid var(--color-border, #E5E7EB);
  padding: 1.25rem 1.5rem;
  margin: 0;
}

.form-section:last-of-type {
  border-bottom: none;
}

.form-section legend,
.form-section-legend {
  display: block;
  width: 100%;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-primary, #1A3A6B);
  padding-bottom: 0.5rem;
  margin-bottom: 0.9rem;
  border-bottom: 2px solid var(--color-primary-light, #EBF2FB);
  letter-spacing: 0.02em;
}

/* ── 4. FIELD ROWS ────────────────────────────────────────── */
.field-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
  align-items: flex-end;
}

.field-row:last-child {
  margin-bottom: 0;
}

/* Individual field wrapper */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1 1 140px;
  min-width: 140px;
}

.field--full {
  flex: 1 1 100%;
  min-width: unset;
}

.field--narrow {
  flex: 0 1 120px;
  min-width: 100px;
}

.field--wide {
  flex: 2 1 220px;
}

/* ── 5. LABELS ────────────────────────────────────────────── */
.field label,
.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.field-label--required::after {
  content: ' *';
  color: var(--color-fail, #DC2626);
  font-weight: 700;
}

/* ── 6. INPUTS & SELECTS ──────────────────────────────────── */
.field input,
.field select,
.field textarea,
.form-input,
.form-select,
.form-textarea {
  border: 1.5px solid var(--color-border-strong, #D1D5DB);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  color: var(--color-text, #1C1C1E);
  background-color: #FFFFFF;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease;
  width: 100%;
  line-height: 1.4;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary-mid, #2C5F9E);
  box-shadow: 0 0 0 3px rgba(44, 95, 158, 0.18);
}

.field input:invalid,
.field select:invalid {
  border-color: var(--color-fail, #DC2626);
}

.field input:invalid:focus,
.field select:invalid:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

/* Disabled inputs */
.field input:disabled,
.field select:disabled,
.field textarea:disabled {
  background-color: #F9FAFB;
  color: var(--color-text-muted, #9CA3AF);
  cursor: not-allowed;
  border-color: var(--color-border, #E5E7EB);
}

/* Number inputs: LTR direction, right-aligned */
.field input[type="number"],
input[type="number"].num-input {
  direction: ltr;
  text-align: right;
}

/* Text inputs: RTL direction, right-aligned */
.field input[type="text"],
.field input[type="search"],
.field textarea {
  direction: rtl;
  text-align: right;
}

/* Select: right-aligned text */
.field select {
  direction: rtl;
  text-align: right;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.65rem center;  /* left in RTL = visually far left */
  padding-left: 2rem;
}

/* ── 7. COMPUTED / READ-ONLY VALUE DISPLAY ────────────────── */
.computed-value {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.45rem 0.65rem;
  background-color: var(--color-primary-xlight, #F0F5FC);
  border: 1.5px solid var(--color-primary-light, #EBF2FB);
  border-radius: 6px;
  color: var(--color-primary, #1A3A6B);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  direction: ltr;
  min-height: 2.2rem;
  font-variant-numeric: tabular-nums;
}

.computed-value--large {
  font-size: 1.1rem;
  padding: 0.6rem 0.85rem;
}

.computed-value.over-limit {
  background-color: var(--color-fail-bg, #FEF2F2);
  border-color: var(--color-fail-border, #FCA5A5);
  color: var(--color-fail, #DC2626);
}

/* ── 8. FIELD HINT TEXT ───────────────────────────────────── */
.field-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted, #9CA3AF);
  line-height: 1.4;
}

.field-hint--error {
  color: var(--color-fail, #DC2626);
}

/* ── 9. CHECKBOX FIELD ────────────────────────────────────── */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text, #1C1C1E);
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  border: 1.5px solid var(--color-border-strong, #D1D5DB);
  border-radius: 4px;
  accent-color: var(--color-primary, #1A3A6B);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── 10. RADIO GROUP ─────────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.radio-label input[type="radio"] {
  accent-color: var(--color-primary, #1A3A6B);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

/* ── 11. FORM ACTIONS BAR ────────────────────────────────── */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border, #E5E7EB);
  background-color: var(--color-surface, #FFFFFF);
  flex-wrap: wrap;
}

/* ── 12. VERSION NOTE TEXTAREA ───────────────────────────── */
.version-note-field {
  width: 100%;
}

.version-note-field textarea {
  width: 100%;
  resize: vertical;
  min-height: 4.5rem; /* ~3 rows */
  max-height: 12rem;
  direction: rtl;
  text-align: right;
}

/* ── 13. PERMIT NUMBER / ID DISPLAY ──────────────────────── */
.permit-id-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background-color: var(--color-bg, #F4F5F7);
  border: 1px solid var(--color-border, #E5E7EB);
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-primary, #1A3A6B);
  direction: ltr;
}

/* ── 14. INLINE STATUS INDICATOR ────────────────────────── */
.field-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.field-status-dot--pass    { background-color: var(--color-pass, #16A34A); }
.field-status-dot--fail    { background-color: var(--color-fail, #DC2626); }
.field-status-dot--warning { background-color: var(--color-warning, #D97706); }

/* ── 15. FORM TOTALS SUMMARY ─────────────────────────────── */
.area-totals {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.area-total-box {
  flex: 1 1 120px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.6rem 0.85rem;
  background-color: var(--color-bg, #F4F5F7);
  border: 1px solid var(--color-border, #E5E7EB);
  border-radius: 6px;
  text-align: center;
}

.area-total-box .label {
  font-size: 0.73rem;
  color: var(--color-text-secondary, #6B7280);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.area-total-box .value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-primary, #1A3A6B);
  direction: ltr;
  font-variant-numeric: tabular-nums;
}

.area-total-box .limit {
  font-size: 0.73rem;
  color: var(--color-text-muted, #9CA3AF);
  direction: ltr;
}

.area-total-box.over-limit {
  background-color: var(--color-fail-bg, #FEF2F2);
  border-color: var(--color-fail-border, #FCA5A5);
}

.area-total-box.over-limit .value {
  color: var(--color-fail, #DC2626);
}

/* ── 16. APPLICANT INFO ──────────────────────────────────── */
.applicant-section .field-row {
  margin-bottom: 0.75rem;
}

/* ── 17. RESPONSIVE: SINGLE COLUMN ──────────────────────── */
@media (max-width: 900px) {
  .permit-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  /* On narrow screens: form goes below results */
  .form-panel {
    grid-column: 1;
    grid-row: 2;
  }

  .results-panel-wrapper {
    grid-column: 1;
    grid-row: 1;
  }
}

@media (max-width: 600px) {
  .form-section {
    padding: 1rem;
  }

  .field-row {
    flex-direction: column;
    gap: 0.65rem;
  }

  .field {
    flex: 1 1 100%;
    min-width: unset;
  }

  .field--narrow,
  .field--wide {
    flex: 1 1 100%;
    min-width: unset;
  }

  .form-actions {
    padding: 0.85rem 1rem;
  }

  .area-totals {
    gap: 0.5rem;
  }
}
