/**
 * Modern Form Input Styles
 * Inspired by contemporary UI design patterns
 */

:root {
  --input-bg: #ffffff;
  --input-border: #e2e8f0;
  --input-border-hover: #cbd5e1;
  --input-border-focus: #6366f1;
  --input-border-error: #ef4444;
  --input-text: #1e293b;
  --input-placeholder: #94a3b8;
  --input-disabled-bg: #f8fafc;
  --input-disabled-text: #94a3b8;
  --input-shadow-focus: rgba(99, 102, 241, 0.15);
  --input-shadow-error: rgba(239, 68, 68, 0.15);
  --label-text: #475569;
  --label-text-required: #ef4444;
}

/* Base Input Styles */
.modern-input-wrapper {
  position: relative;
  width: 100%;
}

.modern-input,
.modern-select,
.modern-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.5;
  color: var(--input-text);
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: 12px;
  transition: all 0.2s ease;
  outline: none;
}

/* Override autofill styling */
.modern-input:-webkit-autofill,
.modern-input:-webkit-autofill:hover,
.modern-input:-webkit-autofill:focus,
.modern-input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset !important;
  -webkit-text-fill-color: var(--input-text) !important;
  transition: background-color 5000s ease-in-out 0s;
}

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

/* Hover State */
.modern-input:hover:not(:disabled),
.modern-select:hover:not(:disabled),
.modern-textarea:hover:not(:disabled) {
  border-color: var(--input-border-hover);
  cursor: pointer;
}

/* Focus/Active State */
.modern-input:focus,
.modern-select:focus,
.modern-textarea:focus {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 4px var(--input-shadow-focus), 0 1px 2px rgba(0, 0, 0, 0.05);
  background: var(--input-bg);
}

/* Disabled State */
.modern-input:disabled,
.modern-select:disabled,
.modern-textarea:disabled {
  background: var(--input-disabled-bg);
  color: var(--input-disabled-text);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Error State */
.modern-input.error,
.modern-select.error,
.modern-textarea.error {
  border-color: var(--input-border-error);
}

.modern-input.error:focus,
.modern-select.error:focus,
.modern-textarea.error:focus {
  box-shadow: 0 0 0 4px var(--input-shadow-error), 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Validation State */
.modern-input.validating {
  border-color: #3b82f6;
  background: var(--input-bg);
}

/* Label Styles */
.modern-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--label-text);
  letter-spacing: 0.01em;
}

.modern-label.required::after {
  content: ' *';
  color: var(--label-text-required);
}

/* Search Input */
.modern-input.search {
  padding-left: 2.5rem;
}

.modern-input-wrapper.search::before {
  content: '🔍';
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  opacity: 0.5;
  pointer-events: none;
}

/* Phone Number Input */
.modern-input-phone {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1.5px solid var(--input-border);
  border-radius: 12px;
  background: var(--input-bg);
  transition: all 0.2s ease;
  overflow: hidden;
}

.modern-input-phone:focus-within {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 4px var(--input-shadow-focus), 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modern-input-phone-flag {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.75rem 0.75rem 0.75rem 1rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.25rem;
  transition: background 0.2s ease;
}

.modern-input-phone-flag:hover {
  background: rgba(0, 0, 0, 0.03);
}

.modern-input-phone-flag svg {
  width: 0.75rem;
  height: 0.75rem;
  opacity: 0.5;
}

.modern-input-phone input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0.75rem 1rem 0.75rem 0.5rem;
  font-size: 0.9375rem;
  background: transparent;
}

/* Credit Card Input */
.modern-input-card {
  position: relative;
}

.modern-input-card input {
  padding-right: 3.5rem;
}

.modern-input-card-logo {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  height: 1.5rem;
  pointer-events: none;
}

/* Number Input with Stepper */
.modern-input-stepper {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1.5px solid var(--input-border);
  border-radius: 12px;
  background: var(--input-bg);
  overflow: hidden;
  max-width: 140px;
}

.modern-input-stepper:focus-within {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 4px var(--input-shadow-focus);
}

.modern-input-stepper input {
  flex: 1;
  border: none;
  outline: none;
  text-align: center;
  padding: 0.75rem 0.5rem;
  font-size: 0.9375rem;
  font-weight: 500;
  background: transparent;
  appearance: textfield;
  -moz-appearance: textfield;
}

.modern-input-stepper input::-webkit-outer-spin-button,
.modern-input-stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.modern-input-stepper-controls {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--input-border);
}

.modern-input-stepper-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0 0.625rem;
  color: var(--input-text);
  transition: background 0.15s ease;
}

.modern-input-stepper-btn:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.08);
  color: var(--input-border-focus);
}

