/* ══════════════════════════════════════════════════════════════
   DeksAir — Enhanced Form Components
   Inspired by Ant Design / Shadcn-UI / Headless UI
   ══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
  --input-h: 38px;
  --input-h-sm: 32px;
  --input-radius: 8px;
  --input-border: #d1d5db;
  --input-border-hover: #9ca3af;
  --input-border-focus: #3b82f6;
  --input-bg: #fff;
  --input-bg-hover: #fafbfc;
  --input-ring: rgba(59, 130, 246, 0.15);
  --input-placeholder: #9ca3af;
  --input-disabled-bg: #f3f4f6;
  --input-disabled-text: #9ca3af;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.dark {
  --input-border: #4b5563;
  --input-border-hover: #6b7280;
  --input-border-focus: #60a5fa;
  --input-bg: #1f2937;
  --input-bg-hover: #263040;
  --input-ring: rgba(96, 165, 250, 0.18);
  --input-placeholder: #6b7280;
  --input-disabled-bg: #374151;
  --input-disabled-text: #6b7280;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
}


/* ══════════════════════════════════════════════════
   TEXT INPUTS, NUMBER, EMAIL, TEL, SEARCH, PASSWORD
   ══════════════════════════════════════════════════ */

input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="search"],
input[type="password"],
input[type="url"],
textarea {
  height: var(--input-h);
  border-radius: var(--input-radius) !important;
  border: 1px solid var(--input-border) !important;
  background-color: var(--input-bg);
  color: inherit;
  font-size: 13px;
  transition: border-color 0.2s ease,
              box-shadow 0.2s ease,
              background-color 0.15s ease;
  outline: none !important;
  -webkit-appearance: none;
}

/* Default padding — only when no Tailwind padding class is present.
   Uses :where() for zero specificity so pl-9, pr-3 etc. always win. */
:where(input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="search"],
input[type="password"],
input[type="url"],
textarea) {
  padding: 0 12px;
}

textarea {
  height: auto;
  padding: 8px 12px;
  min-height: 60px;
}

/* Hover */
input[type="text"]:hover:not(:focus):not(:disabled):not([readonly]),
input[type="number"]:hover:not(:focus):not(:disabled):not([readonly]),
input[type="email"]:hover:not(:focus):not(:disabled):not([readonly]),
input[type="tel"]:hover:not(:focus):not(:disabled):not([readonly]),
input[type="search"]:hover:not(:focus):not(:disabled):not([readonly]),
input[type="password"]:hover:not(:focus):not(:disabled):not([readonly]),
input[type="url"]:hover:not(:focus):not(:disabled):not([readonly]),
textarea:hover:not(:focus):not(:disabled):not([readonly]) {
  border-color: var(--input-border-hover) !important;
  background-color: var(--input-bg-hover);
}

/* Focus */
input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="search"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
textarea:focus {
  border-color: var(--input-border-focus) !important;
  box-shadow: 0 0 0 3px var(--input-ring) !important;
  background-color: var(--input-bg) !important;
}

/* Placeholder */
input::placeholder,
textarea::placeholder {
  color: var(--input-placeholder);
  opacity: 1;
  font-weight: 400;
}

/* Disabled / Readonly */
input:disabled,
input[readonly],
textarea:disabled,
textarea[readonly] {
  background-color: var(--input-disabled-bg) !important;
  color: var(--input-disabled-text) !important;
  cursor: not-allowed;
  opacity: 0.75;
  border-color: var(--input-border) !important;
  box-shadow: none !important;
}

/* Invalid */
input:invalid:not(:placeholder-shown):not(:focus) {
  border-color: #ef4444 !important;
}


/* ══════════════════════════════════════════════════
   SELECT
   ══════════════════════════════════════════════════ */

select {
  height: var(--input-h);
  border-radius: var(--input-radius) !important;
  border: 1px solid var(--input-border) !important;
  background-color: var(--input-bg);
  color: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s ease,
              box-shadow 0.2s ease,
              background-color 0.15s ease;
  outline: none !important;
  /* Custom arrow */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}

:where(select) {
  padding: 0 36px 0 12px;
}

/* Hover */
select:hover:not(:focus):not(:disabled) {
  border-color: var(--input-border-hover) !important;
  background-color: var(--input-bg-hover);
}

