/* ==========================================================================
   Forms
   ========================================================================== */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4) var(--sp-4); }
.form-grid .span-2 { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field:last-child { margin-bottom: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field label .optional { font-weight: 400; color: var(--text-faint); }
.field .required { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--text-faint); }
.field .error-msg { font-size: 12px; color: var(--danger); display: none; align-items: center; gap: 4px; }
.field.has-error .error-msg { display: flex; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); background: var(--danger-soft); }

.color-picker-row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-swatch-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: var(--radius-md);
  border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 13px; font-family: inherit; color: var(--text-muted);
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.color-swatch-btn:hover { border-color: var(--border-strong); }
.color-swatch { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.color-swatch-btn[data-value="high"] .color-swatch { background: #166534; }
.color-swatch-btn[data-value="medium"] .color-swatch { background: #4ade80; }
.color-swatch-btn[data-value="low"] .color-swatch { background: #dc2626; }
.color-swatch-btn[data-value="high"].selected { border-color: #166534; background: var(--success-soft); color: var(--text); font-weight: 600; }
.color-swatch-btn[data-value="medium"].selected { border-color: #4ade80; background: var(--success-soft); color: var(--text); font-weight: 600; }
.color-swatch-btn[data-value="low"].selected { border-color: #dc2626; background: var(--danger-soft); color: var(--text); font-weight: 600; }

.input, .textarea, .select-field2 {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus, .textarea:focus, .select-field2:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.textarea { resize: vertical; min-height: 80px; }

.select-field2 {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239297ab' stroke-width='1.5' fill='none' fill-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 40px; }
.input-group-icon {
  position: absolute; right: 4px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text-faint); cursor: pointer;
  border-radius: var(--radius-sm);
}

/* ---------- Lead picker (searchable "Lead Name" combobox) ---------- */
.lead-picker-input-row { position: relative; }
.lead-picker-panel {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
  max-height: 240px; overflow-y: auto;
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity var(--transition), visibility var(--transition), transform var(--transition);
}
.lead-picker-panel.open { opacity: 1; visibility: visible; transform: translateY(0); }
.lead-picker-option { padding: 8px 12px; cursor: pointer; }
.lead-picker-option:hover { background: var(--primary-soft); }
.lead-picker-option .lp-name { font-size: 13px; font-weight: 600; color: var(--text); }
.lead-picker-option .lp-company { font-size: 12px; color: var(--text-faint); }
.lead-picker-empty { padding: 10px 12px; font-size: 12px; color: var(--text-faint); }
.lead-picker-manual-toggle {
  display: flex; align-items: center; gap: 6px; margin-top: 8px; white-space: nowrap;
  font-size: 12px; color: var(--text-muted); cursor: pointer;
}
.lead-picker-manual-toggle input { cursor: pointer; }
.input-group-icon:hover { color: var(--text); background: var(--surface-hover); }
.input-group-icon svg { width: 17px; height: 17px; }

.input-prefix { position: absolute; left: 12px; color: var(--text-faint); font-size: 13px; pointer-events: none; }
.input-with-prefix { padding-left: 30px; }

/* Checkbox / radio */
.checkbox-row, .radio-row { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.checkbox-row input, .radio-row input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.checkbox-row span, .radio-row span { font-size: 13px; }

/* Expense category radio selector in modal */
.expense-category-radios {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
  margin-top: 6px;
}
.category-radio-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1.5px solid var(--border-strong, #cbd5e1);
  border-radius: 6px;
  background: var(--surface, #fff);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
  user-select: none;
}
.category-radio-card:hover {
  border-color: var(--primary, #9c1d2e);
  background: var(--surface-hover, #f8fafc);
}
.category-radio-card.has-checked {
  border-color: var(--primary, #9c1d2e);
  background: rgba(156, 29, 46, 0.08);
  color: var(--primary, #9c1d2e);
  font-weight: 600;
}
.category-radio-card.primary-opt {
  border-color: var(--primary, #9c1d2e);
  background: rgba(156, 29, 46, 0.03);
}
.category-radio-card input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary, #9c1d2e);
  cursor: pointer;
  margin: 0;
  flex-shrink: 0;
}

/* Expense filter radio pills on the expenses list page */
.expense-filter-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.filter-radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border-strong, #cbd5e1);
  background: var(--surface, #fff);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
  user-select: none;
}
.filter-radio-pill:hover {
  border-color: var(--primary, #9c1d2e);
  background: var(--surface-hover, #f8fafc);
}
.filter-radio-pill.has-checked {
  border-color: var(--primary, #9c1d2e);
  background: var(--primary, #9c1d2e);
  color: #fff;
  font-weight: 600;
}
.filter-radio-pill input[type="radio"] {
  display: none;
}

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border-strong); border-radius: var(--radius-pill);
  transition: background var(--transition);
}
.switch .slider::before {
  content: ""; position: absolute; width: 16px; height: 16px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-xs);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: none; }
.switch-row-label { font-size: 13px; font-weight: 600; }
.switch-row-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* File upload */
.upload-box {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--sp-6);
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.upload-box:hover { border-color: var(--primary); background: var(--primary-soft); }
.upload-box svg { width: 26px; height: 26px; margin: 0 auto var(--sp-2); color: var(--text-faint); }
.upload-box .upload-title { font-size: 13px; font-weight: 600; color: var(--text); }
.upload-box .upload-sub { font-size: 12px; margin-top: 2px; }
.upload-file-chip {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 8px 12px; font-size: 12px; margin-top: var(--sp-2);
}
.upload-file-chip svg { width: 15px; height: 15px; color: var(--text-muted); }
.upload-file-chip button { margin-left: auto; background: none; border: none; color: var(--text-faint); cursor: pointer; }

/* Line item table (quotation/invoice builder) */
.line-items { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.line-items table { width: 100%; border-collapse: collapse; }
.line-items th {
  background: var(--surface-2); text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); padding: 10px 12px; font-weight: 700;
}
.line-items td { padding: 8px; border-top: 1px solid var(--border); vertical-align: top; }
.line-items input { border: 1px solid transparent; background: transparent; width: 100%; padding: 7px 8px; border-radius: 6px; font-size: 13px; }
.line-items input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.line-items .remove-row-btn { background: none; border: none; color: var(--text-faint); cursor: pointer; padding: 6px; }
.line-items .remove-row-btn:hover { color: var(--danger); }
.line-items tfoot td { border-top: 1px solid var(--border); background: var(--surface-2); }

.totals-box { margin-left: auto; width: 280px; margin-top: var(--sp-4); }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; color: var(--text-muted); }
.totals-row.grand { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-size: var(--fs-md); font-weight: 700; color: var(--text); }

.add-row-btn {
  display: flex; align-items: center; gap: 6px;
  padding: var(--sp-3); font-size: 13px; font-weight: 600; color: var(--primary);
  cursor: pointer; border-top: 1px solid var(--border); background: var(--surface);
}
.add-row-btn:hover { background: var(--primary-soft); }
.add-row-btn svg { width: 15px; height: 15px; }
