/* ==========================================================================
   UI component kit — plain CSS, no Tailwind/build step required.
   Backs the Phoenix.UI TagHelpers (text-field, select, checkbox, radio-group, button, dropdown).
   ========================================================================== */

:root {
  --ui-border: #cbd5e1;      /* slate-300 */
  --ui-border-hover: #94a3b8;/* slate-400 */
  --ui-text: #0f172a;        /* slate-900 */
  --ui-label: #334155;       /* slate-700 */
  --ui-helper: #64748b;      /* slate-500 */
  --ui-error: #e11d48;       /* rose-600 */
  --ui-error-bg: #fda4af40;  /* rose-400 @ 25% */
  --ui-accent: #4f46e5;      /* indigo-600 */
  --ui-accent-hover: #4338ca;/* indigo-700 */
  --ui-accent-active: #3730a3;/* indigo-800 */
  --ui-ring: #6366f14d;      /* indigo-500 @ 30% */
  --ui-blue: #2563eb;        /* blue-600 */
  --ui-blue-hover: #1d4ed8;  /* blue-700 */
  --ui-blue-active: #1e40af; /* blue-800 */
  --ui-radius: 8px;
  --ui-disabled-bg: #f8fafc; /* slate-50 */
  --ui-disabled-text: #94a3b8;
}

.ui-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 2px;
}

.ui-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--ui-label);
}

.ui-required {
  color: var(--ui-error);
  margin-left: 2px;
}

.ui-input,
.ui-select {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--ui-text);
  background: #fff;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
}

.ui-input:hover,
.ui-select:hover {
  border-color: var(--ui-border-hover);
}

.ui-input:focus,
.ui-select:focus {
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px var(--ui-ring);
}

.ui-input:disabled,
.ui-select:disabled {
  background: var(--ui-disabled-bg);
  color: var(--ui-disabled-text);
  cursor: not-allowed;
}

.ui-field.has-error .ui-input,
.ui-field.has-error .ui-select {
  border-color: var(--ui-error);
}

.ui-field.has-error .ui-input:focus,
.ui-field.has-error .ui-select:focus {
  box-shadow: 0 0 0 3px var(--ui-error-bg);
}

.ui-helper {
  font-size: 12px;
  color: var(--ui-helper);
}

.ui-field.has-error .ui-helper {
  color: var(--ui-error);
}

/* Field box: wraps .ui-input when a text-field has a leading icon and/or (for
   password fields) a show/hide toggle button. See TextFieldTagHelper. */
.ui-field-box {
  position: relative;
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.ui-field-box:hover {
  border-color: var(--ui-border-hover);
}

.ui-field-box:focus-within {
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px var(--ui-ring);
}

.ui-field-box .ui-input {
  border: none;
  background: transparent;
  flex: 1;
  min-width: 0;
}

.ui-field-box .ui-input:focus {
  box-shadow: none;
}

.ui-field-icon {
  width: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-accent);
  font-size: 14px;
}

.ui-field-toggle {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-helper);
  font-size: 14px;
  transition: color 0.15s ease;
}

.ui-field-toggle:hover {
  color: var(--ui-accent);
}

.ui-field.has-error .ui-field-box {
  border-color: var(--ui-error);
}

.ui-field.has-error .ui-field-box:focus-within {
  box-shadow: 0 0 0 3px var(--ui-error-bg);
}

/* Select wrapper (native <select> + chevron) */
.ui-select-wrap {
  position: relative;
}

.ui-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
}

.ui-select-chevron {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: #94a3b8;
  font-size: 12px;
}

/* Checkbox */
.ui-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ui-text);
  cursor: pointer;
}

.ui-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin: 0;
  border: 1.5px solid var(--ui-border);
  border-radius: 4px;
  background-color: #fff;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.ui-checkbox input[type="checkbox"]:hover {
  border-color: var(--ui-border-hover);
}

.ui-checkbox input[type="checkbox"]:checked {
  background-color: var(--ui-accent);
  border-color: var(--ui-accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3.5 8.3 6.5 11.3 12.5 4.7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 11px;
}

.ui-checkbox input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ui-ring);
}

.ui-checkbox input:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Radio group */
.ui-radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.ui-radio-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ui-text);
  cursor: pointer;
}

.ui-radio-option input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--ui-accent);
  cursor: pointer;
}

/* Button — GM.UI.ui-link shares these styles so a link looks like a button */
.ui-btn,
.ui-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 500;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: var(--ui-radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
  text-decoration: none;
}

