/*
 * Controls shared by the public site and the admin, drawn by the components in
 * src/ui (Button, LinkButton, Select, SearchBox): one look for buttons, fields,
 * selects and search boxes. Both pages load this file before their own, which
 * keep only their layout. Colours come from each page's tokens (--red, --line…).
 */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-height: 46px;
  padding: 0.5em 1.05em;
  border: 1.5px solid #cfc7b8;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 0.15s,
    border-color 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--gold-line);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn svg {
  flex: none;
}

.btn-primary {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--red-dark);
  background: var(--red-dark);
}

.btn-soft,
.btn-danger {
  border-color: var(--red);
  background: #fff;
  color: var(--red);
}

.btn-soft:hover:not(:disabled),
.btn-danger:hover:not(:disabled) {
  border-color: var(--red);
  background: #fff5f4;
}

.btn-zalo {
  border-color: var(--zalo, #0068ff);
  background: var(--zalo, #0068ff);
  color: #fff;
}

.btn-zalo:hover:not(:disabled) {
  border-color: var(--zalo, #0068ff);
  filter: brightness(0.93);
}

.btn-icon {
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-color: transparent;
  background: transparent;
}

.btn-icon:hover:not(:disabled) {
  border-color: transparent;
  background: rgba(0, 0, 0, 0.05);
}

.btn-wide {
  width: 100%;
}

/* Fields: one-line text, many-line text and selects */
:where(input:not([type="checkbox"], [type="radio"], [type="file"], [type="range"], [type="color"], [type="hidden"]), textarea, select) {
  width: 100%;
  min-height: 48px;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid #d6cec0;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    background-color 0.15s;
}

:where(textarea) {
  resize: vertical;
  line-height: 1.5;
}

:where(input, textarea)::placeholder {
  color: #9b9388;
}

:where(input, textarea, select):hover:not(:disabled, :focus) {
  border-color: var(--gold-line);
}

:where(input, textarea, select):focus-visible {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(198, 40, 40, 0.15);
}

:where(input, textarea, select):disabled {
  background: #f3f1ed;
  color: #555;
}

/* Select (Select.tsx): the chosen option on one line, a chevron, an optional icon in front */
.ui-select,
.ui-search {
  position: relative;
  display: block;
}

.ui-select > select {
  appearance: none;
  padding-right: 2.4rem;
  text-overflow: ellipsis;
  cursor: pointer;
}

.ui-select > svg,
.ui-search > svg {
  position: absolute;
  top: 50%;
  width: 1.15rem;
  height: 1.15rem;
  transform: translateY(-50%);
  pointer-events: none;
}

.ui-select > .ui-select-arrow {
  right: 0.8rem;
  width: 1.1rem;
  height: 1.1rem;
  color: var(--muted);
}

.ui-select.has-icon > select {
  padding-left: 2.65rem;
}

.ui-select.has-icon > svg:first-child,
.ui-search > svg {
  left: 0.85rem;
  color: var(--gold-line);
}

/* Where the browser lets the page draw a select's list (Chrome, Edge): a card in the site's colours. Elsewhere the system list stays. */
@supports (appearance: base-select) {
  .ui-select > select,
  .ui-select > select::picker(select) {
    appearance: base-select;
  }

  .ui-select > select {
    display: flex;
    align-items: center;
  }

  .ui-select > select::picker-icon {
    display: none;
  }

  /* Select.tsx's own button: the chosen option, cut with "…" before the chevron. */
  .ui-select > select > button {
    all: unset;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .ui-select > select::picker(select) {
    margin-block: 6px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 18px 44px rgba(80, 50, 10, 0.16);
  }

  .ui-select option {
    padding: 0.6em 0.75em;
    border-radius: 9px;
    color: var(--text);
    font-weight: 500;
  }

  .ui-select option:hover,
  .ui-select option:focus-visible {
    outline: none;
    background: var(--soft);
  }

  .ui-select option:checked {
    background: #fff5f4;
    color: var(--red-dark);
    font-weight: 700;
  }

  .ui-select option::checkmark {
    order: 1;
    margin-left: auto;
    color: var(--red);
  }

  .ui-select optgroup {
    padding-top: 0.35rem;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
  }

  .ui-select optgroup option {
    font-size: 1rem;
  }
}

/* Avatar (Avatar.tsx): a picture, or the first letter of the name, in a circle */
.ui-avatar {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  object-fit: cover;
}

/* Search box (SearchBox.tsx): the magnifier inside the field */
.ui-search > input {
  padding-left: 2.65rem;
}