/* Global button styles (shared across app) */
.btn,
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger {
  border: none;
  border-radius: 10px;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-primary,
.btn.primary {
  background: var(--accent, #6679ff);
  color: #fff;
  border: 1px solid transparent;
}

.btn-secondary,
.btn.secondary {
  background: var(--surface-subtle, #f6f8fa);
  border: 1px solid var(--border, #e3e6eb);
  color: var(--ink, #111827);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border, #e3e6eb);
  color: var(--ink, #111827);
}

.btn-danger {
  background: var(--danger, #dc2626);
  color: #fff;
  border: 1px solid transparent;
}

.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled,
.btn-danger:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.modern-input-stepper-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.modern-input-stepper-btn:first-child {
  border-bottom: 1px solid var(--input-border);
}

.modern-input-stepper-btn svg {
  width: 0.875rem;
  height: 0.875rem;
}

/* Multi-Select / Chips Input */
.modern-input-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--input-border);
  border-radius: 12px;
  background: var(--input-bg);
  transition: all 0.2s ease;
  cursor: text;
}

.modern-input-chips:focus-within {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 4px var(--input-shadow-focus);
}

.modern-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  background: #6366f1;
  color: #ffffff;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.modern-chip-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0;
  margin-left: 0.125rem;
  opacity: 0.8;
  transition: opacity 0.15s ease;
}

.modern-chip-remove:hover {
  opacity: 1;
}

/* Color Picker Input */
.modern-input-color {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--input-border);
  border-radius: 12px;
  background: var(--input-bg);
  transition: all 0.2s ease;
  cursor: pointer;
}

.modern-input-color:hover {
  border-color: var(--input-border-hover);
}

.modern-input-color:focus-within {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 4px var(--input-shadow-focus);
}

.modern-color-swatch {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.modern-color-swatch input[type="color"] {
  position: absolute;
  inset: -2px;
  width: calc(100% + 4px);
  height: calc(100% + 4px);
  border: none;
  cursor: pointer;
  opacity: 0;
}

.modern-color-picker-icon {
  margin-left: auto;
  opacity: 0.4;
}

/* Password Input */
.modern-input-password {
  position: relative;
}

.modern-input-password input {
  padding-right: 3rem;
  letter-spacing: 0.1em;
}

.modern-input-password input::placeholder {
  letter-spacing: normal;
}

.modern-input-password-toggle {
  position: absolute;
  right: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0.25rem;
  color: var(--input-placeholder);
  transition: color 0.15s ease;
}

.modern-input-password-toggle:hover {
  color: var(--input-text);
}

.modern-password-strength {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.modern-password-strength.weak {
  color: #ef4444;
}

.modern-password-strength.medium {
  color: #f59e0b;
}

.modern-password-strength.strong {
  color: #10b981;
}

/* Textarea */
.modern-textarea {
  resize: vertical;
  min-height: 6rem;
  font-family: inherit;
}

.modern-textarea-counter {
  margin-top: 0.375rem;
  text-align: right;
  font-size: 0.75rem;
  color: var(--input-placeholder);
}

/* Select Dropdown */
.modern-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 0.75rem;
  padding-right: 2.75rem;
  cursor: pointer;
}

/* Date Input */
.modern-input-date {
  position: relative;
}

.modern-input-date input[type="date"],
.modern-input-date input[type="datetime-local"],
.modern-input-date input[type="time"] {
  cursor: pointer;
}

.modern-input-date input[type="date"]::-webkit-calendar-picker-indicator,
.modern-input-date input[type="datetime-local"]::-webkit-calendar-picker-indicator,
.modern-input-date input[type="time"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.modern-input-date input:hover::-webkit-calendar-picker-indicator {
  opacity: 0.8;
}

/* Validation Feedback */
.modern-feedback {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
}

.modern-feedback.error {
  color: var(--input-border-error);
}

.modern-feedback.success {
  color: #10b981;
}

.modern-feedback.validating {
  color: #3b82f6;
}

.modern-feedback-icon {
  width: 1rem;
  height: 1rem;
}

/* Form Groups */
.modern-form-group {
  margin-bottom: 1.5rem;
}

.modern-form-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* Inline Form Elements */
.modern-form-inline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Checkbox & Radio Styles */
.modern-checkbox,
.modern-radio {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
}

.modern-checkbox input[type="checkbox"],
.modern-radio input[type="radio"] {
  width: 1.125rem;
  height: 1.125rem;
  cursor: pointer;
  accent-color: #6366f1;
}

/* Size Variants */
.modern-input-sm,
.modern-select-sm,
.modern-textarea-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 8px;
}

.modern-input-lg,
.modern-select-lg,
.modern-textarea-lg {
  padding: 1rem 1.25rem;
  font-size: 1rem;
  border-radius: 14px;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --input-bg: #1e293b;
    --input-border: #334155;
    --input-border-hover: #475569;
    --input-text: #f1f5f9;
    --input-placeholder: #64748b;
    --input-disabled-bg: #0f172a;
    --label-text: #cbd5e1;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .modern-form-row {
    grid-template-columns: 1fr;
  }
  
  .modern-input-stepper {
    max-width: 100%;
  }
}

/* Permission group header: keep title on one line */
h3 .perm-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.perm-group-title {
  white-space: nowrap;
}