/* Focus */
select:focus {
  border-color: var(--input-border-focus) !important;
  box-shadow: 0 0 0 3px var(--input-ring) !important;
  background-color: var(--input-bg) !important;
}

/* Disabled */
select:disabled {
  background-color: var(--input-disabled-bg) !important;
  color: var(--input-disabled-text) !important;
  cursor: not-allowed;
  opacity: 0.75;
  border-color: var(--input-border) !important;
  box-shadow: none !important;
}


/* ══════════════════════════════════════════════════
   CUSTOM SELECT (cs-*) — replaces native dropdown
   ══════════════════════════════════════════════════ */

.cs-wrapper {
  display: inline-flex;
  position: relative;
  flex-shrink: 0;
}

/* ── Trigger button ── */
.cs-trigger {
  height: var(--input-h) !important;
  border-radius: var(--input-radius) !important;
  border: 1px solid var(--input-border) !important;
  background-color: var(--input-bg) !important;
  color: inherit !important;
  font-size: 13px !important;
  cursor: pointer !important;
  transition: border-color 0.2s ease,
              box-shadow 0.2s ease,
              background-color 0.15s ease;
  outline: none !important;
  padding: 0 32px 0 12px !important;
  text-align: left !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex !important;
  align-items: center;
  gap: 4px;
  position: relative;
  line-height: 1;
}

.cs-trigger:hover:not(.cs-disabled) {
  border-color: var(--input-border-hover) !important;
  background-color: var(--input-bg-hover) !important;
}

.cs-trigger:focus:not(.cs-disabled) {
  border-color: var(--input-border-focus) !important;
  box-shadow: 0 0 0 3px var(--input-ring) !important;
  background-color: var(--input-bg) !important;
}

.cs-trigger.cs-open {
  border-color: var(--input-border-focus) !important;
  box-shadow: 0 0 0 3px var(--input-ring) !important;
}

.cs-trigger.cs-disabled {
  background-color: var(--input-disabled-bg) !important;
  color: var(--input-disabled-text) !important;
  cursor: not-allowed;
  opacity: 0.75;
  border-color: var(--input-border) !important;
  box-shadow: none !important;
}

.cs-trigger.cs-placeholder {
  color: var(--input-placeholder) !important;
}

/* Modal selects — slightly larger */
.fixed .cs-trigger {
  height: 40px;
  font-size: 14px;
}

/* ── Arrow icon ── */
.cs-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  color: #6b7280;
  transition: transform 0.2s ease;
  pointer-events: none;
  flex-shrink: 0;
}

.cs-trigger.cs-open .cs-arrow {
  transform: translateY(-50%) rotate(180deg);
}

.dark .cs-arrow {
  color: #9ca3af;
}

/* ── Dropdown panel ── */
.cs-dropdown {
  position: absolute !important;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-width: 340px;
  background: #fff !important;
  border: 1px solid #e5e7eb !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1),
              0 2px 8px rgba(0, 0, 0, 0.06) !important;
  z-index: 9999;
  overflow: hidden;
  /* Animation */
  animation: cs-slide-down 0.15s ease-out;
}

.cs-dropdown.cs-above {
  top: auto;
  bottom: calc(100% + 4px);
  animation: cs-slide-up 0.15s ease-out;
}