.ui-btn:disabled,
.ui-link[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.ui-btn:focus-visible,
.ui-link:focus-visible {
  box-shadow: 0 0 0 3px var(--ui-ring);
  outline: none;
}

.ui-btn-primary,
.ui-link-primary {
  background: var(--ui-accent);
  color: #fff;
}
.ui-btn-primary:hover:not(:disabled),
.ui-link-primary:hover {
  background: var(--ui-accent-hover);
  color: #fff;
}
.ui-btn-primary:active:not(:disabled),
.ui-link-primary:active {
  background: var(--ui-accent-active);
}

.ui-link-blue {
  background: var(--ui-blue);
  color: #fff;
}
.ui-link-blue:hover {
  background: var(--ui-blue-hover);
  color: #fff;
}
.ui-link-blue:active {
  background: var(--ui-blue-active);
}

.ui-btn-secondary,
.ui-link-secondary,
.ui-link-default {
  background: #fff;
  border-color: var(--ui-border);
  color: var(--ui-text);
}
.ui-btn-secondary:hover:not(:disabled),
.ui-link-secondary:hover,
.ui-link-default:hover {
  border-color: var(--ui-border-hover);
  color: var(--ui-text);
}

.ui-btn-ghost,
.ui-link-ghost {
  background: transparent;
  color: var(--ui-text);
}
.ui-btn-ghost:hover:not(:disabled),
.ui-link-ghost:hover {
  background: #f1f5f9;
  color: var(--ui-text);
}

.ui-btn-sm { padding: 6px 12px; font-size: 12px; }
.ui-btn-lg { padding: 10px 20px; font-size: 16px; }

/* City picker (GM.UI.city-picker — see CityPickerTagHelper) */
.ui-city-picker {
  position: relative;
}

.ui-city-picker-results {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  max-height: 240px;
  overflow-y: auto;
}

.ui-city-picker-results li {
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--ui-text);
  border-radius: 6px;
  cursor: pointer;
}

.ui-city-picker-results li:hover {
  background: #eef2ff;
  color: var(--ui-accent);
}

/* Autocomplete (GM.UI.autocomplete — see AutoCompleteTagHelper / autocomplete.js) */
.ui-autocomplete {
  position: relative;
}

.ui-autocomplete-dropdown {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  max-height: 240px;
  overflow-y: auto;
}

.ui-autocomplete-item {
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--ui-text);
  border-radius: 6px;
  cursor: pointer;
}

.ui-autocomplete-item:hover,
.ui-autocomplete-item.is-active {
  background: #eef2ff;
  color: var(--ui-accent);
}

.ui-autocomplete-no-result {
  padding: 8px 10px;
  font-size: 13.5px;
  color: var(--ui-muted, #64748b);
}

/* Reserve room on the input so typed/selected text never runs under the buttons. */
.ui-input.has-add-btn,
.ui-input.has-clear-btn {
  padding-right: 34px;
}

.ui-input.has-add-btn.has-clear-btn {
  padding-right: 60px;
}

/* "+" quick-add button (e.g. Add Supplier next to Select Supplier). */
.ui-autocomplete-add {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  color: #fff;
  background: var(--ui-error);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.ui-autocomplete-add:hover {
  background: #be123c; /* rose-700 */
}

.ui-autocomplete-clear {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  padding: 0 4px;
  font-size: 18px;
  line-height: 1;
  color: var(--ui-muted, #64748b);
  background: transparent;
  border: none;
  cursor: pointer;
}

.ui-autocomplete-clear.beside-add {
  right: 32px;
}

.ui-autocomplete-clear:hover {
  color: var(--ui-text);
}

.ui-autocomplete-clear[hidden] {
  display: none;
}


/* =========================================================
   FORMAT FIELDS (GSTIN / PAN / PHONE)
========================================================= */

.ui-format-input {
    letter-spacing: .08em;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

    .ui-format-input::placeholder {
        letter-spacing: .08em;
    }

.ui-format-field.is-valid .ui-format-input {
    border-color: #16a34a !important;
}

.ui-format-field.has-error .ui-format-input {
    border-color: #dc2626 !important;
}

.ui-format-field.has-error .ui-helper {
    color: #dc2626;
}

.ui-format-field .ui-helper:empty {
    display: none;
}


/* =========================================================
   LINE ITEMS (GM.UI.line-items)
========================================================= */

.ui-line-items {
    border: 1px solid var(--phx-border, #dee2e6);
    border-radius: 6px;
    background: #fff;
}

.ui-line-items-table thead th {
    white-space: nowrap;
}

.ui-line-items-table td {
    vertical-align: top;
}

    /* Cells reuse the normal field components; the column header already labels them. */
    .ui-line-items-table td .ui-field {
        margin-bottom: 0;
    }

    .ui-line-items-table td .ui-label {
        display: none;
    }

.ui-line-items-table tfoot td {
    border-bottom: 0;
}

.ui-line-items-add {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
