/* Reset and the shared controls: buttons, inputs, menus, dialogs, pills. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-m);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app {
  height: 100%;
}

h1,
h2,
p,
dl,
dd,
ul {
  margin: 0;
  padding: 0;
}

ul {
  list-style: none;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.icon {
  display: block;
  flex: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- Buttons --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-height);
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: var(--text-m);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.12s ease;
}

.btn:disabled {
  opacity: 0.5;
}

.btn-primary {
  background: var(--primary-bg);
  color: var(--primary-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-bg-hover);
}

.btn-ghost {
  color: var(--text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

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

.btn-small {
  height: 32px;
  padding: 0 12px;
  font-size: var(--text-s);
}

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

.btn-ghost-danger:hover:not(:disabled) {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-block {
  width: 100%;
  height: 42px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--radius-m);
  background: transparent;
  color: var(--text-2);
  transition: background-color 0.12s ease, color 0.12s ease;
}

.icon-btn:hover,
.icon-btn.is-active {
  background: var(--bg-hover);
  color: var(--text);
}

/* --- Inputs ---------------------------------------------------------------- */

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.input-label {
  font-size: var(--text-s);
  color: var(--text-2);
}

/* A quiet line of help under a control. */
.input-hint {
  color: var(--text-3);
  font-size: var(--text-s);
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--bg-field);
  transition: border-color 0.12s ease;
}

.input:hover {
  border-color: var(--text-3);
}

.input:focus {
  outline: 2px solid var(--focus);
  outline-offset: -1px;
  border-color: transparent;
}

select.input {
  padding-right: 32px;
  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='%2385837b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 10px center;
  background-repeat: no-repeat;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 36px;
  padding: 7px 2px;
  cursor: pointer;
}

.check.is-wide {
  grid-column: 1 / -1;
}

.check input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--primary-bg);
}

.check-text {
  display: flex;
  flex-direction: column;
}

.check-hint {
  color: var(--text-3);
  font-size: var(--text-s);
}

.textarea {
  height: auto;
  min-height: 104px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.45;
}

.segmented {
  display: inline-flex;
  width: fit-content;
  padding: 3px;
  border-radius: var(--radius-m);
  background: var(--bg-selected);
}

.segmented-option {
  height: 34px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-2);
  font-size: var(--text-m);
}

.segmented-option.is-selected {
  background: var(--bg-raised);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.segmented-option:disabled {
  opacity: 0.45;
}

/* A switch: a tick box drawn as on / off, for rows of settings on narrow screens. */
.switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--bg-selected);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.switch:checked {
  border-color: transparent;
  background: var(--primary-bg);
}

.switch:checked::before {
  background: var(--primary-text);
  transform: translateX(18px);
}

.switch:disabled {
  opacity: 0.45;
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  .switch,
  .switch::before {
    transition: none;
  }
}

/* --- Menus ----------------------------------------------------------------- */

.menu-anchor {
  position: relative;
  display: inline-flex;
}

.menu {
  position: absolute;
  z-index: 40;
  min-width: 220px;
  padding: 6px;
  border-radius: var(--radius-l);
  background: var(--bg-raised);
  box-shadow: var(--shadow-pop);
}

.menu-below {
  top: calc(100% + 6px);
}

.menu-above {
  bottom: calc(100% + 6px);
}

.menu-end {
  right: 0;
}

.menu-start {
  left: 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  text-align: left;
  font-size: var(--text-m);
}

.menu-item:hover {
  background: var(--bg-hover);
}

.menu-item.is-danger {
  color: var(--danger);
}

.menu-item-icon {
  display: inline-flex;
  color: var(--text-2);
}

.menu-item.is-danger .menu-item-icon {
  color: inherit;
}

.menu-item-label {
  flex: 1;
  min-width: 0;
}

.menu-item-check {
  display: inline-flex;
  width: 16px;
  color: var(--text-2);
}

.menu-heading {
  padding: 6px 10px 4px;
  overflow: hidden;
  color: var(--text-3);
  font-size: var(--text-s);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-divider {
  height: 1px;
  margin: 6px 4px;
  background: var(--line);
}

/* --- Dialog ---------------------------------------------------------------- */

.dialog-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--scrim);
}

.dialog {
  width: 100%;
  max-width: 400px;
  padding: 24px;
  border-radius: var(--radius-l);
  background: var(--bg-raised);
  box-shadow: var(--shadow-pop);
}

.dialog-title {
  font-size: var(--text-l);
  font-weight: 600;
}

.dialog-body {
  margin-top: 8px;
  color: var(--text-2);
}

/* A pop-up form: a dialog on wide screens, a sheet from the bottom on narrow. */
.dialog-panel {
  display: flex;
  flex-direction: column;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  padding: 0;
}

.dialog-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 6px 24px;
}

.dialog-scroll {
  flex: 1;
  min-height: 0;
  padding: 10px 24px 20px;
  overflow-y: auto;
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dialog-section {
  margin: 8px 0 -4px;
  color: var(--text-3);
  font-size: var(--text-s);
  font-weight: 400;
}

.dialog-foot {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
}

.dialog-foot-gap {
  flex: 1;
}

/* A line under the buttons that says what the strong one will do. */
.dialog-foot:has(.dialog-foot-note) {
  flex-wrap: wrap;
}

.dialog-foot-note {
  flex-basis: 100%;
  color: var(--text-3);
  font-size: var(--text-s);
  text-align: right;
}

@media (max-width: 820px) {
  .dialog-scrim.is-sheet {
    align-items: flex-end;
    padding: 0;
  }

  .dialog-panel {
    max-width: none;
    max-height: calc(100dvh - 32px);
    border-radius: var(--radius-l) var(--radius-l) 0 0;
  }

  .dialog-head {
    padding-left: var(--gutter);
  }

  .dialog-scroll {
    padding-right: var(--gutter);
    padding-left: var(--gutter);
  }

  .dialog-foot {
    padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  }
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

/* --- Pills, notices -------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-s);
  font-weight: 500;
  white-space: nowrap;
}

.pill-small {
  height: 20px;
  padding: 0 8px;
  font-size: 12px;
}

.pill-prospect,
.pill-info {
  background: var(--info-bg);
  color: var(--info);
}

.pill-customer,
.pill-positive {
  background: var(--positive-bg);
  color: var(--positive);
}

.pill-muted {
  background: var(--bg-selected);
  color: var(--text-2);
}

.notice {
  padding: 10px 14px;
  border-radius: var(--radius-m);
  font-size: var(--text-m);
}

.notice-error {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Something worth knowing that is not a problem. */
.notice-quiet {
  background: var(--bg-selected);
  color: var(--text-2);
}

.loading {
  padding: 32px 0;
  color: var(--text-3);
}