.dark .cs-dropdown {
  background: #1f2937 !important;
  border-color: #374151 !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35),
              0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

@keyframes cs-slide-down {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes cs-slide-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Search input inside dropdown ── */
.cs-search {
  width: 100%;
  height: 36px !important;
  border: none !important;
  border-bottom: 1px solid #e5e7eb !important;
  border-radius: 0 !important;
  padding: 0 12px !important;
  font-size: 13px;
  background: transparent !important;
  color: inherit;
  outline: none !important;
  box-shadow: none !important;
}

.cs-search:focus {
  border-bottom-color: var(--input-border-focus) !important;
  box-shadow: none !important;
}

.dark .cs-search {
  border-bottom-color: #374151 !important;
}

.dark .cs-search:focus {
  border-bottom-color: #60a5fa !important;
}

.cs-search::placeholder {
  color: var(--input-placeholder);
  font-weight: 400;
}

/* ── Options container ── */
.cs-options {
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}

/* ── Individual option ── */
.cs-option {
  padding: 7px 10px !important;
  font-size: 13px !important;
  cursor: pointer !important;
  border-radius: 6px !important;
  transition: background-color 0.1s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
  user-select: none;
  background: transparent;
}

.cs-option:hover,
.cs-option.cs-focused {
  background-color: #f3f4f6 !important;
}

.dark .cs-option:hover,
.dark .cs-option.cs-focused {
  background-color: #374151 !important;
}

.cs-option.cs-selected {
  background-color: #eff6ff !important;
  color: #1d4ed8 !important;
  font-weight: 500;
}

.dark .cs-option.cs-selected {
  background-color: rgba(59, 130, 246, 0.15) !important;
  color: #93bbfd !important;
}

.cs-option.cs-selected.cs-focused,
.cs-option.cs-selected:hover {
  background-color: #dbeafe !important;
}

.dark .cs-option.cs-selected.cs-focused,
.dark .cs-option.cs-selected:hover {
  background-color: rgba(59, 130, 246, 0.25) !important;
}

.cs-option.cs-placeholder-opt {
  color: var(--input-placeholder) !important;
  font-style: italic;
}


/* ══════════════════════════════════════════════════
   DATE / DATETIME INPUTS
   ══════════════════════════════════════════════════ */

/* Custom calendar icon (SVG encoded) — used as left-side background */
:root {
  --date-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z' clip-rule='evenodd'/%3E%3C/svg%3E");
  --time-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.dark {
  --date-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z' clip-rule='evenodd'/%3E%3C/svg%3E");
  --time-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

input[type="date"],
input[type="datetime-local"],
input[type="month"],
input[type="week"] {
  height: var(--input-h);
  border-radius: var(--input-radius) !important;
  border: 1px solid var(--input-border) !important;
  background-color: var(--input-bg);
  color: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: border-color 0.2s ease,
              box-shadow 0.2s ease,
              background-color 0.15s ease;
  outline: none !important;
  -webkit-appearance: none;
  /* Calendar icon on the left */
  background-image: var(--date-icon);
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 16px;
}

input[type="time"] {
  height: var(--input-h);
  border-radius: var(--input-radius) !important;
  border: 1px solid var(--input-border) !important;
  background-color: var(--input-bg);
  color: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: border-color 0.2s ease,
              box-shadow 0.2s ease,
              background-color 0.15s ease;
  outline: none !important;
  -webkit-appearance: none;
  /* Clock icon on the left */
  background-image: var(--time-icon);
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 16px;
}

/* Left padding to make room for the icon */
:where(input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"]) {
  padding: 0 12px 0 34px;
}

/* Hover */
input[type="date"]:hover:not(:focus):not(:disabled),
input[type="datetime-local"]:hover:not(:focus):not(:disabled),
input[type="time"]:hover:not(:focus):not(:disabled),
input[type="month"]:hover:not(:focus):not(:disabled),
input[type="week"]:hover:not(:focus):not(:disabled) {
  border-color: var(--input-border-hover) !important;
  background-color: var(--input-bg-hover);
}

/* Focus */
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
input[type="month"]:focus,
input[type="week"]:focus {
  border-color: var(--input-border-focus) !important;
  box-shadow: 0 0 0 3px var(--input-ring) !important;
  background-color: var(--input-bg) !important;
}

/* Disabled */
input[type="date"]:disabled,
input[type="datetime-local"]:disabled,
input[type="time"]:disabled {
  background-color: var(--input-disabled-bg) !important;
  color: var(--input-disabled-text) !important;
  cursor: not-allowed;
  opacity: 0.75;
  border-color: var(--input-border) !important;
  box-shadow: none !important;
}

/* Calendar picker indicator (Webkit) — keep on the right as a clickable area */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0;
  width: 20px;
  height: 20px;
  padding: 0;
  margin: 0;
  position: absolute;
  right: 8px;
}

/* Date text segments (Webkit) — better spacing */
input[type="date"]::-webkit-datetime-edit,
input[type="datetime-local"]::-webkit-datetime-edit,
input[type="time"]::-webkit-datetime-edit {
  display: flex;
  align-items: center;
  padding: 0;
}

input[type="date"]::-webkit-datetime-edit-fields-wrapper,
input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper,
input[type="time"]::-webkit-datetime-edit-fields-wrapper {
  padding: 0;
}

/* Placeholder text when no date is selected */
input[type="date"]:not(:valid):not(:focus)::before,
input[type="datetime-local"]:not(:valid):not(:focus)::before {
  color: var(--input-placeholder);
  font-weight: 400;
}

/* Inner shadow highlight for depth when focused */
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus {
  box-shadow: 0 0 0 3px var(--input-ring),
              inset 0 1px 2px rgba(59, 130, 246, 0.06) !important;
}


/* ══════════════════════════════════════════════════
   CHECKBOXES
   Skip .sr-only checkboxes (used with custom visual spans)
   ══════════════════════════════════════════════════ */

input[type="checkbox"]:not(.sr-only):not(.peer) {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--input-border);
  background-color: var(--input-bg);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  vertical-align: middle;
  flex-shrink: 0;
}

input[type="checkbox"]:not(.sr-only):not(.peer):hover:not(:disabled) {
  border-color: var(--input-border-focus);
}

input[type="checkbox"]:not(.sr-only):not(.peer):focus {
  box-shadow: 0 0 0 3px var(--input-ring);
  border-color: var(--input-border-focus);
}

input[type="checkbox"]:not(.sr-only):not(.peer):checked {
  background-color: #1a3a6b;
  border-color: #1a3a6b;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='white'%3E%3Cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3E%3C/svg%3E");
  background-size: 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.dark input[type="checkbox"]:not(.sr-only):not(.peer):checked {
  background-color: #3b82f6;
  border-color: #3b82f6;
}

input[type="checkbox"]:not(.sr-only):not(.peer):disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


/* ══════════════════════════════════════════════════
   COMPACT (TABLE INLINE) INPUTS
   ══════════════════════════════════════════════════ */

/* Smaller inputs inside table cells */
table input[type="text"],
table input[type="number"],
table select {
  height: var(--input-h-sm);
  font-size: 12px;
  border-radius: 6px !important;
}

:where(table input[type="text"],
table input[type="number"]) {
  padding: 0 8px;
}

:where(table select) {
  padding: 0 28px 0 8px;
}

table select {
  background-position: right 6px center;
  background-size: 14px;
}

/* Compact date inputs inside table cells */
table input[type="date"],
table input[type="datetime-local"],
table input[type="time"] {
  height: var(--input-h-sm);
  font-size: 12px;
  border-radius: 6px !important;
  background-size: 14px;
  background-position: 8px center;
}

:where(table input[type="date"],
table input[type="datetime-local"],
table input[type="time"]) {
  padding: 0 8px 0 28px;
}


/* ══════════════════════════════════════════════════
   LABELS (above form fields)
   ══════════════════════════════════════════════════ */

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #4b5563;
  margin-bottom: 4px;
  letter-spacing: 0.01em;
  user-select: none;
}

.dark label {
  color: #9ca3af;
}


/* ══════════════════════════════════════════════════
   MODAL FORM FIELDS — slightly larger
   ══════════════════════════════════════════════════ */

.fixed input[type="text"],
.fixed input[type="number"],
.fixed input[type="email"],
.fixed input[type="date"],
.fixed input[type="datetime-local"],
.fixed input[type="time"],
.fixed select,
.fixed textarea {
  height: 40px;
  font-size: 14px;
}

/* Slightly larger icon for modal date inputs */
.fixed input[type="date"],
.fixed input[type="datetime-local"],
.fixed input[type="time"] {
  background-size: 18px;
  padding-left: 36px;
}

.fixed textarea {
  height: auto;
  min-height: 68px;
}


/* ══════════════════════════════════════════════════
   BUTTON IMPROVEMENTS
   ══════════════════════════════════════════════════ */

button {
  transition: all 0.15s ease;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}


/* ══════════════════════════════════════════════════
   SCROLLBAR (modern thin scrollbar)
   ══════════════════════════════════════════════════ */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.dark ::-webkit-scrollbar-thumb {
  background: #475569;
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.dark * {
  scrollbar-color: #475569 transparent;
}


/* ══════════════════════════════════════════════════
   FOCUS-VISIBLE (keyboard only focus ring)
   ══════════════════════════════════════════════════ */

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
}


/* ══════════════════════════════════════════════════
   TRANSITIONS & MICRO-INTERACTIONS
   ══════════════════════════════════════════════════ */

/* Smooth table row transitions */
tbody tr {
  transition: background-color 0.12s ease;
}

/* Toast animation */
.toast-fade {
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

/* Modal backdrop */
.fixed[class*="bg-black"] {
  backdrop-filter: blur(3px);
}
