/* Components: buttons, fields, segmented control, dialogs, menus, toasts. They know nothing about the screens. */

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--h-md); padding: 0 14px;
  border-radius: var(--r-md);
  font-size: var(--fs-body); font-weight: 500; line-height: 1; white-space: nowrap;
  user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur);
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .38; cursor: default; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--raised); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--raised-hover); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--raised); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 22%, var(--danger-soft)); }

.btn-sm { height: var(--h-sm); padding: 0 10px; border-radius: var(--r-sm); font-size: var(--fs-caption); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: var(--h-lg); padding: 0 18px; }
.btn-icon { width: var(--h-md); padding: 0; }
.btn-icon.btn-sm { width: var(--h-sm); }
.btn-icon.btn-lg { width: var(--h-lg); }
.btn-block { width: 100%; }

/* ---- Fields ---- */

.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--fs-caption); font-weight: 500; color: var(--text-2); }
.field .req::after { content: "•"; margin-left: 5px; color: var(--text-3); }
.field .hint { font-size: var(--fs-caption); color: var(--text-3); }
.field .error { font-size: var(--fs-caption); color: var(--danger); }

.input, .select, .textarea {
  width: 100%; height: var(--h-lg); padding: 0 12px;
  background: var(--raised); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: color-mix(in srgb, var(--line) 60%, var(--text-3)); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--text-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 10%, transparent);
}
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); }
.input:disabled { opacity: .5; }
.input-sm { height: var(--h-md); font-size: var(--fs-body); }
.textarea { height: auto; padding: 10px 12px; resize: none; line-height: 1.45; display: block; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238a8b8d' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6.5l4 4 4-4'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 14px;
}
.counter { font-size: var(--fs-caption); color: var(--text-3); text-align: right; }

/* A password field with an eye that shows what is typed (js/parts/password.js) */
.pw { position: relative; display: block; min-width: 0; }
.pw > .input { width: 100%; padding-right: 38px; }
.pw-eye {
  position: absolute; right: 4px; top: 50%; translate: 0 -50%; display: grid; place-items: center; width: 28px; height: 28px;
  padding: 0; border-radius: var(--r-sm); color: var(--text-3); transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.pw-eye:hover, .pw-eye[aria-pressed="true"] { color: var(--text); }
.pw-eye:hover { background: var(--raised-hover); }
.pw-eye svg { width: 16px; height: 16px; }
@media (pointer: coarse) { .pw > .input { padding-right: 46px; } .pw-eye { right: 2px; width: 40px; height: 40px; } }

/* A row of colors to choose from (the note dialog); the chosen one has a ring around it */
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 4px; }
.swatch {
  position: relative; flex: none; width: 22px; height: 22px; padding: 0; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18); transition: transform var(--dur) var(--ease);
}
.swatch:hover:not(:disabled) { transform: scale(1.12); }
.swatch[aria-checked="true"]::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 1.5px solid var(--text); }
.swatch.is-none { background: var(--raised); box-shadow: inset 0 0 0 1px var(--line); }
.swatch.is-none::before { content: ""; position: absolute; left: 50%; top: 50%; width: 12px; height: 1.5px; background: var(--text-3); transform: translate(-50%, -50%) rotate(-45deg); }
@media (pointer: coarse) { .swatches { gap: 14px; } .swatch { width: 28px; height: 28px; } }

/* The search bar: an icon in front of a field */
.search { position: relative; }
.search > svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 38px; }

/* A checkbox as a small box with a label */
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--text-2); font-weight: 500; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center;
  background: var(--raised); border: 1px solid var(--line); color: transparent; transition: all var(--dur) var(--ease);
}
.check .box svg { width: 12px; height: 12px; }
.check input:checked + .box { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.check input:focus-visible + .box { outline: 2px solid color-mix(in srgb, var(--text) 55%, transparent); outline-offset: 2px; }
.check:hover { color: var(--text); }

/* ---- Segmented control ---- */

.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 2px; background: var(--raised); border-radius: var(--r-md); }
.seg button {
  height: calc(var(--h-md) - 4px); padding: 0 14px; border-radius: calc(var(--r-md) - 2px);
  color: var(--text-2); font-weight: 500; white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--selected); color: var(--on-selected); }
