/* =============================================================================
   HAISE Universal Form Styling
   Single source of truth for all form elements across the application
   ============================================================================= */

/* =============================================================================
   Form Inputs - Text, Number, Email, etc.
   ============================================================================= */

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

/* Focus States */
input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 121, 161, 0.1);
  background: var(--bg-secondary);
}

/* Hover States */
input[type="text"]:hover,
input[type="number"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
input[type="search"]:hover,
input[type="tel"]:hover,
input[type="url"]:hover,
input[type="date"]:hover,
input[type="datetime-local"]:hover,
input[type="time"]:hover,
select:hover,
textarea:hover {
  border-color: var(--accent-hover);
}

/* Disabled States */
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-tertiary);
}

/* Read-only States */
input[readonly],
select[readonly],
textarea[readonly] {
  background: var(--bg-tertiary);
  cursor: default;
}

/* Placeholder Styling */
input::placeholder,
textarea::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

/* =============================================================================
   Select Dropdowns
   ============================================================================= */

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0a0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Multiple Select */
select[multiple] {
  padding-right: 14px;
  background-image: none;
  min-height: 120px;
}

/* =============================================================================
   Textarea
   ============================================================================= */

textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
}

textarea.no-resize {
  resize: none;
}

textarea.auto-resize {
  resize: none;
  overflow: hidden;
}

/* =============================================================================
   Labels
   ============================================================================= */

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
}

label.inline {
  display: inline-block;
  margin-right: 16px;
}

label.required::after {
  content: " *";
  color: #dc3545;
}

/* =============================================================================
   Helper Text & Validation Messages
   ============================================================================= */

small.helper-text,
.helper-text,
small.muted {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.helper-text.error,
small.error {
  color: #dc3545;
}

.helper-text.success,
small.success {
  color: #28a745;
}

.helper-text.warning,
small.warning {
  color: #ffc107;
}

/* =============================================================================
   Input States - Validation
   ============================================================================= */

input.error,
select.error,
textarea.error,
input:invalid:not(:focus),
select:invalid:not(:focus),
textarea:invalid:not(:focus) {
  border-color: #dc3545;
}

input.success,
select.success,
textarea.success,
input:valid:not(:placeholder-shown):not(:focus),
select:valid:not(:focus),
textarea:valid:not(:focus) {
  border-color: #28a745;
}

input[required]:focus:invalid,
select[required]:focus:invalid,
textarea[required]:focus:invalid {
  border-color: #dc3545;
  box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

/* =============================================================================
   Buttons - Universal Styling
   ============================================================================= */

button,
.btn,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1.5;
  text-decoration: none;
  box-sizing: border-box;
}

/* Primary Button */
button:not(.secondary):not(.danger):not(.ghost):not(.link):not(.send-btn),
.btn:not(.secondary):not(.danger):not(.ghost):not(.link):not(.send-btn),
input[type="submit"] {
  background: linear-gradient(135deg, #1779a1 0%, #40b9c5 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(23, 121, 161, 0.3);
}

button:not(.secondary):not(.danger):not(.ghost):not(.link):not(.send-btn):hover,
.btn:not(.secondary):not(.danger):not(.ghost):not(.link):not(.send-btn):hover,
input[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(23, 121, 161, 0.4);
}

button:not(.secondary):not(.danger):not(.ghost):not(.link):not(.send-btn):active,
.btn:not(.secondary):not(.danger):not(.ghost):not(.link):not(.send-btn):active,
input[type="submit"]:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(23, 121, 161, 0.3);
}

/* Secondary Button */
button.secondary,
.btn.secondary,
input[type="button"],
input[type="reset"] {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.secondary:hover,
.btn.secondary:hover,
input[type="button"]:hover,
input[type="reset"]:hover {
  background: var(--bg-primary);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* Danger Button */
button.danger,
.btn.danger {
  background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

button.danger:hover,
.btn.danger:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4);
}

/* Ghost Button */
button.ghost,
.btn.ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.ghost:hover,
.btn.ghost:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent);
}

/* Link Button */
button.link,
.btn.link {
  background: transparent;
  color: var(--accent);
  border: none;
  box-shadow: none;
  padding: 4px 8px;
  text-decoration: underline;
}

button.link:hover,
.btn.link:hover {
  color: var(--accent-hover);
  transform: none;
}

/* Button Sizes */
button.small,
.btn.small {
  padding: 6px 12px;
  font-size: 12px;
}

button.large,
.btn.large {
  padding: 14px 28px;
  font-size: 16px;
}

/* Disabled Buttons */
button:disabled,
.btn:disabled,
input[type="button"]:disabled,
input[type="submit"]:disabled,
input[type="reset"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Loading State */
button.loading,
.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

button.loading::after,
.btn.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid white;
  border-top-color: transparent;
  border-radius: 50%;
  animation: button-spin 0.6s linear infinite;
}

@keyframes button-spin {
  to {
    transform: rotate(360deg);
  }
}

/* =============================================================================
   Checkboxes & Radio Buttons
   ============================================================================= */

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  margin-right: 8px;
  cursor: pointer;
  accent-color: var(--accent);
}

label.checkbox-label,
label.radio-label {
  display: flex;
  align-items: center;
  font-weight: 400;
  margin-bottom: 8px;
}

/* =============================================================================
   Form Groups & Layout
   ============================================================================= */

.form-group {
  margin-bottom: 20px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-row {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.form-row > * {
  flex: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* =============================================================================
   Input Groups - Addons & Icons
   ============================================================================= */

.input-group {
  display: flex;
  width: 100%;
}

.input-group input,
.input-group select {
  border-radius: 0;
}

.input-group input:first-child,
.input-group select:first-child {
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}

.input-group input:last-child,
.input-group select:last-child {
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
}

.input-addon {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 14px;
  white-space: nowrap;
}

.input-addon:first-child {
  border-right: none;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}

.input-addon:last-child {
  border-left: none;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
}

/* =============================================================================
   Button Groups
   ============================================================================= */

.button-group {
  display: flex;
  gap: 12px;
}

.button-group.vertical {
  flex-direction: column;
}

.button-group.full-width button,
.button-group.full-width .btn {
  flex: 1;
}

/* =============================================================================
   Search Bars
   ============================================================================= */

.search-bar {
  position: relative;
  width: 100%;
}

.search-bar input {
  padding-left: 38px;
}

.search-bar::before {
  content: "🔍";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  opacity: 0.6;
  pointer-events: none;
}

/* =============================================================================
   Filters & Actions Bar
   ============================================================================= */

.filters-bar {
  display: flex;
  gap: 12px;
  align-items: end;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filters-bar > * {
  flex: 1;
  min-width: 200px;
}

.filters-bar button,
.filters-bar .btn {
  flex: 0 0 auto;
  min-width: auto;
}

/* =============================================================================
   Responsive Adjustments
   ============================================================================= */

@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
  }

  .form-grid,
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }

  .button-group:not(.keep-horizontal) {
    flex-direction: column;
  }

  .filters-bar {
    flex-direction: column;
  }

  .filters-bar > * {
    width: 100%;
    min-width: 100%;
  }
}

/* =============================================================================
   Light Theme Adjustments
   ============================================================================= */

body.light-theme select {
  /*background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");*/
}

body.light-theme select:focus {
  /*background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%231779a1' d='M6 9L1 4h10z'/%3E%3C/svg%3E");*/
}
