/* ============================================================
   Nixus — Professional Invoicing Platform
   File: static/css/forms.css
   Purpose: Form controls (inputs, labels, selects, validation)
   Author: Nixus Team
   License: MIT
   ============================================================ */

/* ============================================================
   1. FORM CONTAINER
   ============================================================ */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.form-card {
  background: linear-gradient(180deg, var(--bg-elev-2), var(--bg-elev-1));
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.form-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.form-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-section-title::before {
  content: "";
  width: 3px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--accent-glow);
}

.form-section-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: -4px;
  margin-bottom: var(--space-2);
}


/* ============================================================
   2. FORM ROW / GRID
   ============================================================ */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

@media (max-width: 640px) {
  .form-row-2,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}


/* ============================================================
   3. FORM GROUP / LABEL
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: -0.01em;
}

.form-label .required {
  color: var(--danger);
  margin-left: 2px;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
}

.form-error {
  font-size: 0.75rem;
  color: var(--danger);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-error svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}


/* ============================================================
   4. INPUTS / TEXTAREA / SELECT
   ============================================================ */
.input,
.textarea,
.select {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-elev-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--border-strong);
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--accent);
  background: var(--bg-elev-3);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-disabled);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-elev-1);
}

.input:read-only {
  background: var(--bg-elev-1);
  color: var(--text-secondary);
  cursor: default;
}

.textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.55;
  font-family: var(--font-sans);
}

.textarea-lg { min-height: 160px; }

.select {
  padding-right: 36px;
  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='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

.select option {
  background: var(--bg-elev-3);
  color: var(--text-primary);
}

.select optgroup {
  background: var(--bg-elev-4);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  padding: 4px 8px;
}


/* ============================================================
   5. INPUT SIZES
   ============================================================ */
.input-sm { padding: 6px 10px; font-size: 0.8rem; }
.input-lg { padding: 14px 18px; font-size: 1rem; }

.input-mono {
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.input-number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.input-search {
  padding-left: 40px;
  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='%23737373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='M21 21l-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px center;
}


/* ============================================================
   6. INPUT GROUP (prefix/suffix)
   ============================================================ */
.input-group {
  display: flex;
  align-items: stretch;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  overflow: hidden;
}

.input-group:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-group .input {
  border: 0;
  background: transparent;
  box-shadow: none !important;
  border-radius: 0;
}

.input-group-addon {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: var(--bg-elev-3);
  border-right: 1px solid var(--border-default);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.input-group-addon:last-child {
  border-right: 0;
  border-left: 1px solid var(--border-default);
}

.input-group-addon.accent { color: var(--accent); }


/* ============================================================
   7. CHECKBOX / RADIO
   ============================================================ */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.check input[type="checkbox"],
.check input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  margin-top: 1px;
  flex-shrink: 0;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
}

.check input[type="radio"] {
  border-radius: 50%;
}

.check input:hover {
  border-color: var(--text-muted);
}

.check input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.check input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 6px;
  height: 11px;
  border: solid var(--text-inverse);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.check input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-inverse);
  transform: translate(-50%, -50%);
}

.check input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.check input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.check-label {
  flex: 1;
  cursor: pointer;
}

.check-label a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}


/* ============================================================
   8. SWITCH / TOGGLE
   ============================================================ */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--bg-elev-4);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.switch input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .switch-track::after {
  left: 20px;
  background: var(--text-inverse);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch input:disabled + .switch-track {
  opacity: 0.5;
  cursor: not-allowed;
}

.switch-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}


/* ============================================================
   9. PASSWORD FIELD
   ============================================================ */
.password-wrap {
  position: relative;
}

.password-wrap .input {
  padding-right: 42px;
}

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.password-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-elev-4);
}

.password-toggle svg { width: 16px; height: 16px; }


/* Password strength meter */
.password-strength {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.password-strength-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-elev-4);
  border-radius: 999px;
  transition: background var(--transition-fast);
}

.password-strength-bar.active-weak { background: var(--danger); }
.password-strength-bar.active-fair { background: var(--warning); }
.password-strength-bar.active-good { background: var(--info); }
.password-strength-bar.active-strong { background: var(--success); }

