/* ==========================================================================
   Forms - Input and Button Styles
   ========================================================================== */

/* Labels */
label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-normal);
  color: var(--color-ink);
  margin-bottom: var(--space-1);
}

/* Text Inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
textarea,
select {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-ink);
  background-color: var(--color-canvas);
  border: 1px solid var(--color-field-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

/* iOS draws a date or time field at the width of its own wheel, whatever
   width says, and pushes it past the card at phone width. Without the native
   chrome it takes the width it's given; the value stays left like a text box. */
input[type="date"],
input[type="time"],
input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  min-height: calc(var(--text-base) * var(--leading-normal) + 2 * var(--space-2) + 2px);
}

input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value {
  text-align: left;
}

/* Fields side by side where there's room — dates, amounts — and one above
   the other at phone width. A column never asks for more than the card has:
   min() lets it shrink below 12rem, and min-width: 0 stops a field's own
   width from holding it open. */
.form-fields {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr));
}

.form-fields > * {
  min-width: 0;
}

/* A file field's button looks like the app's secondary buttons rather than
   the browser's grey one, and the chosen name sits beside it in the muted
   ink. The same everywhere, so a reply's attachment and a report's match. */
input[type="file"] {
  max-width: 100%;
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--color-ink-light);
}

input[type="file"]::file-selector-button {
  margin-right: var(--space-3);
  padding: var(--space-1) var(--space-3);
  font: inherit;
  font-weight: var(--font-medium);
  color: var(--color-ink);
  background-color: var(--color-canvas);
  border: 1px solid var(--color-border-dark);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

input[type="file"]::file-selector-button:hover {
  background-color: var(--color-surface-subtle);
}

/* Every textarea starts at two lines and grows with what's typed, so nobody
   writes into a box that scrolls. It's the default rather than an opt-in so a
   new form gets it without asking; `rows` no longer sets the height, except
   rows="1", which keeps a one-line field one line. Browsers without
   field-sizing are grown by helpers/autogrow. */
textarea {
  field-sizing: content;
  min-height: calc(2lh + 2 * var(--space-2) + 2px);
  resize: none;
  overflow-y: hidden;
}

textarea[rows="1"] {
  min-height: calc(1lh + 2 * var(--space-2) + 2px);
}

input[type="color"] {
  min-height: 2.5rem;
  padding: 0.2rem;
  border-radius: var(--radius-md);
}

/* Custom dropdown chevron — the native select arrow renders inconsistently
   inside a styled select in Safari. Gray-400 stays visible on both themes. */
select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 16px 16px;
  padding-right: var(--space-8);
}

/* A select set straight into a flex row (a toolbar, a field beside its
   button) is as wide as its options and leaves the rest of the row alone. At
   100% it took the whole row and wrapped onto a line of its own. In a
   .form-group it still fills the column, and :where() keeps this at element
   specificity, so a width utility on the select still wins. */
:where(.flex) > select {
  width: auto;
}

/* The date picker's hour, minute and AM/PM: the same chevron as every other
   select, scaled down and given room so it isn't pressed against the edge.
   (forms.css loads after components.css, so this wins over their base rules.) */
.dtpicker__time-bar select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-2) center;
  background-size: 14px 14px;
  padding-right: calc(var(--space-2) + 14px + var(--space-2));
}

/* A compact select keeps the native arrow. */
.sidebar-theme__select {
  -webkit-appearance: auto;
  appearance: auto;
  background-image: none;
  padding-right: var(--space-2);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary-text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-primary) 30%, transparent);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-ink-lighter);
}

/* Buttons
 *
 * The bare-element selectors are wrapped in :where() so they carry zero
 * specificity: this is the *default* look for an unstyled <button>, and any
 * component that gives its button a class should win without having to know
 * about these rules. Left at element specificity, `button:hover` (0,1,1)
 * outranked a plain `.thing` (0,1,0), so a component that cleared its resting
 * background still flashed primary-blue on hover — a bug that hit six
 * components before this. `.btn` keeps its own specificity and is unaffected.
 */
:where(button,
input[type="submit"],
input[type="button"]),
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  color: var(--color-white);
  background-color: var(--color-primary-600);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

:where(button:hover,
input[type="submit"]:hover,
input[type="button"]:hover),
.btn:hover {
  background-color: var(--color-primary-700);
  text-decoration: none;
}

/* Ring only on keyboard focus (:focus-visible), not on mouse click, so
   clicking a button doesn't flash a heavy ring. Softer translucent ring
   reads well on both light and dark themes. */
:where(button:focus-visible,
input[type="submit"]:focus-visible,
input[type="button"]:focus-visible),
.btn:focus-visible {
  outline: 2px solid var(--color-primary-text);
  outline-offset: 2px;
}

:where(button:disabled,
input[type="submit"]:disabled),
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Button Variants */
.btn--secondary {
  color: var(--color-ink);
  background-color: var(--color-canvas);
  border-color: var(--color-border-dark);
}

.btn--secondary:hover {
  background-color: var(--color-surface-subtle);
}

.btn--danger {
  background-color: var(--color-danger-600);
}

.btn--danger:hover {
  background-color: var(--color-danger-700);
}

/* A quiet text action that still has to be a button — its own form and method.
   Withdrawing a form reply is the case: a DELETE to another path.

   It lives here rather than in components.css because forms.css loads after it,
   and .btn sets both a background and a colour — a modifier defined earlier
   loses to it and renders as a plain blue button. */
.btn--plain {
  padding: 0;
  background: none;
  border: 0;
  color: var(--color-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn--plain:hover {
  background: none;
  text-decoration: none;
}

.btn--plain.btn--danger-text {
  color: var(--color-danger-600);
}

.btn--plain.btn--danger-text:hover {
  color: var(--color-danger-700);
}

.btn--small {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  line-height: 1.25;
  min-height: 0;
  gap: var(--space-1);
}

/* Sized in em so it tracks the button it sits in rather than needing a size
   per button variant, and never squeezed when the label is long. */
.btn__icon {
  width: 1.15em;
  height: 1.15em;
  flex-shrink: 0;
}

.btn--large {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

.btn--full {
  width: 100%;
}

/* Form Groups
 *
 * Zero specificity, like the bare buttons above: forms.css loads after
 * utilities.css, so a plain `.form-group` beat `.mb-0` on the same element, and
 * a field paired with a button in an items-end row sat a margin higher than
 * the button. Now the utility, or any component that spaces its fields, wins.
 */
:where(.form-group) {
  margin-bottom: var(--space-4);
}

/* Form Errors */
.form-error {
  font-size: var(--text-sm);
  color: var(--color-danger-600);
  margin-top: var(--space-1);
}

.form-hint {
  margin-top: var(--space-1);
  margin-bottom: 0;
  font-size: var(--text-xs);
  color: var(--color-ink-light);
}

/* Inline Forms */
.form-inline {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-inline input {
  width: auto;
  flex: 1;
}

/* The "how many?" box on a slot that counts things rather than people. Outside
   the slot's own label, so tapping the number doesn't toggle the tick. */
.form-slot__quantity {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3) 2.4rem;
}

.form-slot__quantity input {
  width: 5.5rem;
}