.seg-block { display: grid; }

/* ---- Small things ---- */

.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--primary); color: var(--on-primary); font-size: 11px; font-weight: 600; line-height: 1;
}
.dot-sep::before { content: "·"; margin: 0 .5em; color: var(--text-3); }
.hr { height: 1px; background: var(--line-soft); border: 0; margin: 0; }

.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--selected); color: var(--on-selected);
  font-size: 12px; font-weight: 600; text-transform: uppercase;
}

/* ---- Dialogs ---- */

#layer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }

.backdrop {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: var(--overlay); pointer-events: auto;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: fade .16s var(--ease);
}
.dialog {
  display: flex; flex-direction: column; width: min(var(--w, 440px), 100%); max-height: calc(100dvh - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow);
  animation: pop .2s var(--ease);
}
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 4px; }
.dialog-head h2 { font-size: 18px; }
.dialog-head .sub { margin-top: 2px; font-size: var(--fs-caption); color: var(--text-2); }
.dialog-body { padding: 14px 20px 4px; overflow: auto; display: grid; gap: 14px; align-content: start; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 16px 20px 18px; }
.dialog-foot .grow { flex: 1; min-width: 0; }
.dialog-note { font-size: var(--fs-caption); color: var(--text-2); }
.dialog-note.error { color: var(--danger); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes sheet { from { transform: translateY(100%); } }

@media (max-width: 640px) {
  .backdrop { place-items: end center; padding: 0; }
  .dialog {
    width: 100%; max-height: 92dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: 0;
    animation: sheet .26s var(--ease);
  }
  .dialog::before { content: ""; width: 36px; height: 4px; border-radius: 4px; background: var(--line); margin: 8px auto 0; }
  .dialog-head { padding-top: 10px; }
  .dialog-foot { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}

/* ---- Menus and drop-down lists ---- */

.menu {
  position: fixed; z-index: 120; min-width: 200px; max-width: calc(100vw - 16px); max-height: min(360px, 60dvh); overflow: auto;
  padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
  pointer-events: auto; animation: pop .14s var(--ease);
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--h-md); padding: 0 10px;
  border-radius: var(--r-sm); text-align: left; color: var(--text); font-weight: 450;
}
.menu-item svg { width: 16px; height: 16px; color: var(--text-2); flex: none; }
.menu-item:hover, .menu-item.is-lit { background: var(--raised); }
.menu-item.is-danger, .menu-item.is-danger svg { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line-soft); margin: 4px 6px; }
.menu-label { padding: 8px 10px 4px; font-size: var(--fs-caption); color: var(--text-3); font-weight: 500; }

.menu-backdrop { position: fixed; inset: 0; z-index: 110; pointer-events: auto; }

/* A field with a list of values under it */
.combo { position: relative; }
.combo .pick { display: flex; align-items: center; justify-content: space-between; text-align: left; cursor: pointer; }
.combo .pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo .pick.placeholder span { color: var(--text-3); }

/* ---- Toasts ---- */

.toasts { position: fixed; left: 50%; bottom: 24px; translate: -50% 0; z-index: 140; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  padding: 9px 14px; border-radius: 99px; background: var(--selected); color: var(--on-selected);
  font-size: var(--fs-body); font-weight: 500; box-shadow: var(--shadow); animation: pop .2s var(--ease);
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
@media (max-width: 899px) { .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); } }

/* ---- Empty states ---- */

.empty { display: grid; justify-items: center; gap: 6px; padding: 72px 16px; text-align: center; color: var(--text-2); }
.empty h3 { color: var(--text); font-size: 16px; }
.empty svg { width: 28px; height: 28px; color: var(--text-3); margin-bottom: 6px; }