.password-strength-text {
  font-size: 0.75rem;
  margin-top: 6px;
  color: var(--text-muted);
}


/* ============================================================
   10. VALIDATION STATES
   ============================================================ */
.input.is-valid,
.textarea.is-valid,
.select.is-valid {
  border-color: var(--success);
}

.input.is-valid:focus,
.textarea.is-valid:focus,
.select.is-valid:focus {
  box-shadow: 0 0 0 3px rgba(0, 255, 157, 0.15);
}

.input.is-invalid,
.textarea.is-invalid,
.select.is-invalid {
  border-color: var(--danger);
}

.input.is-invalid:focus,
.textarea.is-invalid:focus,
.select.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(255, 92, 92, 0.15);
}

.input-error-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--danger);
  pointer-events: none;
  width: 16px;
  height: 16px;
}


/* ============================================================
   11. FORM ACTIONS
   ============================================================ */
.form-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-5);
  flex-wrap: wrap;
}

.form-actions-left {
  margin-right: auto;
}

.form-actions.sticky {
  position: sticky;
  bottom: 0;
  background: var(--bg-base);
  padding: var(--space-4) var(--space-6);
  margin: 0 calc(-1 * var(--space-6));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 10;
}


/* ============================================================
   12. INLINE FORM
   ============================================================ */
.form-inline {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-inline .form-group {
  flex: 1;
  min-width: 160px;
}


/* ============================================================
   13. SEARCH BAR
   ============================================================ */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.search-bar .input-search {
  flex: 1;
  min-width: 200px;
}

.search-bar-filters {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-elev-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.filter-chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.filter-chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.filter-chip-remove {
  width: 14px;
  height: 14px;
  margin-left: 2px;
  opacity: 0.6;
}
.filter-chip-remove:hover { opacity: 1; }


/* ============================================================
   14. FILE UPLOAD
   ============================================================ */
.file-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-6);
  background: var(--bg-elev-2);
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.file-drop:hover,
.file-drop.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-drop-icon {
  width: 44px;
  height: 44px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.file-drop:hover .file-drop-icon { color: var(--accent); }

.file-drop-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.file-drop-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-preview {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--bg-elev-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  margin-top: var(--space-3);
}

.file-preview-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg-elev-4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.file-preview-info { flex: 1; min-width: 0; }
.file-preview-name {
  font-size: 0.875rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-preview-size { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

.file-preview-remove {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.file-preview-remove:hover { background: var(--danger-bg); color: var(--danger); }


/* ============================================================
   15. AUTOCOMPLETE / COMBOBOX
   ============================================================ */
.autocomplete {
  position: relative;
}

.autocomplete-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg-elev-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  z-index: 50;
  display: none;
}

.autocomplete.open .autocomplete-menu { display: block; }

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--bg-elev-4);
  color: var(--text-primary);
}

.autocomplete-empty {
  padding: 12px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}


/* ============================================================
   16. FORM GRID (invoice line items)
   ============================================================ */
.line-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.line-item {
  display: grid;
  grid-template-columns: 1fr 100px 130px 130px 40px;
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-2);
  background: var(--bg-elev-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
}

.line-item:hover { border-color: var(--border-default); }

.line-item .input {
  background: var(--bg-elev-1);
}

.line-item-total {
  font-size: 0.875rem;
  font-weight: 600;
  text-align: right;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  padding-right: var(--space-2);
}

.line-item-remove {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.line-item-remove:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

@media (max-width: 768px) {
  .line-item {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "desc desc"
      "qty price"
      "total remove";
  }
  .line-item .line-desc { grid-area: desc; }
  .line-item .line-qty { grid-area: qty; }
  .line-item .line-price { grid-area: price; }
  .line-item .line-total { grid-area: total; }
  .line-item .line-remove { grid-area: remove; }
}


/* ============================================================
   17. RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
  .form-card { padding: var(--space-4); }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
  .form-actions-left { margin-right: 0; }
  .input-group { flex-wrap: wrap; }
}